#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve(vector<int>ar){
int n=ar.size()-1;
vector<int>br=ar;
priority_queue<int>pq;
int tot=0;
int ret=0;
for(int i=1;i<=n;i++){
tot+=ar[i];
if(tot<0){
tot+=1;br[i]=0;ret++;
}
}
tot=0;
for(int i=n;i>=1;i--){
tot+=br[i];
if(tot<0){
tot+=1;br[i]=0;ret++;
}
}
cout<<ret<<endl;
}
int n;int Q;
int ar[500005];
signed main(){
cin>>n;
{
string s;
cin>>s;
for(int i=0;i<n;i++){
if(s[i]=='C'){
ar[i+1]=1;
}else{
ar[i+1]=-1;
}
}
}
cin>>Q;
while(Q--){
int l;int r;
cin>>l>>r;
vector<int>vc;
vc.push_back(0);
for(int i=l;i<=r;i++){
vc.push_back(ar[i]);
}
solve(vc);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
604 KB |
Output is correct |
2 |
Correct |
7 ms |
604 KB |
Output is correct |
3 |
Correct |
7 ms |
604 KB |
Output is correct |
4 |
Correct |
7 ms |
548 KB |
Output is correct |
5 |
Correct |
7 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
604 KB |
Output is correct |
2 |
Correct |
7 ms |
604 KB |
Output is correct |
3 |
Correct |
7 ms |
604 KB |
Output is correct |
4 |
Correct |
7 ms |
548 KB |
Output is correct |
5 |
Correct |
7 ms |
604 KB |
Output is correct |
6 |
Execution timed out |
3026 ms |
6400 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
604 KB |
Output is correct |
2 |
Correct |
7 ms |
604 KB |
Output is correct |
3 |
Correct |
7 ms |
604 KB |
Output is correct |
4 |
Correct |
7 ms |
548 KB |
Output is correct |
5 |
Correct |
7 ms |
604 KB |
Output is correct |
6 |
Execution timed out |
3026 ms |
6400 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |