Submission #716543

# Submission time Handle Problem Language Result Execution time Memory
716543 2023-03-30T09:29:55 Z 1zaid1 Street Lamps (APIO19_street_lamps) C++17
20 / 100
333 ms 22860 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define endl '\n'

const signed M = 3e6, MOD = 998244353;

int N = 1 << 20;
int seg[M], lazy[M], o[M];

void spread(int ind) {
    seg[ind] += lazy[ind]*o[ind];
    if (ind < N) {
        lazy[ind*2] += lazy[ind];
        lazy[ind*2+1] += lazy[ind];
    } lazy[ind] = 0;
}

int query(int x) {
    x += N-1;
    vector<int> v = {x};
    while (x /= 2) v.push_back(v.back()/2);
    reverse(v.begin(), v.end());
    for (int i:v) spread(i);
    return seg[v.back()];
}

void toggle(int x) {
    x += N-1;
    int add = 1-2*o[x];
    vector<int> v = {x};
    while (x /= 2) v.push_back(v.back()/2);
    reverse(v.begin(), v.end());
    for (int i:v) spread(i);
    reverse(v.begin(), v.end());
    for (int i:v) o[i] += add;
    return;
}

signed main() {
    cin.tie(0)->sync_with_stdio(0);

    int n, q;
    cin >> n >> q;

    string s;
    cin >> s;
    for (int i = 0; i < n; i++) {
        if (s[i] == '1') toggle(i+1);
    }

    lazy[1]++;
    while (q--) {
        string s;
        cin >> s;

        if (s == "query") {
            int l, r;
            cin >> l >> r;
            cout << query(l) << endl;
        } else {
            int x;
            cin >> x;
            toggle(x);
        }

        lazy[1]++;
    }

    return 0;
}
/*
5 7
11011
query 1 2
query 1 2
query 1 6
query 3 4
toggle 3
query 3 4
query 1 6
*/
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 158 ms 1400 KB Output is correct
2 Correct 160 ms 4852 KB Output is correct
3 Correct 173 ms 5644 KB Output is correct
4 Correct 304 ms 20780 KB Output is correct
5 Correct 311 ms 21220 KB Output is correct
6 Correct 298 ms 20592 KB Output is correct
7 Correct 246 ms 16748 KB Output is correct
8 Correct 333 ms 22860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -