#include"bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long a[2000005],up[2000005];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n;
cin>>n;
string s;
cin>>s;
long long q;
cin>>q;
for(int i=0;i<q;i++)
{
long long fr,sc;
cin>>fr>>sc;
long long c=0,t=0,del=0;
vector <char> cur;
for(int i=fr-1;i<sc;i++)
{
cur.push_back(s[i]);
if(s[i]=='C')
c++;
else
t++;
if(t>c)
{
t--;
del++;
cur.pop_back();
}
}
reverse(cur.begin(),cur.end());
c=0;
t=0;
for(int i=0;i<cur.size();i++)
{
//cout<<cur[i];
if(cur[i]=='C')
c++;
else
t++;
if(t>c)
{
t--;
del++;
}
}
cout<<del<<"\n";
}
}
Compilation message
election.cpp: In function 'int main()':
election.cpp:44:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(int i=0;i<cur.size();i++)
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
340 KB |
Output is correct |
2 |
Correct |
12 ms |
344 KB |
Output is correct |
3 |
Correct |
11 ms |
352 KB |
Output is correct |
4 |
Correct |
11 ms |
336 KB |
Output is correct |
5 |
Correct |
7 ms |
352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
340 KB |
Output is correct |
2 |
Correct |
12 ms |
344 KB |
Output is correct |
3 |
Correct |
11 ms |
352 KB |
Output is correct |
4 |
Correct |
11 ms |
336 KB |
Output is correct |
5 |
Correct |
7 ms |
352 KB |
Output is correct |
6 |
Execution timed out |
3039 ms |
800 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
340 KB |
Output is correct |
2 |
Correct |
12 ms |
344 KB |
Output is correct |
3 |
Correct |
11 ms |
352 KB |
Output is correct |
4 |
Correct |
11 ms |
336 KB |
Output is correct |
5 |
Correct |
7 ms |
352 KB |
Output is correct |
6 |
Execution timed out |
3039 ms |
800 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |