// you're already the best
// yay
// _
// ^ ^ //
// >(O_O)<___//
// \ __ __ \
// \\ \\ \\\\
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("O3","unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using ll = long long;
#define int long long
//#define double long double
#define forn(i,n) for(int i=0; i<(n); ++i)
#define pb push_back
#define pi pair<int,int>
#define f first
#define s second
#define vii(a,n) vector<int> a(n); forn(i,n) cin>>a[i];
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int inf = 1e18;
const int mod = 998244353;
void solve() {
int n; cin>>n;
string s; cin>>s;
int m; cin>>m;
while (m--) {
int l,r; cin>>l>>r;
vector<int> z(n,0);
int x=0;
int ans=0;
for (int i=l-1; i<r; ++i) {
x+=1-2*(s[i]=='T');
if (x<0) {
z[i]=1;
x-=1-2*(s[i]=='T');
++ans;
}
}
x=0;
for (int i=r-1; i>=l-1; --i) {
if (z[i]) continue;
x+=1-2*(s[i]=='T');
if (x<0) {
z[i]=1;
x-=1-2*(s[i]=='T');
++ans;
}
}
cout<<ans<<'\n';
}
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t=1;
//cin>>t;
while (t--) solve();
return 0;
}
Compilation message
election.cpp:6:1: warning: multi-line comment [-Wcomment]
6 | // \ __ __ \
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
340 KB |
Output is correct |
2 |
Correct |
5 ms |
340 KB |
Output is correct |
3 |
Correct |
7 ms |
340 KB |
Output is correct |
4 |
Correct |
8 ms |
368 KB |
Output is correct |
5 |
Correct |
4 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
340 KB |
Output is correct |
2 |
Correct |
5 ms |
340 KB |
Output is correct |
3 |
Correct |
7 ms |
340 KB |
Output is correct |
4 |
Correct |
8 ms |
368 KB |
Output is correct |
5 |
Correct |
4 ms |
340 KB |
Output is correct |
6 |
Execution timed out |
3058 ms |
2240 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
340 KB |
Output is correct |
2 |
Correct |
5 ms |
340 KB |
Output is correct |
3 |
Correct |
7 ms |
340 KB |
Output is correct |
4 |
Correct |
8 ms |
368 KB |
Output is correct |
5 |
Correct |
4 ms |
340 KB |
Output is correct |
6 |
Execution timed out |
3058 ms |
2240 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |