Submission #237428

#TimeUsernameProblemLanguageResultExecution timeMemory
237428SortingElection (BOI18_election)C++14
28 / 100
3078 ms2124 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const int mx_N = 5e5 + 3; int n, q; string s; int a[mx_N]; int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cin >> n >> s; for(int i = 0; i < n; ++i) a[i + 1] = (s[i] == 'C') ? 1 : -1; cin >> q; for(int i = 0; i < q; ++i){ int l, r; cin >> l >> r; vector<int> v; int sum = 0, answer = 0; for(int j = l; j <= r; ++j){ if(!sum && a[j] == -1) answer++; else{ sum += a[j]; v.push_back(a[j]); } } reverse(v.begin(), v.end()); sum = 0; for(int x: v){ if(!sum && x == -1) answer++; else sum += x; } cout << answer << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...