#include <bits/stdc++.h>
using namespace std;
int main(){
cin.tie(0)->sync_with_stdio(0);
int n, q; cin >> n >> q;
vector<bool> a(n);
for (int i = 0; i < n; i++){
char c; cin >> c;
a[i] = c - '0';
}
vector<vector<int>> dt(q);
for (int qq = 0; qq < q; qq++){
string t; cin >> t;
if (t == "toggle"){
int i; cin >> i;
i--;
dt[qq].push_back(i);
}else{
int l, r; cin >> l >> r;
l--, r--;
int ans = 0;
for (int tt = 0; tt <= qq; tt++){
bool flag = 1;
for (int i = l; i < r; i++)
flag &= a[i];
ans += flag;
for (auto &i: dt[tt])
a[i] = !a[i];
}
cout << ans << '\n';
for (int tt = qq; tt >= 0; tt--){
for (auto &i: dt[tt])
a[i] = !a[i];
}
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5049 ms |
8228 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
85 ms |
368 KB |
Output is correct |
3 |
Correct |
125 ms |
344 KB |
Output is correct |
4 |
Correct |
165 ms |
340 KB |
Output is correct |
5 |
Execution timed out |
5034 ms |
7760 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
164 ms |
360 KB |
Output is correct |
2 |
Correct |
149 ms |
352 KB |
Output is correct |
3 |
Correct |
92 ms |
364 KB |
Output is correct |
4 |
Correct |
13 ms |
388 KB |
Output is correct |
5 |
Execution timed out |
5081 ms |
7668 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Execution timed out |
5049 ms |
8228 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |