# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
916863 | duckindog | Street Lamps (APIO19_street_lamps) | C++14 | 92 ms | 24752 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.
//from duckindog wth depression
#include<bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int n, q;
int a[N];
struct Query {
int ty, x, y;
Query() : ty(0), x(0), y(0) {}
Query(int ty, int x, int y) : ty(ty), x(x), y(y) {}
} Q[N];
string s[N];
void sub1() {
cin >> s[1];
for (int i = 1; i <= q; ++i) {
s[i + 1] = s[i];
string ty; cin >> ty;
if (ty == "toggle") {
int p; cin >> p;
s[i + 1][p - 1] = (s[i + 1][p - 1] == '0' ? '1' : '0');
} else {
int a, b; cin >> a >> b;
int answer = 0;
for (int j = 1; j <= i; ++j) {
bool pass = 1;
for (int t = a - 1; t < b - 1; ++t)
if (s[j][t] == '0') pass = 0;
answer += pass;
}
cout << answer << '\n';
}
}
}
int cnt[N], t[N];
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
if (fopen("duck.inp", "r")) {
freopen("duck.inp", "r", stdin);
freopen("duck.out", "w", stdout);
}
cin >> n >> q;
if (n <= 100 && q <= 100) {
sub1();
return 0;
}
for (int i = 1; i <= n; ++i) {
char x; cin >> x;
a[i] = (x == '1');
}
bool s2 = 1;
for (int i = 1; i <= q; ++i) {
string ty; cin >> ty;
if (ty == "toggle") {
int x; cin >> x;
Q[i] = {0, x, 0};
} else {
int x, y; cin >> x >> y;
Q[i] = {1, x, y};
s2 &= (y - x == 1);
}
}
if (s2) {
for (int i = 1; i <= n; ++i) {
t[i] = (a[i] == 1);
}
for (int i = 1; i <= q; ++i) {
int ty = Q[i].ty, x = Q[i].x, y = Q[i].y;
if (!ty) {
if (a[x] == 1) {
cnt[x] += i - t[x] + 1;
t[x] = i + 1;
} else {
t[x] = i + 1;
}
a[x] = 1 - a[x];
} else {
int answer = 0;
if (a[x]) {
answer = cnt[x] + i - t[x] + 1;
} else {
answer = cnt[x];
}
cout << answer << '\n';
}
}
}
}
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... |