## 답안 #686435

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
686435 2023-01-25T09:27:41 Z cig32 The short shank; Redemption (BOI21_prison) C++14
80 / 100
2000 ms 138456 KB
```#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e6 + 10;
const int MOD = 1e9 + 7;
int rnd(int x, int y) {
int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
int bm(int b, int p) {
if(p==0) return 1 % MOD;
int r = bm(b, p >> 1);
if(p&1) return (((r*r) % MOD) * b) % MOD;
return (r*r) % MOD;
}
int inv(int b) {
return bm(b, MOD-2);
}
int fastlog(int x) {
return (x == 0 ? -1 : 64 - __builtin_clzll(x) - 1);
}
void printcase(int i) { cout << "Case #" << i << ": "; }

struct node {
int ma = 0, upd = 0, idx;
} st[4 * MAXN];
void build(int l, int r, int idx) {
if(l == r) {
st[idx].idx = l; return;
}
int mid = (l + r) >> 1;
build(l, mid, (idx<<1)+1);
build(mid+1, r, (idx<<1)+2);
st[idx].ma = max(st[(idx<<1)+1].ma, st[(idx<<1)+2].ma);
st[idx].idx = (st[(idx<<1)+1].ma == st[idx].ma ? st[(idx<<1)+1].idx : st[(idx<<1)+2].idx);
}
void u(int l, int r, int constl, int constr, int idx, int val) {
if(l <= constl && constr <= r) {
st[idx].ma += val;
st[idx].upd += val;
return;
}
int mid = (constl + constr) >> 1;
st[(idx<<1)+1].ma += st[idx].upd;
st[(idx<<1)+1].upd += st[idx].upd;
st[(idx<<1)+2].ma += st[idx].upd;
st[(idx<<1)+2].upd += st[idx].upd;
st[idx].upd = 0;
if(mid < l || r < constl) u(l, r, mid+1, constr, (idx<<1)+2, val);
else if(constr < l || r < mid+1) u(l, r, constl, mid, (idx<<1)+1, val);
else {
u(l, r, constl, mid, (idx<<1)+1,val); u(l, r, mid+1, constr, (idx<<1)+2, val);
}
st[idx].ma = max(st[(idx<<1)+1].ma, st[(idx<<1)+2].ma);
st[idx].idx = (st[(idx<<1)+1].ma == st[idx].ma ? st[(idx<<1)+1].idx : st[(idx<<1)+2].idx);
}
int seg[4 * MAXN];

void u2(int l, int r, int tar, int idx, int val) {
if(l == r) {
seg[idx] = val; return;
}
int mid = (l + r) >> 1;
if(tar <= mid) u2(l, mid, tar, (idx<<1)+1, val);
else u2(mid+1, r, tar, (idx<<1)+2, val);
seg[idx] = min(seg[(idx<<1)+1], seg[(idx<<1)+2]);
}

int qu2(int l, int r, int constl, int constr, int idx, int val) { // first <= v
if(l <= constl && constr <= r) {
if(seg[idx] > val) return -1;
while(constl < constr) {
int mid = (constl + constr) >> 1;
if(seg[(idx<<1)+1] <= val) constr = mid, idx = (idx<<1)+1;
else constl = mid+1, idx = (idx<<1)+2;
}
return constl;
}
int mid = (constl + constr) >> 1;
if(mid < l || r < constl) return qu2(l, r, mid+1, constr, (idx<<1)+2, val);
else if(constr < l || r < mid+1) return qu2(l, r, constl, mid, (idx<<1)+1, val);
else {
int lc = qu2(l, r, constl, mid, (idx<<1)+1, val);
if(lc != -1) return lc;
return qu2(l, r, mid+1, constr, (idx<<1)+2, val);
}
}
int x = 0, c = getchar(), neg = false;
while(('0' > c || c > '9') && c!='-' && c!=EOF) c = getchar();
if(c == '-') neg = true, c = getchar();
while('0' <= c && c <= '9') x = x*10 + (c^'0'), c = getchar();
if(neg) x = -x;
return x; // returns 0 if EOF
}
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0);
int32_t n, d, t;
pair<int, int> tri[n+1];
for(int i=1; i<=n; i++) {
tri[i] = {x-i, i};
}
sort(tri+1, tri+1+n);
build(1, n-1, 0);
int ans = 0;
int pr = 0;
priority_queue<int> ok;
int sv[n+1];
for(int i=n; i>=1; i--) {
while(pr+1 <= n && tri[pr+1].first <= t-i) {
pr++;
if(tri[pr].second <= i) ok.push(tri[pr].second);
}
int bruh = (ok.size() ? ok.top() : -1);
if(bruh == i) ok.pop();
sv[i]= bruh;
if(bruh != -1) {
ans++;
if(bruh < i) {
u(bruh, i-1, 1, n-1, 0, 1);
}
u2(1, n, i, 0, bruh);
}
else {
u2(1, n, i, 0, MOD);
}
}
while(d--) {
int ss = st[0].idx;
while(1) {
int idx = qu2(ss+1, n, 1, n, 0, ss);
if(idx == -1) break;
u2(1, n, idx, 0, MOD);
u(sv[idx], idx-1, 1, n-1, 0, -1);
ans--;
}
}
cout << ans << "\n";
}```

