제출 #237438

#제출 시각아이디문제언어결과실행 시간메모리
237438SortingElection (BOI18_election)C++14
0 / 100
13 ms384 KiB
#include <bits/stdc++.h>

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]);
            }
        }

        int answer2 = answer;
        for(int j = l; j <= r; ++j){
            if(a[j] == -1 && answer2){
                answer2--;
            }
            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...