Submission #934390

#TimeUsernameProblemLanguageResultExecution timeMemory
934390VladaMG98Street Lamps (APIO19_street_lamps)C++17
60 / 100
449 ms22968 KiB
// Problem: C - Street Lamps // Contest: Virtual Judge - 2024-02-27 APIO Simulation // URL: https://vjudge.net/contest/612540#problem/C // Memory Limit: 512 MB // Time Limit: 5000 ms // // Powered by CP Editor (https://cpeditor.org) #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for(int i = a; i < (b); ++i) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define print(A,t) cerr << #A << ": "; copy(all(A),ostream_iterator<t>(cerr," " )); cerr << endl #define prArr(A,n,t) cerr << #A << ": "; copy(A,A + n,ostream_iterator<t>(cerr," " )); cerr << endl #define what_is(x) cerr << #x << " is " << x << endl typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef vector<int> vi; const int MAXQ = 300010; int n, q; string s; int type[MAXQ], a[MAXQ], b[MAXQ]; void subtask1() { vector<vector<bool>> history; vector<bool> cur(n); rep(i, 0, n) cur[i] = (s[i] == '1'); history.push_back(cur); rep (qq, 1, q + 1) { if (type[qq]) { int l = a[qq], r = b[qq]; l -= 1; r -= 1; int ans = 0; for (auto ev : history) { int cnt = 0; rep(k, l, r) cnt += ev[k]; if (cnt == r - l) ans += 1; } cout << ans << endl; } else { int pos = a[qq]; pos -= 1; cur[pos] = !cur[pos]; } history.push_back(cur); } } void subtask2() { vector<bool> cur(n); rep(i, 0, n) cur[i] = (s[i] == '1'); vector<int> last_turned_on(n, 0); vector<int> ans(n, 0); int cur_time = 0; rep (qq, 1, q + 1) { cur_time += 1; if (type[qq]) { int l = a[qq], r = b[qq]; l -= 1; r -= 1; // so we only care about l int ret = ans[l] + (cur[l] ? cur_time - last_turned_on[l] : 0); cout << ret << endl; } else { int pos = a[qq]; pos -= 1; if (cur[pos]) { ans[pos] += (cur_time - last_turned_on[pos]); cur[pos] = false; } else { last_turned_on[pos] = cur_time; cur[pos] = true; } } } } int t[MAXQ << 1]; void build() { for (int i = n - 1; i > 0; --i) t[i] = max(t[i << 1], t[i << 1 | 1]); } void modify (int pos, int val) { for (t[pos += n] = val; pos > 1; pos >>= 1) t[pos >> 1] = max(t[pos], t[pos ^ 1]); } int query (int l, int r) { int ans = 0; for (l += n, r += n; l < r; l >>= 1, r >>= 1) { if (l & 1) ans = max(ans, t[l++]); if (r & 1) ans = max(ans, t[--r]); } return ans; } void subtask3() { for (int i = 0; i < n; i++) t[n + i] = INT_MAX; for (int i = 0; i < n; i++) { if (s[i] == '1') t[n + i] = 0; } build(); int cur_time = 0; rep (qq, 1, q + 1) { cur_time += 1; if (type[qq]) { int l = a[qq] - 1, r = b[qq] - 1; int goes_on = query(l, r); if (goes_on >= cur_time) cout << 0 << endl; else cout << cur_time - goes_on << endl; } else { int pos = a[qq] - 1; modify(pos, cur_time); } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> q >> s; for (int i = 1; i <= q; i++) { string str; cin >> str; type[i] = (str == "query"); if (type[i]) cin >> a[i] >> b[i]; else cin >> a[i]; } if (n <= 100 && q <= 100) { subtask1(); return 0; } bool is_two = true; for (int i = 1; i <= q; i++) { if (type[i] && b[i] != a[i] + 1) { is_two = false; break; } } if (is_two) { subtask2(); return 0; } unordered_map<int, int> toggles; for (int i = 1; i <= q; i++) { if (!type[i]) toggles[a[i] - 1] += 1; } bool is_three = true; for (auto [k, v] : toggles) { if (v > 1) { is_three = false; break; } if (s[k] == '1') { is_three = false; break; } } if (is_three) { subtask3(); return 0; } 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...