This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
using namespace std;
const int INF=(int)1e9;
int N,Q;
string S;
int Tree[1<<20];
int update(int x,int v,int l,int r,int n){
if (r<x||x<l)
return Tree[n];
if (l==r)
return Tree[n]=v;
int m=(l+r)>>1;
return Tree[n]=max(update(x,v,l,m,n<<1),update(x,v,m+1,r,n<<1|1));
}
int query(int lx,int rx,int l,int r,int n){
if (r<lx||rx<l)
return 0;
if (lx<=l&&r<=rx)
return Tree[n];
int m=(l+r)>>1;
return max(query(lx,rx,l,m,n<<1),query(lx,rx,m+1,r,n<<1|1));
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>N>>Q>>S;
for (int i=1; i<=N; i++){
if (S[i-1]=='0')
update(i,INF,1,N,1);
}
for (int t=1; t<=Q; t++){
string s;
cin>>s;
if (s[0]=='t'){
int x;
cin>>x;
update(x,t,1,N,1);
}
else{
int l,r;
cin>>l>>r;
int mx=query(l,r-1,1,N,1);
cout<<max(t-mx,0)<<"\n";
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |