# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
163964 | Leonardo_Paes | Street Lamps (APIO19_street_lamps) | C++17 | 8 ms | 5368 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;
const int maxn = 1e5+10;
int n, q;
string initial;
vector<int> toggles;
vector<int> events[maxn];
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin >> n >> q;
initial.resize(n+2);
for(int i=1; i<=n; i++){
cin >> initial[i];
if(initial[i]=='0') events[i].push_back(0);
}
toggles.push_back(0);
if(n<=100 and q<=100){
for(int t=1; t<=q; t++){
string op;
cin >> op;
if(op[0] == 'q'){
int a, b;
cin >> a >> b;
string now = initial;
int ans = 0;
for(int i=0; i<toggles.size(); i++){
if(now[toggles[i]]=='0') now[toggles[i]] = '1';
else now[toggles[i]] = '0';
bool ok = true;
for(int j=a; j<b; j++) if(now[j] == '0') ok = false;
if(ok) ans++;
}
cout << ans << endl;
toggles.push_back(0);
}
else{
int i;
cin >> i;
toggles.push_back(i);
}
}
}
else{
for(int t=1; t<=q; t++){
string op;
cin >> op;
if(op[0] == 'q'){
int a, b;
cin >> a >> b;
int ans = 0;
for(int i=0; i<events[a].size(); i++){
if(i%2){
ans += events[a][i] - events[a][i-1];
}
else{
continue;
}
}
if(events[a].size()%2 == 0) ans += t - events[a].back();
cout << ans << endl;
}
else{
int i;
cin >> i;
events[i].push_back(t);
}
}
}
return 0;
}
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... |