Submission #378442

# Submission time Handle Problem Language Result Execution time Memory
378442 2021-03-16T19:37:42 Z thecodingwizard Election (BOI18_election) C++11
0 / 100
6 ms 492 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
#define ii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define F0R(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define inf 1000000010

int cLeft[500001], cRight[500001], tLeft[500001], tRight[500001];

int main() {
    cin.tie(0)->sync_with_stdio(0);

    int n; cin >> n;
    string s; cin >> s;

    F0R(i, n) {
        cLeft[i+1] = cLeft[i] + (s[i] == 'C');
        tLeft[i+1] = tLeft[i] + (s[i] == 'T');
    }
    for (int i = n-1; ~i; i--) {
        cRight[i] = cRight[i+1] + (s[i] == 'C');
        tRight[i] = tRight[i+1] + (s[i] == 'T');
    }

    int q; cin >> q;
    F0R(i, q) {
        int L, R; cin >> L >> R;
        int l = L, r = R;
        int best = 0;
        while (l <= r) {
            int mid = (l+r)/2;
            int cl = cLeft[mid] - cLeft[L-1], cr = cRight[mid+1] - cRight[R+1];
            int tl = tLeft[mid] - tLeft[L-1], tr = tRight[mid+1] - tRight[R+1];
            int lft = min(cl, tl);
            int rht = min(cr, tr);
            best = max(best, min(lft, rht));
            if (lft > rht) {
                r = mid - 1;
            } else {
                l = mid + 1;
            }
        }
        
        best = tLeft[R] - tLeft[L-1] - best;
        cout << best << endl;
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 492 KB Output isn't correct
2 Halted 0 ms 0 KB -