Submission #680513

#TimeUsernameProblemLanguageResultExecution timeMemory
680513vjudge1Election (BOI18_election)C++14
28 / 100
3069 ms2124 KiB
#include <bits/stdc++.h> #define ll long long #define st first #define nd second #define pii pair <ll, ll> #define rep(i, n, m) for (ll i = (n); i <= (m); i ++) #define rrep(i, n, m) for (ll i = (n); i >= (m); i --) using namespace std; const long long N = 1e6 + 5; ll n, a[N], q; bool del[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; rep(i, 1, n) { char ch; cin >> ch; if (ch == 'T') a[i] = -1; else a[i] = 1; } cin >> q; while (q --) { int l, r; cin >> l >> r; int b = 0, ans = 0; rep(i, l, r) { b += a[i]; if (b < 0) b ++, ans ++, del[i] = true; } b = 0; rrep(i, r, l) { if (!del[i]) { b += a[i]; if (b < 0) b ++, ans ++; } del[i] = false; } cout << ans << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...