#### Subtask #1 15.0 / 15.0

# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 94160 KB Output is correct
2 Correct 35 ms 94168 KB Output is correct
3 Correct 39 ms 94256 KB Output is correct
4 Correct 40 ms 94228 KB Output is correct
5 Correct 45 ms 94140 KB Output is correct
6 Correct 36 ms 94248 KB Output is correct
7 Correct 35 ms 94248 KB Output is correct
8 Correct 39 ms 94180 KB Output is correct
9 Correct 43 ms 94256 KB Output is correct
10 Correct 37 ms 94204 KB Output is correct
11 Correct 37 ms 94156 KB Output is correct

#### Subtask #2 10.0 / 10.0

# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 94204 KB Output is correct
2 Correct 240 ms 105188 KB Output is correct
3 Correct 233 ms 105716 KB Output is correct
4 Correct 229 ms 104932 KB Output is correct
5 Correct 233 ms 104128 KB Output is correct
6 Correct 233 ms 104188 KB Output is correct
7 Correct 619 ms 104220 KB Output is correct
8 Correct 245 ms 104172 KB Output is correct

#### Subtask #3 20.0 / 20.0

# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 94160 KB Output is correct
2 Correct 35 ms 94168 KB Output is correct
3 Correct 39 ms 94256 KB Output is correct
4 Correct 40 ms 94228 KB Output is correct
5 Correct 45 ms 94140 KB Output is correct
6 Correct 36 ms 94248 KB Output is correct
7 Correct 35 ms 94248 KB Output is correct
8 Correct 39 ms 94180 KB Output is correct
9 Correct 43 ms 94256 KB Output is correct
10 Correct 37 ms 94204 KB Output is correct
11 Correct 37 ms 94156 KB Output is correct
12 Correct 36 ms 94224 KB Output is correct
13 Correct 37 ms 94244 KB Output is correct
14 Correct 37 ms 94224 KB Output is correct
15 Correct 41 ms 94284 KB Output is correct
16 Correct 42 ms 94160 KB Output is correct
17 Correct 39 ms 94236 KB Output is correct
18 Correct 42 ms 94164 KB Output is correct
19 Correct 40 ms 94164 KB Output is correct
20 Correct 43 ms 94164 KB Output is correct
21 Correct 39 ms 94156 KB Output is correct
22 Correct 37 ms 94136 KB Output is correct
23 Correct 43 ms 94216 KB Output is correct
24 Correct 38 ms 94320 KB Output is correct
25 Correct 39 ms 94252 KB Output is correct
26 Correct 38 ms 94324 KB Output is correct
27 Correct 45 ms 94236 KB Output is correct
28 Correct 38 ms 94304 KB Output is correct
29 Correct 38 ms 94240 KB Output is correct
30 Correct 39 ms 94272 KB Output is correct
31 Correct 39 ms 94220 KB Output is correct
32 Correct 40 ms 94308 KB Output is correct
33 Correct 38 ms 94332 KB Output is correct
34 Correct 63 ms 94240 KB Output is correct
35 Correct 40 ms 94276 KB Output is correct

#### Subtask #4 10.0 / 10.0

# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 94216 KB Output is correct
2 Correct 67 ms 96332 KB Output is correct
3 Correct 71 ms 96336 KB Output is correct
4 Correct 89 ms 96316 KB Output is correct
5 Correct 95 ms 96360 KB Output is correct
6 Correct 97 ms 96280 KB Output is correct
7 Correct 65 ms 96104 KB Output is correct
8 Correct 73 ms 96080 KB Output is correct
9 Correct 117 ms 96104 KB Output is correct
10 Correct 58 ms 96076 KB Output is correct

#### Subtask #5 25.0 / 25.0

# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 94160 KB Output is correct
2 Correct 35 ms 94168 KB Output is correct
3 Correct 39 ms 94256 KB Output is correct
4 Correct 40 ms 94228 KB Output is correct
5 Correct 45 ms 94140 KB Output is correct
6 Correct 36 ms 94248 KB Output is correct
7 Correct 35 ms 94248 KB Output is correct
8 Correct 39 ms 94180 KB Output is correct
9 Correct 43 ms 94256 KB Output is correct
10 Correct 37 ms 94204 KB Output is correct
11 Correct 37 ms 94156 KB Output is correct
12 Correct 36 ms 94224 KB Output is correct
13 Correct 37 ms 94244 KB Output is correct
14 Correct 37 ms 94224 KB Output is correct
15 Correct 41 ms 94284 KB Output is correct
16 Correct 42 ms 94160 KB Output is correct
17 Correct 39 ms 94236 KB Output is correct
18 Correct 42 ms 94164 KB Output is correct
19 Correct 40 ms 94164 KB Output is correct
20 Correct 43 ms 94164 KB Output is correct
21 Correct 39 ms 94156 KB Output is correct
22 Correct 37 ms 94136 KB Output is correct
23 Correct 43 ms 94216 KB Output is correct
24 Correct 38 ms 94320 KB Output is correct
25 Correct 39 ms 94252 KB Output is correct
26 Correct 38 ms 94324 KB Output is correct
27 Correct 45 ms 94236 KB Output is correct
28 Correct 38 ms 94304 KB Output is correct
29 Correct 38 ms 94240 KB Output is correct
30 Correct 39 ms 94272 KB Output is correct
31 Correct 39 ms 94220 KB Output is correct
32 Correct 40 ms 94308 KB Output is correct
33 Correct 38 ms 94332 KB Output is correct
34 Correct 63 ms 94240 KB Output is correct
35 Correct 40 ms 94276 KB Output is correct
36 Correct 38 ms 94216 KB Output is correct
37 Correct 67 ms 96332 KB Output is correct
38 Correct 71 ms 96336 KB Output is correct
39 Correct 89 ms 96316 KB Output is correct
40 Correct 95 ms 96360 KB Output is correct
41 Correct 97 ms 96280 KB Output is correct
42 Correct 65 ms 96104 KB Output is correct
43 Correct 73 ms 96080 KB Output is correct
44 Correct 117 ms 96104 KB Output is correct
45 Correct 58 ms 96076 KB Output is correct
46 Correct 44 ms 94124 KB Output is correct
47 Correct 41 ms 94180 KB Output is correct
48 Correct 43 ms 94236 KB Output is correct
49 Correct 42 ms 94236 KB Output is correct
50 Correct 37 ms 94208 KB Output is correct
51 Correct 38 ms 94168 KB Output is correct
52 Correct 43 ms 94248 KB Output is correct
53 Correct 40 ms 94216 KB Output is correct
54 Correct 38 ms 94164 KB Output is correct
55 Correct 40 ms 94232 KB Output is correct
56 Correct 39 ms 94172 KB Output is correct
57 Correct 39 ms 94276 KB Output is correct
58 Correct 38 ms 94284 KB Output is correct
59 Correct 38 ms 94300 KB Output is correct
60 Correct 45 ms 94224 KB Output is correct
61 Correct 38 ms 94304 KB Output is correct
62 Correct 43 ms 94264 KB Output is correct
63 Correct 41 ms 94292 KB Output is correct
64 Correct 43 ms 94220 KB Output is correct
65 Correct 42 ms 94208 KB Output is correct
66 Correct 39 ms 94256 KB Output is correct
67 Correct 40 ms 94292 KB Output is correct
68 Correct 40 ms 94292 KB Output is correct
69 Correct 39 ms 94288 KB Output is correct
70 Correct 36 ms 94160 KB Output is correct
71 Correct 69 ms 96380 KB Output is correct
72 Correct 63 ms 96340 KB Output is correct
73 Correct 94 ms 96224 KB Output is correct
74 Correct 110 ms 96368 KB Output is correct
75 Correct 117 ms 96364 KB Output is correct
76 Correct 69 ms 96136 KB Output is correct
77 Correct 64 ms 96124 KB Output is correct
78 Correct 124 ms 96060 KB Output is correct
79 Correct 58 ms 96152 KB Output is correct
80 Correct 73 ms 96368 KB Output is correct
81 Correct 88 ms 96372 KB Output is correct
82 Correct 77 ms 96392 KB Output is correct
83 Correct 93 ms 96104 KB Output is correct
84 Correct 82 ms 96108 KB Output is correct
85 Correct 102 ms 96272 KB Output is correct
86 Correct 83 ms 96188 KB Output is correct
87 Correct 78 ms 96144 KB Output is correct
88 Correct 122 ms 96108 KB Output is correct
89 Correct 103 ms 96112 KB Output is correct
90 Correct 97 ms 96148 KB Output is correct

