#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)3e5+10;
string s;
int a[maxn];
int cnt[maxn], ti[maxn];
int n, q;
int32_t main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> q >> s;
for(int i = 1; i <= n; i++){
a[i] = (s[i-1]=='1');
ti[i] = (a[i]==1?0:-1);
}
for(int i = 1; i <= q; i++){
int x, y; cin >> s >> x;
if(s[0]=='t'){
a[x]^=1;
//if turned to 1, cnt[x]+=now-last time it was turned to 1
//cntx = number of times x was 0
//ti x = last time x was a 1
if(a[x]==1){
if(ti[x]!=-1) cnt[x]+=i-ti[x]-1;
else cnt[x]=i;
ti[x]=i;
}
else ti[x]=i-1;
}
else{
cin >> y;
int tot = 0;
//cout << i << " " << cnt[x] << " " << ti[x] << " ";
if(ti[x]!=-1){
tot = ti[x]-cnt[x];
if(a[x]) tot+=i-ti[x];
}
cout << tot << "\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
56 ms |
1236 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |