#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007
#define dancila 3.14159265359
#define eps 1e-9
using namespace std;
typedef long long ll;
int n, q;
string s;
int aint[2000002], lazy[2000002], ans[500002];
vector<pair<int, int> >qu[500002];
void lz(int nod, int st, int dr)
{
aint[nod] += lazy[nod];
if(st != dr)
{
lazy[nod << 1] += lazy[nod];
lazy[nod << 1|1] += lazy[nod];
}
lazy[nod] = 0;
}
void upd(int nod, int st, int dr, int L, int R, int val)
{
lz(nod, st, dr);
if(dr < L || st > R)
return;
if(L <= st && dr <= R)
{
lazy[nod] += val;
lz(nod, st, dr);
return;
}
int mid = (st + dr) / 2;
upd(nod << 1, st, mid, L, R, val);
upd(nod << 1|1, mid+1, dr, L, R, val);
aint[nod] = min(aint[nod << 1], aint[nod << 1|1]);
}
int query(int nod, int st, int dr, int L, int R)
{
cout << L << " " << R << " " << nod << " " << st << " " << dr << " " << aint[nod] << '\n';
lz(nod, st, dr);
if(dr < L || st > R)
return 100000001;
if(L <= st && dr <= R)
return aint[nod];
int mid = (st + dr) / 2;
return min(query(nod << 1, st, mid, L, R), query(nod << 1|1, mid+1, dr, L, R));
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
cin >> s;
s = ' ' + s;
cin >> q;
for(int i = 1; i <= q; ++i)
{
int a, b;
cin >> a >> b;
qu[b].pb({a, i});
}
vector<int> d;
for(int i = 1; i <= n; ++i)
{
if(s[i] == 'T')
d.pb(i);
else
{
if(!d.empty())
{
upd(1, 1, n, (int) d.back(), n, -1);
d.pop_back();
}
upd(1, 1, n, i, n, 1);
}
for(int j = 0; j < qu[i].size(); ++j)
{
int cs = qu[i][j].fi;
int pz = qu[i][j].se;
int sol = query(1, 1, n, cs, i);
if(cs > 1)
sol -= query(1, 1, n, cs-1, cs-1);
auto it = lower_bound(d.begin(), d.end(), cs);
int cnt = (int) d.size() - (it - d.begin());
ans[pz] = cnt - min(0, sol);
}
}
for(int i = 1; i <= q; ++i)
cout << ans[i] << '\n';
return 0;
}
Compilation message
election.cpp: In function 'int main()':
election.cpp:89:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 0; j < qu[i].size(); ++j)
~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
70 ms |
14968 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
70 ms |
14968 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
70 ms |
14968 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |