#include <bits/stdc++.h>
#define Alora "cownav"
#define fi(i,a,b) for(int i = a; i <= b; i++)
#define fid(i,a,b) for(int i = a; i >= b; i--)
#define ll long long
#define f first
#define se second
#define pii pair<int, int>
#define getbit(i, j) ((i >> j) & 1)
#define all(v) v.begin(), v.end()
#define pb push_back
#define maxn 300005
const int M = 1e9 + 7;
using namespace std;
int n, m, st[maxn*4];
string s;
void build(int id, int l, int r){
if(l == r){
if(s[l] == '1') st[id] = 0;
else st[id] = 1e9;
return;
}
int m = (l + r)/2;
build(id*2, l, m);
build(id*2 + 1, m + 1, r);
st[id] = max(st[id*2], st[id*2 + 1]);
}
void ud(int id, int l, int r, int u, int x){
if(l > u || r < u) return;
if(l == r) {st[id] = x; return;}
int m = (l + r)/2;
ud(id*2, l, m, u, x);
ud(id*2 + 1, m + 1, r, u, x);
st[id] = max(st[id*2], st[id*2 + 1]);
}
int get(int id, int l, int r, int u, int v){
if(l > v || r < u) return 0;
if(u <= l && r <= v) return st[id];
int m = (l + r)/2;
return max(get(id*2, l, m, u, v), get(id*2 + 1, m + 1, r, u, v));
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
if(fopen(Alora".inp","r")){
freopen(Alora".inp","r",stdin);
freopen(Alora".out","w",stdout);}
cin >> n >> m;
cin >> s; s = ' ' + s;
build(1, 1, n);
fi(i, 1, m){
string c; cin >> c;
if(c == "toggle"){
int x; cin >> x;
ud(1, 1, n, x, i);
}
else{
int a, b; cin >> a >> b;
int x = get(1, 1, n, a, b - 1);
if(x == 1e9) cout << 0 << '\n';
else cout << i - x << '\n';
}
}
return 0;
}
Compilation message
street_lamps.cpp: In function 'int main()':
street_lamps.cpp:50:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
50 | freopen(Alora".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
street_lamps.cpp:51:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
51 | freopen(Alora".out","w",stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
70 ms |
928 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
476 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
92 ms |
9404 KB |
Output is correct |
6 |
Correct |
118 ms |
9996 KB |
Output is correct |
7 |
Correct |
143 ms |
10680 KB |
Output is correct |
8 |
Correct |
178 ms |
13088 KB |
Output is correct |
9 |
Correct |
70 ms |
3988 KB |
Output is correct |
10 |
Correct |
76 ms |
4176 KB |
Output is correct |
11 |
Correct |
81 ms |
4440 KB |
Output is correct |
12 |
Correct |
179 ms |
11484 KB |
Output is correct |
13 |
Correct |
179 ms |
12988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |