Submission #546208

#TimeUsernameProblemLanguageResultExecution timeMemory
546208Ooops_sorryStreet Lamps (APIO19_street_lamps)C++14
20 / 100
454 ms524288 KiB
#include<bits/stdc++.h>

using namespace std;

#define int long long
#define pb push_back
#define ld double
#define ll __int128

mt19937 rnd(51);

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif // LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    vector<int> s(n);
    vector<vector<int>> sum(n, vector<int>(n));
    set<int> st{-1, n};
    for (int i = 0; i < n; i++) {
        char c;
        cin >> c;
        s[i] = c - '0';
        if (s[i] == 0) {
            st.insert(i);
        }
    }
    for (int i = 0; i < q; i++) {
        string t;
        cin >> t;
        if (t == "toggle") {
            int j;
            cin >> j;
            j--;
            if (st.find(j) == st.end()) {
                auto l = *prev(st.lower_bound(j)), r = *st.upper_bound(j);
                for (int k = l + 1; k <= j; k++) {
                    for (int f = j; f <= r - 1; f++) {
                        sum[k][f] += i + 1;
                    }
                }
                st.insert(j);
            } else {
                st.erase(j);
                auto l = *prev(st.lower_bound(j)), r = *st.upper_bound(j);
                for (int k = l + 1; k <= j; k++) {
                    for (int f = j; f <= r - 1; f++) {
                        sum[k][f] -= i + 1;
                    }
                }
            }
        } else {
            int l, r;
            cin >> l >> r;
            l--, r -= 2;
            bool good = 1;
            int ans = sum[l][r];
            for (int j = l; j <= r; j++) {
                if (st.find(j) != st.end()) {
                    good = 0;
                }
            }
            if (good) ans += i + 1;
            cout << ans << endl;
        }
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...