#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define sz(x) (int)x.size()
#define ff first
#define ss second
const ll N = 300005;
const ll M = 1e9 + 7;
int T, n, q, ind1[N], a1[N], b1[N], x[N], y[N];
string s[N], s1[N];
int main(){
ios::sync_with_stdio(false); cin.tie(0);
cin >> n >> q >> s[0];
if(n <= 100 and q <= 100){
for(int i = 1; i <= q; i++){
string s1;
cin >> s1;
s[i] = s[i-1];
if(s1 == "toggle"){
int ind;
cin >> ind;
ind--;
if(s[i][ind] == '1') s[i][ind] = '0';
else s[i][ind] = '1';
}
else {
int a, b, ans = 0;
cin >> a >> b;
for(int j = 0; j <= i-1; j++){
bool tr = 0;
for(int k = a-1; k < b-1; k++){
if(s[j][k] == '0'){
tr = 1;
break;
}
}
ans += (tr == 0);
}
cout << ans << '\n';
}
}
}
else {
for(int i = 0; i < sz(s[0]); i++){
if(s[0][i] == '1') x[i] = 0;
else x[i] = -1;
}
for(int i = 1; i <= q; i++){
string s1;
cin >> s1;
if(s1 == "toggle"){
int ind;
cin >> ind;
ind--;
if(s[0][ind] == '0'){
x[ind] = i;
s[0][ind] = '1';
}
else {
y[ind] += abs(i-x[ind]);
x[ind] = -1;
s[0][ind] = '0';
}
}
else {
int a, b, ans;
cin >> a >> b;
a--;
ans = y[a];
if(x[a] != -1) ans += (abs(i-x[a]));
cout << ans << "\n";
}
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
19032 KB |
Output is correct |
2 |
Correct |
7 ms |
19036 KB |
Output is correct |
3 |
Correct |
7 ms |
19100 KB |
Output is correct |
4 |
Correct |
7 ms |
19036 KB |
Output is correct |
5 |
Correct |
7 ms |
19032 KB |
Output is correct |
6 |
Correct |
7 ms |
19172 KB |
Output is correct |
7 |
Correct |
10 ms |
19036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
20048 KB |
Output is correct |
2 |
Correct |
55 ms |
23632 KB |
Output is correct |
3 |
Correct |
67 ms |
24088 KB |
Output is correct |
4 |
Correct |
86 ms |
27620 KB |
Output is correct |
5 |
Correct |
64 ms |
27112 KB |
Output is correct |
6 |
Correct |
58 ms |
27364 KB |
Output is correct |
7 |
Correct |
79 ms |
27368 KB |
Output is correct |
8 |
Correct |
75 ms |
28568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
19032 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
19036 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
19032 KB |
Output is correct |
2 |
Correct |
7 ms |
19036 KB |
Output is correct |
3 |
Correct |
7 ms |
19100 KB |
Output is correct |
4 |
Correct |
7 ms |
19036 KB |
Output is correct |
5 |
Correct |
7 ms |
19032 KB |
Output is correct |
6 |
Correct |
7 ms |
19172 KB |
Output is correct |
7 |
Correct |
10 ms |
19036 KB |
Output is correct |
8 |
Correct |
50 ms |
20048 KB |
Output is correct |
9 |
Correct |
55 ms |
23632 KB |
Output is correct |
10 |
Correct |
67 ms |
24088 KB |
Output is correct |
11 |
Correct |
86 ms |
27620 KB |
Output is correct |
12 |
Correct |
64 ms |
27112 KB |
Output is correct |
13 |
Correct |
58 ms |
27364 KB |
Output is correct |
14 |
Correct |
79 ms |
27368 KB |
Output is correct |
15 |
Correct |
75 ms |
28568 KB |
Output is correct |
16 |
Incorrect |
8 ms |
19032 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |