ピットすぎて、時には(ブロックするようになりました荷受人に)それを埋めます
ブロックのチームは、非常に良いとMo暴力アルゴリズムです
質問の特別なシーケンスを維持するための要件のいくつかの顔の人々を作成するには、ハイスコアも、暴力ACを得ることができます
選択した州全体でも複数回は、良いものの損失を学んだん
(しかし、それでもまだ、私たちはああ巧妙に曲がった正の解決策を模索する必要があります)
ブロック
ブロックは、定義により、各ブロックの列の数、バッチ回答情報をカットします
問合せ部は、ラインの答えは上のブロック、直接的な統計情報を網羅かどうかを尋ねられたときでない場合は、離れてブロック暴力を入れ、内部の特定のデータを照会します。
あなたがカバーされていない場合は、それが特定のデータを維持するために暴力を開き、特定のデータのブロックに、マークを作るために、このセクションでは、ブロックをカバーし、クエリ時間ラベリング処理をこのブロックを変更する場合は変更します。
具体的にタイトル。
Luogu P3870 [TJOI2009]スイッチ
力により、排他的論理和演算範囲クエリの範囲をサポートするために必要な01のシーケンスは、あります。
=配列長=番号動作の1E5
セグメントの木、ブロック、ナイーブ暴力缶
まず、ブロックの数は、得られた各ブロックの基本的な情報を処理し、次いで注意深くライン上に維持され、ブロックの長さを取得します
ブロックの多くの詳細、私は午後を転送しました、サイードは、ここ数こんにゃく間違った場所
答えは、処理時間を処理し、答える再びタグを解消された際に、タグを再生する......
ブロック内のセクションの取り扱いません
サイクルはブロックインデックスである場合I、サイクルは添え字をインデックスと検索の結果......
#include<bits/stdc++.h>
using namespace std ;
const int MAXN = 100010;
int n,m;
struct Block{
int l,r;
int ans,tag;
}blo[1000];
int fab[MAXN],a[MAXN],sq,bctr;
void set_up(){
sq = sqrt(n);
bctr = n/sq;
if(n%sq) ++bctr;
// cout<<sq<<"<-sq bctr->"<<bctr<<endl;
for(int i=1;i<=n;i++){
fab[i] = (i-1)/sq+1;
// cout<<fab[i]<<" ";
}
// cout<<endl;
for(int i=1;i<bctr;i++){
blo[i].l = (i-1) * sq + 1;
blo[i].r = i * sq;
}
blo[bctr].l = (bctr-1) * sq + 1;
blo[bctr].r = n;
// for(int i=1;i<=bctr;i++){
// cout<<"i = "<<i;
// cout<<" ans = "<<blo[i].ans;
// cout<<" tag = "<<blo[i].tag;
// cout<<" l = "<<blo[i].l<<" r = "<<blo[i].r<<endl;
// }
}
void pushdown(int x){//无脑push
// if(blo[x].tag == 0) cout<<"???"<<endl;
for(int i=blo[x].l;i<=blo[x].r;i++)
a[i] ^= 1;
blo[x].tag = 0;
}
void change (int x,int y){
if(fab[x] == fab[y]){
if(blo[fab[x]].tag) pushdown(fab[x]);
for(int i=x;i<=y;i++){
a[i] ^= 1;
blo[fab[i]].ans += ((a[i] == 1) ? 1 : -1);
}
return;
}
/*-----------same block--------*/
if(blo[fab[x]].l != x){
if(blo[fab[x]].tag) pushdown(fab[x]);
for(int i=x;i<=blo[fab[x]].r;i++){
a[i] ^= 1;
blo[fab[i]].ans += (a[i] == 1) ? 1 : -1;
}
}
else {
blo[fab[x]].tag ^= 1;
blo[fab[x]].ans = (blo[fab[x]].r - blo[fab[x]].l + 1) - blo[fab[x]].ans;
}
/*-----------left part---------*/
if(blo[fab[y]].r != y){
if(blo[fab[y]].tag) pushdown(fab[y]);
for(int i=blo[fab[y]].l;i<=y;i++){
a[i] ^= 1;
blo[fab[y]].ans += (a[i] == 1) ? 1 : -1;
}
}
else{
blo[fab[y]].tag ^= 1;
blo[fab[y]].ans = (blo[fab[y]].r - blo[fab[y]].l + 1) - blo[fab[y]].ans;
}
/*-----------right part---------*/
for(int i=fab[x]+1;i<=fab[y]-1;i++){
blo[i].tag ^= 1;
blo[i].ans = (blo[i].r - blo[i].l + 1) - blo[i].ans;
}
// for(int i=1;i<=bctr;i++){
// cout<<blo[i].ans<<" ";
// }
return;
/*-----------middle part--------*/
}
int ask(int x,int y){
int ret = 0;
// for(int i=1;i<=bctr;i++){
// cout<<blo[i].ans<<" ";
// }
if(fab[x] == fab[y]){
if(blo[fab[x]].tag) pushdown(fab[x]);
for(int i=x;i<=y;i++){
ret += a[i];
}
return ret;
}
if(x != blo[fab[x]].l) {
if(blo[fab[x]].tag) pushdown(fab[x]);
for(int i = x; i <= blo[fab[x]].r; i++) {
ret += a[i];
}
}
else ret += blo[fab[x]].ans;
// for(int i=1;i<=bctr;i++){
// cout<<blo[i].ans<<" ";
// }
if(y != blo[fab[y]].r) {
if(blo[fab[y]].tag) pushdown(fab[y]);
for(int i = blo[fab[y]].l; i <= y; i++) {
ret += a[i];
}
}
else ret += blo[fab[y]].ans;
// for(int i=1;i<=bctr;i++){
// cout<<blo[i].ans<<" ";
// }
for(int i=fab[x]+1;i<=fab[y]-1;i++){
ret += blo[i].ans;
// cout<<"ret = "<<ret<<endl;
// cout<<"i = "<<i<<endl;
// cout<<"blo[i].ans = "<<blo[i].ans<<endl;
}
return ret;
}
int main(){
ios::sync_with_stdio(false);
cin>>n>>m;
set_up();
for(int i=1;i<=m;i++){
int t,x,y;
cin>>t>>x>>y;
if(t == 0){
change(x,y);
}
if(t == 1){
cout<<ask(x,y)<<endl;
}
// cout<<"for this round,the ans1 and ans2 and ans3 is "<<blo[1].ans<<" "<<blo[2].ans<<" "<<blo[3].ans<<endl;
}
return 0;
}
一万人の不名誉なデバッグ情報