답안 #378442

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
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;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 492 KB Output isn't correct
2 Halted 0 ms 0 KB -