#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
using namespace std ;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 1000 + 10 , inf = 1e9+10 ;
int pre[maxn][maxn] ;
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n , q;
cin >>n >> q;
string s;
cin >> s;
s= "0" + s;
for(int j = 1; j <= n ; j++){
pre[0][j] = pre[0][j-1] + (s[j] == '0');
}
for(int i = 1; i <= q ; i++){
string a ;
cin >> a;
if(a[0] == 't'){
int x;
cin >> x;
if(s[x] == '0')s[x] = '1' ;
else s[x] = '0' ;
}
for(int j = 1; j <= n; j++){
pre[i][j] = pre[i][j-1] + (s[j] == '0') ;
}
if(a[0] == 'q'){
int r , l;
cin >> l >> r ;
r--;
int ans = 0 ;
for(int j = 0; j < i ;j++){
if(pre[j][r] == pre[j][l-1]){
ans ++ ;
}
}
cout <<ans << "\n";
}
}
}
/*
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 |
Correct |
0 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
7 ms |
8552 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4180 KB |
Output is correct |
2 |
Correct |
4 ms |
4284 KB |
Output is correct |
3 |
Correct |
6 ms |
4316 KB |
Output is correct |
4 |
Correct |
5 ms |
4308 KB |
Output is correct |
5 |
Runtime error |
420 ms |
9888 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4180 KB |
Output is correct |
2 |
Correct |
5 ms |
4248 KB |
Output is correct |
3 |
Correct |
5 ms |
4308 KB |
Output is correct |
4 |
Correct |
4 ms |
4308 KB |
Output is correct |
5 |
Runtime error |
419 ms |
9904 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Runtime error |
7 ms |
8552 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |