Submission #966775

#TimeUsernameProblemLanguageResultExecution timeMemory
966775kilkuwuStreet Lamps (APIO19_street_lamps)C++17
20 / 100
5059 ms524288 KiB
#include <bits/stdc++.h> #define nl '\n' #ifdef LOCAL #include "template/debug.hpp" #else #define dbg(...) ; #define timer(...) ; #endif signed main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n, q; std::cin >> n >> q; std::vector<std::string> state(q + 1); std::cin >> state[0]; std::vector<std::vector<int>> pref(q + 1); auto make_pref = [&](int id) { pref[id].resize(n + 1); pref[id][0] = 0; for (int i = 0; i < n; i++) { pref[id][i + 1] = pref[id][i] + (state[id][i] == '1'); } }; make_pref(0); for (int tt = 1; tt <= q; tt++) { std::string com; std::cin >> com; state[tt] = state[tt - 1]; if (com == "toggle") { int i; std::cin >> i; --i; state[tt][i] = '1' ^ '0' ^ state[tt][i]; make_pref(tt); } else { make_pref(tt); int a, b; std::cin >> a >> b; --a, --b; int ans = 0; for (int x = 0; x < tt; x++) { ans += pref[x][b] - pref[x][a] == b - a; } std::cout << ans << nl; } } }
#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...