#pragma GCC optimize("O3")
#include<stdint.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define VIS(it,con) for(auto it=con.begin();it!=con.end();++it)
#define pob pop_back
#define pf push_front
#define pof pop_front
#define MIN(x,y) (x=min(x,(y)))
#define MAX(x,y) (x=max(x,(y)))
#define mid ((l+r)/2)
#define lch (idx*2+1)
#define rch (idx*2+2)
/*****************************************************************************/
#include<bits/stdc++.h>
#define int int_fast64_t
using namespace std;
typedef pair<int,int> pii;
#define REP(i,j,k) for(register int i=(j);i<(k);++i)
#define RREP(i,j,k) for(register int i=int(j)-1;i>=(k);--i)
#define ALL(a) a.begin(),a.end()
#define pb push_back
#define F first
#define S second
#define endl '\n'
// #define __debug
#ifdef __debug
#define IOS (void)0
#define de(...) cerr<<__VA_ARGS__
#define ar(a,s,t) {REP(__i,s,t)de(a[__i]<<' ');de(endl);}
#else
#define IOS cin.tie(0),cout.tie(0),ios_base::sync_with_stdio(false)
#define de(...) (void)0
#define ar(...) (void)0
#endif
/***********************************default***********************************/
struct OP{int o,l,r,t,d;};
const int maxn=3e5+9;
int n,q,p=0,res[maxn];
OP ops[4*maxn],t[4*maxn];
set<int>st;
void cdq2(int l,int r){
if(l+1==r)return;
cdq2(l,mid),cdq2(mid,r);
REP(i,l,mid)t[i].r=0;
REP(i,mid,r)t[i].r=1;
inplace_merge(t+l,t+mid,t+r,[](OP a,OP b){return a.t<b.t;});
int c=0;
REP(i,l,r){
OP&oo=t[i];
if(!oo.o&&!oo.l&&!oo.r)c+=oo.d*(q-1-oo.t);
if(oo.o&&oo.l&&oo.r)res[oo.t]+=c;
}
}
void cdq1(int l,int r){
if(l+1==r)return;
cdq1(l,mid),cdq1(mid,r);
REP(i,l,mid)ops[i].l=0;
REP(i,mid,r)ops[i].l=1;
inplace_merge(ops+l,ops+mid,ops+r,[](OP a,OP b){return a.r==b.r?a.o<b.o:a.r>b.r;});
REP(i,l,r)t[i]=ops[i];
cdq2(l,r);
}
main(){
IOS;
cin>>n>>q;
st.insert(-1);
REP(i,0,n){
char c;cin>>c;
if(c=='0')st.insert(i);
else{
if(p&&ops[p-1].r==i-1)ops[p-1].r=i;
else{
ops[p++]=OP{0,*st.rbegin()+1,i-1,-1,-1};
ops[p++]=OP{0,*st.rbegin()+1,i,-1,1};
}
}
}
st.insert(n);
REP(t,0,q){
string cmd;cin>>cmd;
if(cmd[0]=='t'){
int i,x;cin>>i,--i;
x=st.count(i)?1:-1;
if(x<0)st.insert(i);
auto it=st.find(i);
ops[p++]=OP{0,*prev(it)+1,*next(it)-1,t,x};
ops[p++]=OP{0,*prev(it)+1,i-1,t,-x};
ops[p++]=OP{0,i+1,*next(it)-1,t,-x};
if(x>0)st.erase(it);
res[i]=-1;
}else{
int a,b;cin>>a>>b,--a,--b;
ops[p++]=OP{1,a,b-1,t,0};
auto it=st.lower_bound(a);
if(it!=st.end()&&*it>=b)res[t]-=q-1-t;
}
}
sort(ops,ops+p,[](OP a,OP b){return a.l==b.l?a.o<b.o:a.l<b.l;});
cdq1(0,p);
REP(i,0,q)if(res[i]>=0)cout<<res[i]<<endl;
}
Compilation message
street_lamps.cpp:70:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2969 ms |
70660 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
888 KB |
Output is correct |
2 |
Incorrect |
9 ms |
632 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |