제출 #137574

#제출 시각아이디문제언어결과실행 시간메모리
137574mechfrog88Election (BOI18_election)C++14
28 / 100
3010 ms1100 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll n,q;
    cin >> n;
    string a;
    cin >> a;
    cin >> q;
    for (int z=0;z<q;z++){
        ll l,r;
        cin >> l >> r;
        l--;r--;
        ll c = 0;
        ll t = 0;
        vector <bool> arr(n,false);
        for (int x=l;x<=r;x++){
            if (a[x] == 'C'){
                c++;
            } else {
                t++;
            }
            if (t > c){
                t--;
                arr[x] = true;
            }
        }
        c = 0;
        t = 0;
        for (int x=r;x>=l;x--){
            if (a[x] == 'C'){
                c++;
            } else if (!arr[x]){
                t++;
            }
            if (t > c){
                t--;
                arr[x] = true;
            }
        }
        ll ans = 0;
        for (int z=0;z<n;z++){
            if (arr[z]) ans++;
        }
        cout << ans << endl;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...