제출 #1133268

#제출 시각아이디문제언어결과실행 시간메모리
1133268sardor_salimovElection (BOI18_election)C++20
28 / 100
3084 ms1304 KiB
#include <bits/stdc++.h>
#define ar array
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, q;
    string s;
    cin >> n >> s >> q;
    s = "1" + s;
    vector <int> a(n + 1);
    for (int i = 1; i <= n; i++)
        a[i] = s[i] == 'C' ? 1 : -1;
    while (q--) {
        int l, r, sm = 0, ans = 0;
        cin >> l >> r;
        vector <int> pos(n + 1, 1);
        for (int i = l; i <= r; i++) {
            sm += a[i];
            if (sm < 0)
                sm++, pos[i] = 0, ans++;
        }
        sm = 0;
        for (int i = r; i >= l; i--) {
            sm += a[i] * pos[i];
            if (sm < 0)
                sm++, ans++;
        }
        cout << ans << '\n';
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...