This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |