// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define RREP(i, s, e) for (int i = (s); i >= (e); i--)
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define SZ(_a) (int) _a.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;
#ifndef DEBUG
#define cerr if (0) cerr
#endif
const int INF = 1000000005;
const ll LINF = 1000000000000000005ll;
const int MAXN = 120005;
int n, m, q;
bool c[MAXN];
int a[MAXN];
#define MLR int mid = lo + hi >> 1, lc = u << 1, rc = u << 1 ^ 1
int sm[MAXN * 4], lz[MAXN * 4];
void init(int u = 1, int lo = 1, int hi = n) {
lz[u] = -1;
if (lo == hi) {
sm[u] = c[lo];
cerr << u << ' ' << lo << ' ' << hi << ": " << sm[u] << '\n';
return;
}
MLR;
init(lc, lo, mid);
init(rc, mid + 1, hi);
sm[u] = sm[lc] + sm[rc];
cerr << u << ' ' << lo << ' ' << hi << ": " << sm[u] << '\n';
}
void propo(int u, int lo, int hi) {
if (lz[u] == -1) {
return;
}
MLR;
sm[lc] = lz[u] * (mid - lo + 1);
sm[rc] = lz[u] * (hi - mid);
lz[lc] = lz[u];
lz[rc] = lz[u];
lz[u] = -1;
}
int qsm(int s, int e, int u = 1, int lo = 1, int hi = n) {
if (s > e) {
return 0;
}
if (lo >= s && hi <= e) {
return sm[u];
}
MLR;
propo(u, lo, hi);
int res = 0;
if (s <= mid) {
res += qsm(s, e, lc, lo, mid);
}
if (e > mid) {
res += qsm(s, e, rc, mid + 1, hi);
}
return res;
}
void upd(int s, int e, int x, int u = 1, int lo = 1, int hi = n) {
if (s > e) {
return;
}
if (lo >= s && hi <= e) {
sm[u] = x * (hi - lo + 1);
lz[u] = x;
return;
}
MLR;
propo(u, lo, hi);
if (s <= mid) {
upd(s, e, x, lc, lo, mid);
}
if (e > mid) {
upd(s, e, x, rc, mid + 1, hi);
}
sm[u] = sm[lc] + sm[rc];
}
int lb(int x, bool inv, int u = 1, int lo = 1, int hi = n) {
int usm = sm[u];
if (inv) {
usm = hi - lo + 1 - sm[u];
}
if (usm < x) {
return INF;
}
if (lo == hi) {
assert(usm == x);
return lo;
}
MLR;
propo(u, lo, hi);
int lsm = sm[lc];
if (inv) {
lsm = mid - lo + 1 - sm[lc];
}
if (lsm >= x) {
return lb(x, inv, lc, lo, mid);
} else {
return lb(x - lsm, inv, rc, mid + 1, hi);
}
}
int main() {
#ifndef DEBUG
ios::sync_with_stdio(0), cin.tie(0);
#endif
cin >> n >> m;
REP (i, 1, n + 1) {
char t; cin >> t;
c[i] = t == 'R';
}
REP (i, 1, m + 1) {
cin >> a[i];
}
cin >> q;
while (q--) {
int l, r; cin >> l >> r;
init();
REP (i, l, r + 1) {
int p = a[i];
int lftr = qsm(1, p - 1), rhtb = n - p - qsm(p + 1, n);
cerr << p << ' ' << lftr << ' ' << rhtb << '\n';
if (lftr < rhtb) {
int lftb = p - qsm(1, p);
int np = lb(lftb + lftr + 1, 1);
upd(1, np, 1);
} else {
int rhtr = qsm(p, n);
int tot = qsm(1, n);
int np = lb(tot - rhtr - rhtb + 1, 0);
cerr << ' ' << np << '\n';
upd(np, n, 0);
}
}
cout << qsm(1, n) << '\n';
}
return 0;
}
Compilation message
Main.cpp: In function 'void init(int, int, int)':
Main.cpp:42:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
42 | #define MLR int mid = lo + hi >> 1, lc = u << 1, rc = u << 1 ^ 1
| ~~~^~~~
Main.cpp:51:5: note: in expansion of macro 'MLR'
51 | MLR;
| ^~~
Main.cpp: In function 'void propo(int, int, int)':
Main.cpp:42:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
42 | #define MLR int mid = lo + hi >> 1, lc = u << 1, rc = u << 1 ^ 1
| ~~~^~~~
Main.cpp:61:5: note: in expansion of macro 'MLR'
61 | MLR;
| ^~~
Main.cpp: In function 'int qsm(int, int, int, int, int)':
Main.cpp:42:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
42 | #define MLR int mid = lo + hi >> 1, lc = u << 1, rc = u << 1 ^ 1
| ~~~^~~~
Main.cpp:75:5: note: in expansion of macro 'MLR'
75 | MLR;
| ^~~
Main.cpp: In function 'void upd(int, int, int, int, int, int)':
Main.cpp:42:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
42 | #define MLR int mid = lo + hi >> 1, lc = u << 1, rc = u << 1 ^ 1
| ~~~^~~~
Main.cpp:95:5: note: in expansion of macro 'MLR'
95 | MLR;
| ^~~
Main.cpp: In function 'int lb(int, bool, int, int, int)':
Main.cpp:42:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
42 | #define MLR int mid = lo + hi >> 1, lc = u << 1, rc = u << 1 ^ 1
| ~~~^~~~
Main.cpp:117:5: note: in expansion of macro 'MLR'
117 | MLR;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
3 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
4 ms |
468 KB |
Output is correct |
13 |
Correct |
3 ms |
468 KB |
Output is correct |
14 |
Correct |
5 ms |
472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
3 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
4 ms |
468 KB |
Output is correct |
13 |
Correct |
3 ms |
468 KB |
Output is correct |
14 |
Correct |
5 ms |
472 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
274 ms |
3572 KB |
Output is correct |
19 |
Correct |
362 ms |
3440 KB |
Output is correct |
20 |
Correct |
469 ms |
3676 KB |
Output is correct |
21 |
Correct |
510 ms |
3724 KB |
Output is correct |
22 |
Correct |
353 ms |
3444 KB |
Output is correct |
23 |
Correct |
330 ms |
3644 KB |
Output is correct |
24 |
Correct |
314 ms |
3296 KB |
Output is correct |
25 |
Correct |
325 ms |
3284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Execution timed out |
3064 ms |
1108 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Execution timed out |
3064 ms |
1108 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Execution timed out |
3064 ms |
1108 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
3 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
4 ms |
468 KB |
Output is correct |
13 |
Correct |
3 ms |
468 KB |
Output is correct |
14 |
Correct |
5 ms |
472 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
274 ms |
3572 KB |
Output is correct |
19 |
Correct |
362 ms |
3440 KB |
Output is correct |
20 |
Correct |
469 ms |
3676 KB |
Output is correct |
21 |
Correct |
510 ms |
3724 KB |
Output is correct |
22 |
Correct |
353 ms |
3444 KB |
Output is correct |
23 |
Correct |
330 ms |
3644 KB |
Output is correct |
24 |
Correct |
314 ms |
3296 KB |
Output is correct |
25 |
Correct |
325 ms |
3284 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Execution timed out |
3064 ms |
1108 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |