Submission #571423

#TimeUsernameProblemLanguageResultExecution timeMemory
571423BackNoobElection (BOI18_election)C++14
28 / 100
3070 ms1132 KiB
#include <bits/stdc++.h> #define ll long long #define fi first #define se second #define endl '\n' #define MASK(i) (1LL << (i)) #define ull unsigned long long #define ld long double #define pb push_back #define all(x) (x).begin() , (x).end() #define BIT(x , i) ((x >> (i)) & 1) #define TASK "task" #define sz(s) (int) (s).size() using namespace std; const int mxN = 5e5 + 227; const int inf = 1e9 + 277; const int mod = 24211007; const ll infll = 1e18 + 7; const int base = 200; const int LOG = 29; template <typename T1, typename T2> bool minimize(T1 &a, T2 b) { if (a > b) {a = b; return true;} return false; } template <typename T1, typename T2> bool maximize(T1 &a, T2 b) { if (a < b) {a = b; return true;} return false; } int n; int q; string s; bool vis[mxN]; void solve() { cin >> n; cin >> s; cin >> q; while(q--) { int l, r; cin >> l >> r; for(int i = l; i <= r; i++) vis[i] = false; int cur = 0; int tmp = 0; for(int i = l; i <= r; i++) { if(s[i - 1] == 'C') ++cur; else --cur; if(cur < 0) { if(vis[i] == false) { ++tmp; vis[i] = true; } cur = 0; } } cur = 0; for(int i = r; i >= l; i--) { if(vis[i] == true) continue; if(s[i - 1] == 'C') ++cur; else --cur; if(cur < 0) { if(vis[i] == false) { vis[i] = true; ++tmp; } ++cur; } } cout << tmp << endl; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); //freopen(TASK".in" , "r" , stdin); //freopen(TASK".out" , "w" , stdout); int tc = 1; // cin >> tc; while(tc--) { solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...