# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
63526 | Talant | Election (BOI18_election) | C++17 | 3046 ms | 1176 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define mk make_pair
#define sc second
#define fr first
#define pb emplace_back
#define all(s) s.begin(), s.end()
#define sz(s) ( (int)s.size() )
#define Scan(a) scanf ("%I64d", &a)
#define scan(a) scanf ("%d", &a)
using namespace std;
const int inf = (int)1e9 + 7;
const int N = (int)5e5 + 7;
int n;
int q;
int l,r;
int u[N];
string a;
vector <int> v;
main () {
cin >> n;
cin >> a;
cin >> q;
while (q --) {
int sum = 0,sum1 = 0,f = 0;
cin >> l >> r;
l --,r --;
for (int i = l; i <= r; i ++) {
if (a[i] == 'T' && f == 0) u[i] = 1;
else if (a[i] == 'T' && f > 0) f --;
else f ++;
}
f = 0;
for (int i = r; i >= l; i --) {
if (u[i] == 1) continue;
if (a[i] == 'T' && f == 0) u[i] = 1;
else if (a[i] == 'T' && f > 0) f --;
else f ++;
}
for (int i = l; i <= r; i ++)
sum += u[i],u[i] = 0;
v.pb(sum);
}
for (auto to : v)
cout << to << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |