#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//1 => l-1~r
ll n,q;
string s;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cin>>n;
cin>>s;
cin>>q;
while(q--)
{
ll l,r;
cin>>l>>r;
vector<char> lf;
ll cnt = 0,ans = 0;
for(ll i=l-1;i<r;i++)
{
if(s[i]=='T'&&cnt==0)
ans++;
else
{
if(s[i]=='T')
cnt--;
else
cnt++;
lf.push_back(s[i]);
}
}
reverse(lf.begin(),lf.end());
cnt = 0;
for(char c:lf)
{
if(c=='T'&&cnt==0)
ans++;
else
{
if(c=='T')
cnt--;
else
cnt++;
}
}
cout<<ans<<"\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
212 KB |
Output is correct |
2 |
Correct |
11 ms |
328 KB |
Output is correct |
3 |
Correct |
10 ms |
352 KB |
Output is correct |
4 |
Correct |
8 ms |
340 KB |
Output is correct |
5 |
Correct |
6 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
212 KB |
Output is correct |
2 |
Correct |
11 ms |
328 KB |
Output is correct |
3 |
Correct |
10 ms |
352 KB |
Output is correct |
4 |
Correct |
8 ms |
340 KB |
Output is correct |
5 |
Correct |
6 ms |
340 KB |
Output is correct |
6 |
Execution timed out |
3074 ms |
1108 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
212 KB |
Output is correct |
2 |
Correct |
11 ms |
328 KB |
Output is correct |
3 |
Correct |
10 ms |
352 KB |
Output is correct |
4 |
Correct |
8 ms |
340 KB |
Output is correct |
5 |
Correct |
6 ms |
340 KB |
Output is correct |
6 |
Execution timed out |
3074 ms |
1108 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |