Submission #1367079

#TimeUsernameProblemLanguageResultExecution timeMemory
1367079NxmkxingStreet Lamps (APIO19_street_lamps)C++20
20 / 100
39 ms4012 KiB
#include <bits/stdc++.h>
using namespace std;

const int N = 3e5 + 10;
int n, q;
string s;
int total[N], start[N];

int main() {
    cin.tie(nullptr)->ios_base::sync_with_stdio(false);
    cin >> n >> q >> s;
    for (int i = 1; i <= n; i++) {
        if (s[i-1] == '0') start[i] = -1;
        else start[i] = 0;
    }
    for (int i = 1; i <= q; i++) {
        string type;
        cin >> type;
        if (type == "toggle") {
            int pos;
            cin >> pos;
            if (start[pos] == -1) start[pos] = i;
            else {
                total[pos] += i - start[pos];
                start[pos] = -1;
            }
        } 
        else {
            int a, b;
            cin >> a >> b;
            if (start[a] == -1) cout << total[a] << "\n";
            else cout << total[a] + i - start[a] << "\n";
        }
    }
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...