#include<bits/stdc++.h>
#define MAXN 300007
using namespace std;
struct ST{
int tree[4*MAXN];
void update(int v,int l,int r,int pos){
if(l==r){
tree[v]=1-tree[v];
}else{
int tt=(l+r)/2;
if(pos<=tt)update(2*v,l,tt,pos);
else update(2*v+1,tt+1,r,pos);
tree[v]=min(tree[2*v],tree[2*v+1]);
}
}
int getmin(int v,int l,int r,int ll,int rr){
if(ll>rr)return 1;
if(l==ll and r==rr){
return tree[v];
}else{
int tt=(l+r)/2;
return min( getmin(2*v,l,tt,ll,min(tt,rr)) , getmin(2*v+1,tt+1,r,max(tt+1,ll),rr) );
}
}
};
int n,q,tim,x,l,r;
char c[MAXN];
int last[MAXN],sum[MAXN];
vector<int> tree[4*MAXN];
string type;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>q>>(c+1);
for(int i=1;i<=q;i++){
cin>>type;
if(type=="toggle"){
cin>>x;
if(c[x]=='0'){
c[x]='1'; last[x]=i;
}else{
c[x]='0'; sum[x]+=i-last[x];
}
}else{
cin>>l>>r;
if(c[l]=='0')cout<<sum[l]<<"\n";
else cout<<sum[l]+i-last[l]<<"\n";
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
28504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
32592 KB |
Output is correct |
2 |
Correct |
57 ms |
32852 KB |
Output is correct |
3 |
Correct |
62 ms |
33620 KB |
Output is correct |
4 |
Correct |
74 ms |
36948 KB |
Output is correct |
5 |
Correct |
68 ms |
36180 KB |
Output is correct |
6 |
Correct |
63 ms |
36836 KB |
Output is correct |
7 |
Correct |
73 ms |
35412 KB |
Output is correct |
8 |
Correct |
82 ms |
36688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
28508 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
28508 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
28504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |