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>
using namespace std;
#define ll long long
#define ar array
const int mxN=3e5;
int n, q, ans[mxN], st[mxN];
string s;
vector<int> changes[mxN];
vector<ar<int, 2>> qry[mxN];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> q >> s;
for (int i=0; i<n; ++i)
if (s[i]=='0')
changes[i].push_back(-1);
for (int i=0; i<q; ++i) {
string type;
cin >> type;
if (type=="toggle") {
int x;
cin >> x, --x;
changes[x].push_back(i);
} else {
int l, r;
cin >> l >> r, --l, r-=2;
qry[r].push_back({l, i});
}
ans[i]=-1;
}
for (int i=0; i<n; ++i) {
for (int j=0; j<changes[i].size(); j+=2) {
int b=j+1<changes[i].size()?changes[i][j+1]:q-1;
for (int k=changes[i][j]+1; k<=b; ++k)
st[k]=i+1;
}
for (auto [l, t] : qry[i]) {
ans[t]=0;
for (int j=0; j<=t; ++j)
ans[t]+=st[j]<=l;
}
}
for (int i=0; i<q; ++i)
if (~ans[i])
cout << ans[i] << "\n";
return 0;
}
Compilation message (stderr)
street_lamps.cpp: In function 'int main()':
street_lamps.cpp:35:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for (int j=0; j<changes[i].size(); j+=2) {
| ~^~~~~~~~~~~~~~~~~~
street_lamps.cpp:36:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | int b=j+1<changes[i].size()?changes[i][j+1]:q-1;
| ~~~^~~~~~~~~~~~~~~~~~
# | 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... |