Submission #565655

#TimeUsernameProblemLanguageResultExecution timeMemory
565655RealSnakeElection (BOI18_election)C++14
28 / 100
3082 ms944 KiB
#include "bits/stdc++.h" using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define ll long long #define mod 1000000007 ofstream fout(".out"); ifstream fin(".in"); signed main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, q; string st; cin >> n >> st >> q; int b[n] = {}; while(q--) { int l, r; cin >> l >> r; l--; r--; int c = 0, ans = 0; for(int i = l; i <= r; i++) { if(st[i] == 'C') c++; else { if(!c) { b[i] = 1; ans++; } else c--; } } c = 0; for(int i = r; i >= l; i--) { if(b[i]) { b[i] = 0; continue; } if(st[i] == 'C') c++; else { if(!c) ans++; else c--; } } cout << ans << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...