#include <iostream>
#include <vector>
using namespace std;
typedef pair<int,int> pii;
bool sub1=true;
bool sub2=true;
int N,Q;
char c;
string s;
int A[300005],B[300005];
bool P[300005];
bool T[105][105];
vector<pii> V[300005];
int INF=1e9;
int R[1200005];
void update(int a, int b, int k=1, int l=0, int r=N-1){
if(l==r)
R[k]=b;
else{
int m=(l+r)/2;
if(a<=m)
update(a,b,2*k,l,m);
else
update(a,b,2*k+1,m+1,r);
R[k]=max(R[2*k],R[2*k+1]);
}
}
int query(int a, int b, int k=1, int l=0, int r=N-1){
if(b<l or r<a)
return -1;
else if(a<=l and r<=b)
return R[k];
else{
int m=(l+r)/2;
return max(query(a,b,2*k,l,m),query(a,b,2*k+1,m+1,r));
}
}
int main(){
cin>>N>>Q;
for(int i=0;i<N;i++){
cin>>c;
P[i]=(c=='1');
T[0][i]=P[i];
}
for(int i=0;i<Q;i++){
cin>>s;
if(s=="query"){
cin>>A[i]>>B[i];
A[i]--;
B[i]--;
if(B[i]-A[i]!=1)
sub2=false;
}
else{
cin>>A[i];
A[i]--;
B[i]=-1;
}
}
if(sub1 and N<=100 and Q<=100){
for(int i=0;i<Q;i++){
if(B[i]==-1)
T[i+1][A[i]]=true;
else{
int ans=0;
for(int k=0;k<i+1;k++){
bool flag=true;
for(int j=A[i];j<B[i];j++)
flag&=T[k][j];
ans+=flag;
}
cout<<ans<<"\n";
}
for(int j=0;j<N;j++)
T[i+1][j]^=T[i][j];
}
}
else if(sub2){
for(int i=0;i<N;i++)
V[i].push_back({0,0});
for(int i=0;i<Q;i++){
int k=A[i];
if(B[i]==-1){
if(P[k])
V[k].push_back({i+1,V[k].back().second+i+1-V[k].back().first});
else
V[k].push_back({i+1,V[k].back().second});
P[k]=!P[k];
}
else{
if(P[k])
cout<<V[k].back().second+i+1-V[k].back().first<<"\n";
else
cout<<V[k].back().second<<"\n";
}
}
}
else{
for(int i=0;i<N;i++){
if(!P[i])
update(i,INF);
else
update(i,0);
}
for(int i=0;i<Q;i++){
if(B[i]==-1)
update(A[i],i+1);
else
cout<<max(0,i+1-query(A[i],B[i]-1))<<"\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
7416 KB |
Output is correct |
2 |
Correct |
9 ms |
7416 KB |
Output is correct |
3 |
Correct |
8 ms |
7416 KB |
Output is correct |
4 |
Correct |
9 ms |
7416 KB |
Output is correct |
5 |
Correct |
9 ms |
7416 KB |
Output is correct |
6 |
Correct |
9 ms |
7416 KB |
Output is correct |
7 |
Correct |
9 ms |
7416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
339 ms |
12556 KB |
Output is correct |
2 |
Correct |
358 ms |
12512 KB |
Output is correct |
3 |
Correct |
414 ms |
12736 KB |
Output is correct |
4 |
Incorrect |
622 ms |
21496 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
7416 KB |
Output is correct |
2 |
Correct |
10 ms |
7420 KB |
Output is correct |
3 |
Correct |
10 ms |
7416 KB |
Output is correct |
4 |
Correct |
12 ms |
7416 KB |
Output is correct |
5 |
Incorrect |
495 ms |
17972 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
7416 KB |
Output is correct |
2 |
Incorrect |
10 ms |
7416 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
7416 KB |
Output is correct |
2 |
Correct |
9 ms |
7416 KB |
Output is correct |
3 |
Correct |
8 ms |
7416 KB |
Output is correct |
4 |
Correct |
9 ms |
7416 KB |
Output is correct |
5 |
Correct |
9 ms |
7416 KB |
Output is correct |
6 |
Correct |
9 ms |
7416 KB |
Output is correct |
7 |
Correct |
9 ms |
7416 KB |
Output is correct |
8 |
Correct |
339 ms |
12556 KB |
Output is correct |
9 |
Correct |
358 ms |
12512 KB |
Output is correct |
10 |
Correct |
414 ms |
12736 KB |
Output is correct |
11 |
Incorrect |
622 ms |
21496 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |