제출 #855824

#제출 시각아이디문제언어결과실행 시간메모리
855824NeroZein가로등 (APIO19_street_lamps)C++17
0 / 100
1 ms604 KiB
#include "bits/stdc++.h" using namespace std; #ifdef Nero #include "Deb.h" #else #define deb(...) #endif const int INF = 1e9; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n, q; cin >> n >> q; string s; cin >> s; set<array<int, 3>> se; for (int i = 0; i < n; ++i) { if (s[i] == '0') { continue; } int j = i; while (j + 1 < n && s[j + 1] == '1') { j++; } se.insert({i, j, 0}); i = j; } auto edit_set = [&](int i, int t) { if (s[i] == '1') { array<int, 3> key = {i, INF, INF}; auto f = se.upper_bound(key); --f; if (i > 0 && i < n - 1 && s[i - 1] == '1' && s[i + 1] == '1') { int l = (*f)[0], r = (*f)[1]; se.erase(f); se.insert({l, i - 1, t}); se.insert({i + 1, r, t}); } else if (i > 0 && s[i - 1] == '1') { int l = (*f)[0]; se.erase(f); se.insert({l, i - 1, t}); } else if (i < n - 1 && s[i + 1] == '1') { int r = (*f)[1]; se.erase(f); se.insert({i + 1, r, t}); } } else { if (i > 0 && i < n - 1 && s[i - 1] == '1' && s[i + 1] == '1') { array<int, 3> key = {i, -1, -1}; auto pr = se.upper_bound(key); --pr; key = {i, INF, INF}; auto nx = se.upper_bound(key); int l = (*pr)[0], r = (*nx)[1]; se.erase(pr); se.erase(nx); se.insert({l, r, t}); } else if (i > 0 && s[i - 1] == '1') { array<int, 3> key = {i, -1, -1}; auto pr = se.upper_bound(key); int l = (*pr)[0], r = i; se.erase(pr); se.insert({l, r, t}); } else if (i < n - 1 && s[i + 1] == '1') { array<int, 3> key = {i, INF, INF}; auto nx = se.upper_bound(key); int l = i, r = (*nx)[1]; se.insert({l, r, t}); } else { se.insert({i, i, t}); } } s[i] ^= 1; }; vector<vector<pair<int, int>>> vec(n); for (int i = 1; i <= q; ++i) { string qs; cin >> qs; if (qs == "query") { int l, r; cin >> l >> r; --l, r -= 2; int ans = 0; array<int, 3> key = {l, INF, INF}; auto f = se.upper_bound(key); if (f != se.begin()) { --f; if ((*f)[0] <= l && (*f)[1] >= r) { ans += i - (*f)[2]; } } cout << ans << '\n'; } else { int ind; cin >> ind; edit_set(ind - 1, i); } } 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...