#### Subtask #6 0 / 20.0

# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 94160 KB Output is correct
2 Correct 35 ms 94168 KB Output is correct
3 Correct 39 ms 94256 KB Output is correct
4 Correct 40 ms 94228 KB Output is correct
5 Correct 45 ms 94140 KB Output is correct
6 Correct 36 ms 94248 KB Output is correct
7 Correct 35 ms 94248 KB Output is correct
8 Correct 39 ms 94180 KB Output is correct
9 Correct 43 ms 94256 KB Output is correct
10 Correct 37 ms 94204 KB Output is correct
11 Correct 37 ms 94156 KB Output is correct
12 Correct 38 ms 94204 KB Output is correct
13 Correct 240 ms 105188 KB Output is correct
14 Correct 233 ms 105716 KB Output is correct
15 Correct 229 ms 104932 KB Output is correct
16 Correct 233 ms 104128 KB Output is correct
17 Correct 233 ms 104188 KB Output is correct
18 Correct 619 ms 104220 KB Output is correct
19 Correct 245 ms 104172 KB Output is correct
20 Correct 36 ms 94224 KB Output is correct
21 Correct 37 ms 94244 KB Output is correct
22 Correct 37 ms 94224 KB Output is correct
23 Correct 41 ms 94284 KB Output is correct
24 Correct 42 ms 94160 KB Output is correct
25 Correct 39 ms 94236 KB Output is correct
26 Correct 42 ms 94164 KB Output is correct
27 Correct 40 ms 94164 KB Output is correct
28 Correct 43 ms 94164 KB Output is correct
29 Correct 39 ms 94156 KB Output is correct
30 Correct 37 ms 94136 KB Output is correct
31 Correct 43 ms 94216 KB Output is correct
32 Correct 38 ms 94320 KB Output is correct
33 Correct 39 ms 94252 KB Output is correct
34 Correct 38 ms 94324 KB Output is correct
35 Correct 45 ms 94236 KB Output is correct
36 Correct 38 ms 94304 KB Output is correct
37 Correct 38 ms 94240 KB Output is correct
38 Correct 39 ms 94272 KB Output is correct
39 Correct 39 ms 94220 KB Output is correct
40 Correct 40 ms 94308 KB Output is correct
41 Correct 38 ms 94332 KB Output is correct
42 Correct 63 ms 94240 KB Output is correct
43 Correct 40 ms 94276 KB Output is correct
44 Correct 38 ms 94216 KB Output is correct
45 Correct 67 ms 96332 KB Output is correct
46 Correct 71 ms 96336 KB Output is correct
47 Correct 89 ms 96316 KB Output is correct
48 Correct 95 ms 96360 KB Output is correct
49 Correct 97 ms 96280 KB Output is correct
50 Correct 65 ms 96104 KB Output is correct
51 Correct 73 ms 96080 KB Output is correct
52 Correct 117 ms 96104 KB Output is correct
53 Correct 58 ms 96076 KB Output is correct
54 Correct 44 ms 94124 KB Output is correct
55 Correct 41 ms 94180 KB Output is correct
56 Correct 43 ms 94236 KB Output is correct
57 Correct 42 ms 94236 KB Output is correct
58 Correct 37 ms 94208 KB Output is correct
59 Correct 38 ms 94168 KB Output is correct
60 Correct 43 ms 94248 KB Output is correct
61 Correct 40 ms 94216 KB Output is correct
62 Correct 38 ms 94164 KB Output is correct
63 Correct 40 ms 94232 KB Output is correct
64 Correct 39 ms 94172 KB Output is correct
65 Correct 39 ms 94276 KB Output is correct
66 Correct 38 ms 94284 KB Output is correct
67 Correct 38 ms 94300 KB Output is correct
68 Correct 45 ms 94224 KB Output is correct
69 Correct 38 ms 94304 KB Output is correct
70 Correct 43 ms 94264 KB Output is correct
71 Correct 41 ms 94292 KB Output is correct
72 Correct 43 ms 94220 KB Output is correct
73 Correct 42 ms 94208 KB Output is correct
74 Correct 39 ms 94256 KB Output is correct
75 Correct 40 ms 94292 KB Output is correct
76 Correct 40 ms 94292 KB Output is correct
77 Correct 39 ms 94288 KB Output is correct
78 Correct 36 ms 94160 KB Output is correct
79 Correct 69 ms 96380 KB Output is correct
80 Correct 63 ms 96340 KB Output is correct
81 Correct 94 ms 96224 KB Output is correct
82 Correct 110 ms 96368 KB Output is correct
83 Correct 117 ms 96364 KB Output is correct
84 Correct 69 ms 96136 KB Output is correct
85 Correct 64 ms 96124 KB Output is correct
86 Correct 124 ms 96060 KB Output is correct
87 Correct 58 ms 96152 KB Output is correct
88 Correct 73 ms 96368 KB Output is correct
89 Correct 88 ms 96372 KB Output is correct
90 Correct 77 ms 96392 KB Output is correct
91 Correct 93 ms 96104 KB Output is correct
92 Correct 82 ms 96108 KB Output is correct
93 Correct 102 ms 96272 KB Output is correct
94 Correct 83 ms 96188 KB Output is correct
95 Correct 78 ms 96144 KB Output is correct
96 Correct 122 ms 96108 KB Output is correct
97 Correct 103 ms 96112 KB Output is correct
98 Correct 97 ms 96148 KB Output is correct
99 Correct 43 ms 94208 KB Output is correct
100 Correct 38 ms 94192 KB Output is correct
101 Correct 48 ms 94312 KB Output is correct
102 Correct 40 ms 94216 KB Output is correct
103 Correct 42 ms 94252 KB Output is correct
104 Correct 37 ms 94156 KB Output is correct
105 Correct 39 ms 94236 KB Output is correct
106 Correct 42 ms 94180 KB Output is correct
107 Correct 41 ms 94244 KB Output is correct
108 Correct 43 ms 94212 KB Output is correct
109 Correct 41 ms 94156 KB Output is correct
110 Correct 40 ms 94196 KB Output is correct
111 Correct 241 ms 105052 KB Output is correct
112 Correct 249 ms 105648 KB Output is correct
113 Correct 228 ms 104980 KB Output is correct
114 Correct 231 ms 104172 KB Output is correct
115 Correct 224 ms 104216 KB Output is correct
116 Correct 640 ms 104220 KB Output is correct
117 Correct 238 ms 104132 KB Output is correct
118 Correct 39 ms 94292 KB Output is correct
119 Correct 38 ms 94284 KB Output is correct
120 Correct 40 ms 94284 KB Output is correct
121 Correct 40 ms 94244 KB Output is correct
122 Correct 41 ms 94340 KB Output is correct
123 Correct 43 ms 94324 KB Output is correct
124 Correct 38 ms 94268 KB Output is correct
125 Correct 39 ms 94292 KB Output is correct
126 Correct 39 ms 94208 KB Output is correct
127 Correct 38 ms 94208 KB Output is correct
128 Correct 38 ms 94260 KB Output is correct
129 Correct 39 ms 94332 KB Output is correct
130 Correct 39 ms 94284 KB Output is correct
131 Correct 37 ms 94176 KB Output is correct
132 Correct 66 ms 96364 KB Output is correct
133 Correct 67 ms 96332 KB Output is correct
134 Correct 84 ms 96332 KB Output is correct
135 Correct 95 ms 96316 KB Output is correct
136 Correct 100 ms 96240 KB Output is correct
137 Correct 65 ms 96176 KB Output is correct
138 Correct 64 ms 96140 KB Output is correct
139 Correct 122 ms 96076 KB Output is correct
140 Correct 58 ms 96040 KB Output is correct
141 Correct 76 ms 96300 KB Output is correct
142 Correct 81 ms 96348 KB Output is correct
143 Correct 77 ms 96472 KB Output is correct
144 Correct 93 ms 96272 KB Output is correct
145 Correct 78 ms 96096 KB Output is correct
146 Correct 103 ms 96184 KB Output is correct
147 Correct 81 ms 96112 KB Output is correct
148 Correct 80 ms 96264 KB Output is correct
149 Correct 104 ms 96120 KB Output is correct
150 Correct 99 ms 96088 KB Output is correct
151 Correct 89 ms 96048 KB Output is correct
152 Correct 926 ms 137120 KB Output is correct
153 Correct 941 ms 137792 KB Output is correct
154 Correct 990 ms 138456 KB Output is correct
155 Correct 1335 ms 135012 KB Output is correct
156 Correct 1178 ms 134256 KB Output is correct
157 Correct 687 ms 134140 KB Output is correct
158 Correct 968 ms 134132 KB Output is correct
159 Execution timed out 2082 ms 134176 KB Time limit exceeded
160 Halted 0 ms 0 KB -