//#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
const int DIM = 3E5+7;
int n,q;
int A[DIM];
struct node{
int type,a,b;
} Q[DIM];
const int SZ = 107;
vector<node> V[SZ];
int ans[DIM];
void solve(){
for(int i = q;i>=1;--i){
V[i] = V[i+1];
if (Q[i].type==1)
V[i].push_back({i,Q[i].a,Q[i].b});
}
for(int i = 1;i<=q;++i){
for(auto to:V[i]){
ll flag = 0;
for(int j = to.a;j<to.b;++j){
if (!A[j]){
flag = 1;
break;
}
}
if (!flag)
ans[to.type]++;
}
if (Q[i].type==0)
A[Q[i].a]^=1;
if (Q[i].type)
cout<<ans[i]<<endl;
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>q;
for(int i = 1;i<=n;++i){
char ch;
cin>>ch;
A[i] = int(ch-'0');
}
for(int i = 1;i<=q;++i){
string s;
cin>>s;
Q[i].type = (s=="query");
if (Q[i].type==1)
cin>>Q[i].a>>Q[i].b;
else cin>>Q[i].a;
}
if (n<=100 && q<=100)
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
66 ms |
3780 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Incorrect |
66 ms |
3780 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |