# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
985263 | nnin | Street Lamps (APIO19_street_lamps) | C++14 | 5022 ms | 524288 KiB |
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;
int n, q;
vector<pair<int,vector<int>>> mat;
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin>>n>>q;
string s;
cin>>s;
mat.push_back({0, vector<int>(n+1)});
mat[0].second[0] = 0;
for(int i=0;i<n;i++) {
mat[0].second[i+1] = mat[0].second[i];
if(s[i]-'0'==1) mat[0].second[i+1]++;
}
for(int i=1;i<=q;i++) {
cin>>s;
if(s[0]=='q') {
int a, b;
cin>>a>>b;
int ans = 0;
for(int j=0;j<mat.size();j++) {
if(mat[j].second[b-1]-mat[j].second[a-1]!=b-a) continue;
if(j+1<mat.size()) ans += mat[j+1].first-mat[j].first;
else ans += i-mat[j].first;
}
cout<<ans<<'\n';
} else {
int a;
cin>>a;
int idx = mat.size();
mat.push_back({i, mat[idx-1].second});
for(int j=a;j<=n;j++) mat[idx].second[j]++;
}
}
}
/*
5 7
11011
query 1 2
query 1 2
query 1 6
query 3 4
toggle 3
query 3 4
query 1 6
*/
Compilation message (stderr)
# | 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... |