#include <bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(int i = a; i < b; i++)
const int N = 3e5 + 5, M = 105;
int n, q;
int a[M][M];
string s;
void subtask_1(){
f(i,1,q+1){
f(j,1,n+1) a[i][j] = a[i-1][j];
string ty;
int x, y;
cin >> ty;
if(ty[0] == 'q'){
cin >> x >> y;
// cuantos tiempos el rango [x, y-1] suma 0
int ans = 0;
f(j,0,i){
int sum = 0;
f(r,x,y) sum += a[j][r];
if(sum == 0) ans++;
}
cout << ans << "\n";
}
else{
cin >> x;
a[i][x] = 1 - a[i][x];
}
}
}
int A[N], root[N];
vector <int> L, R, st;
int createLeaf(int val){
L.push_back(-1), R.push_back(-1);
st.push_back(val);
return L.size() - 1;
}
int createNode(int u, int v){
L.push_back(u), R.push_back(v);
st.push_back(st[u] + st[v]);
return L.size() - 1;
}
int build(int l, int r){
if(l == r) return createLeaf(A[l]);
int m = (l+r)>>1;
return createNode(build(l, m), build(m+1, r));
}
int upd(int id, int l, int r, int pos, int val){
if(r < pos or pos < l) return id;
if(l == r) return createLeaf(val);
int m = (l+r)>>1;
if(pos <= m) return createNode(upd(L[id], l, m, pos, val), R[id]);
return createNode(L[id], upd(R[id], m+1, r, pos, val));
}
int Query(int id, int l, int r, int x, int y){
if(r < x or y < l) return 0;
if(x <= l and r <= y) return st[id];
int m = (l+r)>>1;
return Query(L[id], l, m, x, y) + Query(R[id], m+1, r, x, y);
}
int que(int time, int x, int y){
return Query(root[time], 1, n, x, y);
}
void subtask_3(){
root[0] = build(1, n);
f(i,1,q+1){
root[i] = root[i-1];
string ty;
cin >> ty;
int x, y;
if(ty[0] == 'q'){
cin >> x >> y;
y--;
int ans = 0;
if(que(i-1, x, y) == 0){
int l = 0, r = i-1;
while(l < r){
int m = (l+r)>>1;
if(que(m, x, y) == 0) r = m;
else l = m+1;
}
ans = i - l;
}
cout << ans << "\n";
}
else{
cin >> x;
root[i] = upd(root[i], 1, n, x, 0);
}
}
}
int main(){
cin >> n >> q;
cin >> s;
f(i,0,n){
if(s[i] == '0') a[0][i+1] = A[i+1] = 1;
else a[0][i+1] = A[i+1] = 0;
}
if(n <= 100){
subtask_1();
return 0;
}
subtask_3();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
576 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
5 ms |
340 KB |
Output is correct |
5 |
Runtime error |
9 ms |
2032 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
324 KB |
Output is correct |
2 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |