// FUCKED UP FUCKED UP FUCKED UP FUCKED UP FUCKED UP _ Who? _
// FUCKED UP FUCKED UP FUCKED UP FUCKED UP FUCKED UP _ You _
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")
#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()
#define MP make_pair
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll maxn=3e5+10, maxm=1e6+10, lg=21, mod=998244353, inf=1e18;
#define git(x) (x&-x)
#define lc (v<<1)
#define rc (lc^1)
#define md ((s+t)>>1)
struct node{
vector<ll> vec,bit; bool ok=0;
void add(ll i,ll x){for(i++;i<SZ(bit);i+=git(i))bit[i]+=x;}
ll get(ll i){ll ret=0;for(i++;i;i-=git(i))ret+=bit[i];return ret;}
}seg[maxn<<2];
ll n,q,l[maxn],r[maxn];
string S;
vector<ll> qq[maxn];
void rev(ll x,ll s=1,ll t=n+1,ll v=1){
if(t-s==1){
seg[v].ok^=1;
return;
}
(x<md ? rev(x,s,md,lc):rev(x,md,t,rc));
seg[v].ok=seg[lc].ok&seg[rc].ok;
}
ll getc(ll x,ll s=1,ll t=n+1,ll v=1){
if(s>=x || seg[v].ok) return 0;
if(t-s==1) return s;
ll xx=getc(x,md,t,rc);
if(xx!=0) return xx;
return getc(x,s,md,lc);
}
ll getr(ll x,ll s=1,ll t=n+1,ll v=1){
if(t<=x+1 || seg[v].ok) return n+1;
if(t-s==1) return s;
ll xx=getr(x,s,md,lc);
if(xx!=n+1) return xx;
return getr(x,md,t,rc);
}
bool geto(ll l,ll r,ll s=1,ll t=n+1,ll v=1){
if(l>=t || r<=s) return 1;
if(l<=s && r>=t) return seg[v].ok;
return geto(l,r,s,md,lc) && geto(l,r,md,t,rc);
}
void bild(ll s=1,ll t=n+1,ll v=1){
if(t-s==1){
for(auto r:qq[s]) seg[v].vec.pb(r);
sort(all(seg[v].vec)), seg[v].vec.resize(unique(all(seg[v].vec))-seg[v].vec.begin());
seg[v].bit.resize(SZ(seg[v].vec)+10);
return;
}
bild(s,md,lc), bild(md,t,rc);
seg[v].vec.resize(SZ(seg[lc].vec)+SZ(seg[rc].vec));
merge(all(seg[lc].vec),all(seg[rc].vec),seg[v].vec.begin());
seg[v].bit.resize(SZ(seg[v].vec)+10);
}
void add(ll l,ll r,ll lx,ll rx,ll x,ll s=1,ll t=n+1,ll v=1){
if(l>=t || r<=s) return;
if(l<=s && r>=t){
ll L=upper_bound(all(seg[v].vec),lx)-seg[v].vec.begin();
ll R=upper_bound(all(seg[v].vec),rx)-seg[v].vec.begin();
seg[v].add(L,+x);
seg[v].add(R,-x);
return;
}
add(l,r,lx,rx,x,s,md,lc);
add(l,r,lx,rx,x,md,t,rc);
}
ll get(ll l,ll r,ll s=1,ll t=n+1,ll v=1){
ll ret=seg[v].get(lower_bound(all(seg[v].vec),r)-seg[v].vec.begin());
if(t-s==1) return ret;
ret+=(l<md ? get(l,r,s,md,lc):get(l,r,md,t,rc));
return ret;
}
int main(){
ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n>>q>>S; S='#'+S;
for(int i=0;i<q;i++){
string s; cin>>s>>l[i];
if(s[0]=='q') cin>>r[i], qq[l[i]].pb(r[i]);
}
bild();
for(int i=1;i<=n;i++)if(S[i]=='1') add(getc(i)+1,i+1,i,getr(i),q), rev(i);
for(int i=0;i<q;i++){
if(r[i]){
ll x=get(l[i],r[i]);
if(geto(l[i],r[i])) x-=(q-i-1);
cout<<x<<'\n';
}
else add(getc(l[i])+1,l[i]+1,l[i],getr(l[i]),(geto(l[i],l[i]+1) ? -1:+1)*(q-i-1)), rev(l[i]);
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
73080 KB |
Output is correct |
2 |
Correct |
42 ms |
73080 KB |
Output is correct |
3 |
Correct |
42 ms |
73116 KB |
Output is correct |
4 |
Correct |
42 ms |
73208 KB |
Output is correct |
5 |
Correct |
43 ms |
73208 KB |
Output is correct |
6 |
Correct |
42 ms |
73208 KB |
Output is correct |
7 |
Correct |
42 ms |
73208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
219 ms |
83192 KB |
Output is correct |
2 |
Correct |
281 ms |
85496 KB |
Output is correct |
3 |
Correct |
441 ms |
88340 KB |
Output is correct |
4 |
Correct |
1721 ms |
184676 KB |
Output is correct |
5 |
Correct |
1718 ms |
191380 KB |
Output is correct |
6 |
Correct |
1291 ms |
176228 KB |
Output is correct |
7 |
Correct |
2400 ms |
211376 KB |
Output is correct |
8 |
Correct |
2487 ms |
212684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
73340 KB |
Output is correct |
2 |
Correct |
44 ms |
73464 KB |
Output is correct |
3 |
Correct |
47 ms |
73720 KB |
Output is correct |
4 |
Correct |
45 ms |
73592 KB |
Output is correct |
5 |
Correct |
736 ms |
137188 KB |
Output is correct |
6 |
Correct |
1240 ms |
168804 KB |
Output is correct |
7 |
Correct |
1824 ms |
198756 KB |
Output is correct |
8 |
Correct |
3064 ms |
238868 KB |
Output is correct |
9 |
Correct |
272 ms |
84216 KB |
Output is correct |
10 |
Correct |
277 ms |
84856 KB |
Output is correct |
11 |
Correct |
303 ms |
85496 KB |
Output is correct |
12 |
Correct |
2473 ms |
237676 KB |
Output is correct |
13 |
Correct |
2976 ms |
238924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
73592 KB |
Output is correct |
2 |
Correct |
52 ms |
73464 KB |
Output is correct |
3 |
Correct |
47 ms |
73464 KB |
Output is correct |
4 |
Correct |
45 ms |
73336 KB |
Output is correct |
5 |
Correct |
2555 ms |
241888 KB |
Output is correct |
6 |
Correct |
1932 ms |
212264 KB |
Output is correct |
7 |
Correct |
1387 ms |
181476 KB |
Output is correct |
8 |
Correct |
837 ms |
138164 KB |
Output is correct |
9 |
Correct |
428 ms |
93292 KB |
Output is correct |
10 |
Correct |
232 ms |
79220 KB |
Output is correct |
11 |
Correct |
443 ms |
93324 KB |
Output is correct |
12 |
Correct |
251 ms |
79224 KB |
Output is correct |
13 |
Correct |
462 ms |
93176 KB |
Output is correct |
14 |
Correct |
223 ms |
79224 KB |
Output is correct |
15 |
Correct |
2457 ms |
242848 KB |
Output is correct |
16 |
Correct |
2968 ms |
244044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
73080 KB |
Output is correct |
2 |
Correct |
42 ms |
73080 KB |
Output is correct |
3 |
Correct |
42 ms |
73116 KB |
Output is correct |
4 |
Correct |
42 ms |
73208 KB |
Output is correct |
5 |
Correct |
43 ms |
73208 KB |
Output is correct |
6 |
Correct |
42 ms |
73208 KB |
Output is correct |
7 |
Correct |
42 ms |
73208 KB |
Output is correct |
8 |
Correct |
219 ms |
83192 KB |
Output is correct |
9 |
Correct |
281 ms |
85496 KB |
Output is correct |
10 |
Correct |
441 ms |
88340 KB |
Output is correct |
11 |
Correct |
1721 ms |
184676 KB |
Output is correct |
12 |
Correct |
1718 ms |
191380 KB |
Output is correct |
13 |
Correct |
1291 ms |
176228 KB |
Output is correct |
14 |
Correct |
2400 ms |
211376 KB |
Output is correct |
15 |
Correct |
2487 ms |
212684 KB |
Output is correct |
16 |
Correct |
44 ms |
73340 KB |
Output is correct |
17 |
Correct |
44 ms |
73464 KB |
Output is correct |
18 |
Correct |
47 ms |
73720 KB |
Output is correct |
19 |
Correct |
45 ms |
73592 KB |
Output is correct |
20 |
Correct |
736 ms |
137188 KB |
Output is correct |
21 |
Correct |
1240 ms |
168804 KB |
Output is correct |
22 |
Correct |
1824 ms |
198756 KB |
Output is correct |
23 |
Correct |
3064 ms |
238868 KB |
Output is correct |
24 |
Correct |
272 ms |
84216 KB |
Output is correct |
25 |
Correct |
277 ms |
84856 KB |
Output is correct |
26 |
Correct |
303 ms |
85496 KB |
Output is correct |
27 |
Correct |
2473 ms |
237676 KB |
Output is correct |
28 |
Correct |
2976 ms |
238924 KB |
Output is correct |
29 |
Correct |
57 ms |
73592 KB |
Output is correct |
30 |
Correct |
52 ms |
73464 KB |
Output is correct |
31 |
Correct |
47 ms |
73464 KB |
Output is correct |
32 |
Correct |
45 ms |
73336 KB |
Output is correct |
33 |
Correct |
2555 ms |
241888 KB |
Output is correct |
34 |
Correct |
1932 ms |
212264 KB |
Output is correct |
35 |
Correct |
1387 ms |
181476 KB |
Output is correct |
36 |
Correct |
837 ms |
138164 KB |
Output is correct |
37 |
Correct |
428 ms |
93292 KB |
Output is correct |
38 |
Correct |
232 ms |
79220 KB |
Output is correct |
39 |
Correct |
443 ms |
93324 KB |
Output is correct |
40 |
Correct |
251 ms |
79224 KB |
Output is correct |
41 |
Correct |
462 ms |
93176 KB |
Output is correct |
42 |
Correct |
223 ms |
79224 KB |
Output is correct |
43 |
Correct |
2457 ms |
242848 KB |
Output is correct |
44 |
Correct |
2968 ms |
244044 KB |
Output is correct |
45 |
Correct |
132 ms |
80460 KB |
Output is correct |
46 |
Correct |
239 ms |
81272 KB |
Output is correct |
47 |
Correct |
943 ms |
130036 KB |
Output is correct |
48 |
Correct |
1584 ms |
193048 KB |
Output is correct |
49 |
Correct |
322 ms |
88108 KB |
Output is correct |
50 |
Correct |
309 ms |
87928 KB |
Output is correct |
51 |
Correct |
332 ms |
89080 KB |
Output is correct |
52 |
Correct |
531 ms |
107896 KB |
Output is correct |
53 |
Correct |
525 ms |
108024 KB |
Output is correct |
54 |
Correct |
526 ms |
108152 KB |
Output is correct |