Submission #265144

#TimeUsernameProblemLanguageResultExecution timeMemory
265144hanagasumiStreet Lamps (APIO19_street_lamps)C++17
20 / 100
235 ms30328 KiB
#include <iostream> #include <vector> #include <cmath> #include <algorithm> #include <deque> #include <map> #include <set> #include <complex> #include <string> #include <unordered_map> #include <unordered_set> #include <random> #define ft first #define sc second #define pb push_back #define len(v) (int)v.size() #define int ll #define all(v) v.begin(), v.end() using namespace std; typedef long long ll; typedef long double ld; signed main() { #ifdef PC freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, q; cin >> n >> q; vector<vector<pair<int, int>>> have(n); vector<int> ans(n, 0); for (int i = 0; i < n; i++) { char c; cin >> c; if(c == '1') have[i].pb({0, 1}); else have[i].pb({0, 0}); } for (int i = 0; i < q; i++) { string s; cin >> s; if(s == "toggle") { int id; cin >> id; id--; have[id].pb({i + 1, 1 - have[id].back().sc}); continue; } int l, r, anss = 0; cin >> l >> r; l--, r--; for (int j = 0; j < len(have[l]) - 1; j++) { if(have[l][j].sc != 1) continue; ans[l] += (have[l][j + 1].ft - have[l][j].ft); } have[l] = {have[l].back()}; anss = ans[l]; if(have[l].back().sc == 1) anss += (i + 1) - have[l].back().ft; cout << anss << '\n'; } }
#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...