# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1126886 | VinhLuu | Election (BOI18_election) | C++20 | 5 ms | 320 KiB |
#include <bits/stdc++.h>
#define ll long long
#define all(lpv) lpv.begin(), lpv.end()
#define pot(x, y) lower_bound(x.begin(), x.end(), y) - x.begin() + 1
using namespace std;
#define lpv
#ifndef lpv
#include "AC.h"
#endif // lpv
const int N = 1e6 + 5;
const int oo = 1e9;
int n, q, a[N], s[N], p[N], b[N], bs[N], bp[N];
#ifdef lpv
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define task "v"
if(fopen(task ".inp","r")) {
freopen(task ".inp","r",stdin);
freopen(task ".out","w",stdout);
}
cin >> n;
string str; cin >> str;
str = " " + str;
for(int i = 1; i <= n; i ++) {
if(str[i] == 'C') a[i] = 1;
else a[i] = -1;
s[i] = s[i - 1] + a[i];
}
for(int i = n; i >= 1; i --) p[i] = p[i + 1] + a[i];
cin >> q;
while(q--) {
int l, r; cin >> l >> r;
int cnt = 0;
bs[l - 1] = 0;
for(int i = l; i <= r; i ++) {
b[i] = a[i];
bs[i] = bs[i - 1] + b[i];
if(bs[i] < 0) {
bs[i] = bs[i - 1];
b[i] = 0;
cnt++;
}
}
bp[r + 1] = 0;
for(int i = r; i >= l; i --) {
bp[i] = bp[i + 1] + b[i];
if(bp[i] < 0) {
bp[i] = bp[i - 1];
b[i] = 0;
cnt++;
}
}
cout << cnt << "\n";
}
}
#endif // lpv
컴파일 시 표준 에러 (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... |