Submission #572428

#TimeUsernameProblemLanguageResultExecution timeMemory
572428CpDarkStreet Lamps (APIO19_street_lamps)C++14
20 / 100
5087 ms4308 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); string curr; cin >> curr; for (int i = 0; i < n; i++) { if (curr[i] == '1') { lights[i + 1] = true; } else { lights[i + 1] = false; } st.update(i + 1, lights[i + 1]); } vvi ans(n + 2, vi(n + 2)); string type; for (int i = 0; i < q; i++) { for (int v = 1; v <= n + 1; v++) { for (int u = v; u <= n + 1; u++) { if (st.query(v, u - 1) == 1) { ans[v][u]++; } } } cin >> type; if (type == "query") { int a, b; cin >> a >> b; cout << ans[a][b] << endl; } else { int index; cin >> index; lights[index] = !lights[index]; st.update(index, lights[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...