#include<bits/stdc++.h>
using namespace std;
#define int long long
int n;int Q;
string tss;
int ar[300005];
string typ[300005];int qa[300005];int qb[300005];
int ps[300005];
int ans[300005];
signed main(){
cin>>n>>Q;
cin>>tss;tss="*"+tss;
for(int i=1;i<=n;i++){
ar[i]=tss[i]-'0';
}
for(int i=1;i<=Q;i++){
cin>>typ[i];
if(typ[i][0]=='q'){
cin>>qa[i]>>qb[i];
}else{
cin>>qa[i];
}
}
for(int i=1;i<=n;i++){
ps[i]=ps[i-1]+ar[i];
}
for(int i=1;i<=Q;i++){
for(int j=i;j<=Q;j++){
if(typ[j][0]=='q'){
int len=qb[j]-1-qa[j]+1;
if(ps[qb[j]-1]-ps[qa[j]-1]==len){
ans[j]++;
}
}
}
if(typ[i][0]=='t'){
ar[qa[i]]^=1;
for(int j=1;j<=n;j++){
ps[j]=ps[j-1]+ar[j];
}
}
}
for(int i=1;i<=Q;i++){
if(typ[i][0]=='q'){
cout<<ans[i]<<"\n";
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9696 KB |
Output is correct |
2 |
Correct |
5 ms |
9708 KB |
Output is correct |
3 |
Correct |
5 ms |
9620 KB |
Output is correct |
4 |
Correct |
5 ms |
9684 KB |
Output is correct |
5 |
Correct |
5 ms |
9640 KB |
Output is correct |
6 |
Correct |
5 ms |
9720 KB |
Output is correct |
7 |
Correct |
5 ms |
9684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5048 ms |
19840 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
9684 KB |
Output is correct |
2 |
Correct |
9 ms |
9724 KB |
Output is correct |
3 |
Correct |
8 ms |
9684 KB |
Output is correct |
4 |
Correct |
7 ms |
9684 KB |
Output is correct |
5 |
Execution timed out |
5049 ms |
23748 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
9684 KB |
Output is correct |
2 |
Correct |
8 ms |
9720 KB |
Output is correct |
3 |
Correct |
8 ms |
9684 KB |
Output is correct |
4 |
Correct |
10 ms |
9700 KB |
Output is correct |
5 |
Execution timed out |
5046 ms |
25352 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9696 KB |
Output is correct |
2 |
Correct |
5 ms |
9708 KB |
Output is correct |
3 |
Correct |
5 ms |
9620 KB |
Output is correct |
4 |
Correct |
5 ms |
9684 KB |
Output is correct |
5 |
Correct |
5 ms |
9640 KB |
Output is correct |
6 |
Correct |
5 ms |
9720 KB |
Output is correct |
7 |
Correct |
5 ms |
9684 KB |
Output is correct |
8 |
Execution timed out |
5048 ms |
19840 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |