Submission #934378

#TimeUsernameProblemLanguageResultExecution timeMemory
934378VladaMG98Street Lamps (APIO19_street_lamps)C++17
40 / 100
410 ms5212 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; int n, q; void subtask1() { string s; cin >> s; vector<vector<bool>> history; vector<bool> cur(n); rep(i, 0, n) cur[i] = (s[i] == '1'); history.push_back(cur); while (q--) { string what; cin >> what; if (what == "query") { int l, r; cin >> l >> r; 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; cin >> pos; pos -= 1; cur[pos] = !cur[pos]; } history.push_back(cur); } } void subtask2() { string s; cin >> s; 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; while (q--) { cur_time += 1; string what; cin >> what; if (what == "query") { int l, r; cin >> l >> r; l -= 1; r -= 1; assert (l + 1 == r); // 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; cin >> pos; 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 main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> q; if (n <= 100 && q <= 100) { subtask1(); return 0; } subtask2(); 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...