#include<bits/stdc++.h>
using namespace std;
int n, q, last[300005], ct[300005];
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin>>n>>q;
string s;
cin>>s;
for(int i=0;i<n;i++) {
if(s[i]-'0'==1) last[i] = 0;
else last[i] = -1;
}
for(int i=1;i<=q;i++) {
cin>>s;
if(s[0]=='q') {
int a, b;
cin>>a>>b;
cout<<ct[a]+(last[a]==-1 ? 0:i-last[a])<<'\n';
} else {
int a;
cin>>a;
if(last[a]==-1) {
last[a] = i;
} else {
ct[a] += (last[a]==-1 ? 0:i-last[a]);
last[a] = -1;
}
}
}
}
/*
5 7
11011
query 1 2
query 1 2
query 1 6
query 3 4
toggle 3
query 3 4
query 1 6
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
52 ms |
6484 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |