#include <bits/stdc++.h>
#define fastInput ios::sync_with_stdio(false); cin.tie(nullptr);
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pii;
typedef vector<pii> vp;
typedef vector<bool> vb;
typedef vector<vb> vvb;
struct segmentTree
{
vi st;
int size;
void init(int n) {
for (size = 1; size < n; size *= 2) {}
st.resize(2 * size);
}
void update(int index, int val) {
index += size;
st[index] = val;
for (index /= 2; index; index /= 2) {
st[index] = min(st[index * 2], st[index * 2 + 1]);
}
}
int query(int l, int r) {
int ans = INT_MAX;
for (l += size, r += size; l <= r; l /= 2, r /= 2) {
if (l % 2) {
ans = min(ans, st[l]);
l++;
}
if (r % 2 == 0) {
ans = min(ans, st[r]);
r--;
}
}
return ans;
}
};
int main() {
fastInput;
int n, q;
cin >> n >> q;
segmentTree st;
st.init(n + 1);
vb lights(n+1);
string curr;
cin >> curr;
for (int i = 0; i < n; i++) {
if (curr[i] == '1') {
lights[i + 1] = true;
}
else {
lights[i + 1] = false;
}
st.update(i + 1, lights[i + 1]);
}
vvi ans(n + 2, vi(n + 2));
string type;
for (int i = 0; i < q; i++) {
for (int v = 1; v <= n + 1; v++) {
for (int u = v; u <= n + 1; u++) {
if (st.query(v, u - 1) == 1) {
ans[v][u]++;
}
}
}
cin >> type;
if (type == "query") {
int a, b;
cin >> a >> b;
cout << ans[a][b] << endl;
}
else {
int index;
cin >> index;
lights[index] = !lights[index];
st.update(index, lights[index]);
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
15 ms |
340 KB |
Output is correct |
5 |
Correct |
13 ms |
340 KB |
Output is correct |
6 |
Correct |
13 ms |
320 KB |
Output is correct |
7 |
Correct |
13 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5052 ms |
1076 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5086 ms |
4284 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5087 ms |
4308 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
15 ms |
340 KB |
Output is correct |
5 |
Correct |
13 ms |
340 KB |
Output is correct |
6 |
Correct |
13 ms |
320 KB |
Output is correct |
7 |
Correct |
13 ms |
340 KB |
Output is correct |
8 |
Execution timed out |
5052 ms |
1076 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |