This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
//Types
using ll = long long;
using db = double;
//Vectors
#define pb push_back
#define sz(vec) ((ll)vec.size())
#define all(vec) vec.begin(), vec.end()
//things
#define f first
#define s second
const int SMALLINF = 1e9 + 7;
const ll BIGINF = ((ll)1e18) + 7;
#define Speeed ios::sync_with_stdio(0);cin.tie(NULL); cout.tie(NULL);
void solve(){
ll n, q;
string s;
cin>>n>>s>>q;
while(q--){
ll l, r, cntc = 0, cnte = 0, ans = 0;
map<ll, bool> mark;
cin>>l>>r;
l--, r--;
for(ll i = l; i <= r; i++){
if(s[i]=='C')cntc++;
else if(!mark[i])cnte++;
if(cnte>cntc){
if(!mark[i]){
cnte--;
mark[i] = true;
ans++;
}
}
}
cntc = 0, cnte = 0;
for(ll i = r; i >= l; i--){
if(s[i]=='C')cntc++;
else if(!mark[i])cnte++;
if(cnte>cntc){
if(!mark[i]){
cnte--;
mark[i] = true;
ans++;
}
}
}
cout<<ans<<"\n";
}
}
int main(){
Speeed
ll t=1;
// cin>>t;
while(t--){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |