Submission #572429

#TimeUsernameProblemLanguageResultExecution timeMemory
572429CpDarkStreet Lamps (APIO19_street_lamps)C++14
0 / 100
244 ms3328 KiB
#include <bits/stdc++.h> #define fastInput ios::sync_with_stdio(false); cin.tie(nullptr); using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vll; typedef vector<vll> vvll; typedef pair<ll, ll> pii; typedef vector<pii> vp; typedef vector<bool> vb; typedef vector<vb> vvb; struct segmentTree { vi st; int size; void init(int n) { for (size = 1; size < n; size *= 2) {} st.resize(2 * size); } void update(int index, int val) { index += size; st[index] = val; for (index /= 2; index; index /= 2) { st[index] = min(st[index * 2], st[index * 2 + 1]); } } int query(int l, int r) { int ans = INT_MAX; for (l += size, r += size; l <= r; l /= 2, r /= 2) { if (l % 2) { ans = min(ans, st[l]); l++; } if (r % 2 == 0) { ans = min(ans, st[r]); r--; } } return ans; } }; int main() { fastInput; int n, q; cin >> n >> q; segmentTree st; st.init(n + 1); vb lights(n+1); vi ans(n + 1); vi last(n + 1, -1); string curr; cin >> curr; for (int i = 0; i < n; i++) { if (curr[i] == '1') { lights[i + 1] = true; last[i] = 0; } else { lights[i + 1] = false; } //st.update(i + 1, lights[i + 1]); } string type; for (int i = 1; i <= q; i++) { cin >> type; if (type == "query") { int a, b; cin >> a >> b; int count = ans[a]; if (lights[a]) { count += i - last[a]; } cout << count << endl; } else { int index; cin >> index; lights[index] = !lights[index]; if (lights[index]) { last[index] = i; } else { ans[index] = i - last[index]; } } } 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...