제출 #1232803

#제출 시각아이디문제언어결과실행 시간메모리
1232803AdnanboiElection (BOI18_election)C++20
0 / 100
4 ms320 KiB
#include <bits/stdc++.h>

using namespace std;

const int MOD = 1e9 + 7;

void solve(){
	int n; 
    cin>>n;
    string s; 
    cin>>s;
    int q; 
    cin>>q;
    while(q--){
        int l,r;
        cin>>l>>r;
        --l; --r;
        int cf=0, tf=0, remf=0;
        for(int i = l; i <= r; i++){
            if(s[i] == 'C'){
                cf++;
            } 
            else{
                if(tf + 1 > cf) remf++;
                else tf++;
            }
        }
        int cb = 0, tb = 0, remb = 0;
        for(int i = r; i >= l; i--){
            if(s[i] == 'C'){
                cb++;
            } 
            else{
                if(tb + 1 > cb) remb++;
                else tb++;
            }
        }
        cout<<max(remf, remb)<<"\n";
    }
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	//cin>>t;
	while(t--){
		solve();
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...