QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#290623 | #2016. 贪吃蛇 | MoRanSky | 100 ✓ | 208ms | 40884kb | C++23 | 1.9kb | 2023-12-25 06:10:24 | 2023-12-25 06:10:24 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
using namespace std;
const int N = 1000005, INF = 2e9;
int n, a[N], d[N], mx[N], mn[N], ans;
struct E{
int x, id;
bool operator < (const E &b) const {
if (x != b.x) return x < b.x;
return id < b.id;
}
bool operator == (const E &b) const {
return x == b.x && id == b.id;
}
};
E b[N], c[N], f[N];
int hh, tt, L, R;
E inline getMax() {
E x = (E) { -1, -1 };
if (hh <= tt && x < b[hh]) x = b[hh];
if (L <= R && x < c[L]) x = c[L];
if (hh <= tt && x == b[hh]) hh++;
if (L <= R && x == c[L]) L++;
return x;
}
E inline getMin() {
E x = (E) { INF, INF };
if (hh <= tt && b[tt] < x) x = b[tt];
if (L <= R && c[R] < x) x = c[R];
if (hh <= tt && x == b[tt]) tt--;
if (L <= R && x == c[R]) R--;
return x;
}
void inline merge() {
int len = tt - hh + 1 + R - L + 1;
for (int k = 1, i = hh, j = L; k <= len; k++) {
if (j > R || (i <= tt && c[j] < b[i])) f[k] = b[i++];
else f[k] = c[j++];
}
L = 0, R = -1;
hh = 1, tt = len;
for (int i = 1; i <= len; i++) b[i] = f[i];
}
void inline solve() {
hh = 0, tt = -1, L = 0, R = -1;
memset(d, 0, sizeof d);
ans = 1;
for (int i = n; i; i--) b[++tt] = (E) { a[i], i };
bool ok = false;
for (int i = n; i >= 2; i--) {
E A = getMax(), B = getMin();
mx[i] = A.id, mn[i] = B.id;
c[++R] = (E) { A.x - B.x, mx[i] };
if (!ok && A.x < B.x * 2) {
ok = true;
merge();
}
d[mn[i]] = i - 1;
}
for (int i = 2; i <= n; i++)
if (d[mx[i]] >= ans) ans = i;
printf("%d\n", ans);
}
int main() {
int T; scanf("%d", &T); T--;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", a + i);
solve();
while (T--) {
int k; scanf("%d", &k);
for (int i = 1, x, y; i <= k; i++) {
scanf("%d%d", &x, &y);
a[x] = y;
}
solve();
}
return 0;
}
详细
Test #1:
score: 5
Accepted
time: 2ms
memory: 18132kb
input:
10 3 29 46 67 3 1 15 2 34 3 114 3 1 120 2 168 3 224 3 1 65 2 132 3 293 3 1 79 2 192 3 474 3 1 24 2 64 3 562 3 1 396 2 458 3 595 3 1 44 2 317 3 592 3 1 138 2 145 3 572 3 1 602 2 726 3 831
output:
3 1 3 1 1 1 3 1 1 3
result:
ok 10 lines
Test #2:
score: 5
Accepted
time: 0ms
memory: 18128kb
input:
10 3 21 73 85 3 1 53 2 69 3 126 3 1 90 2 244 3 259 3 1 67 2 288 3 320 3 1 247 2 351 3 445 3 1 150 2 483 3 568 3 1 534 2 583 3 590 3 1 114 2 226 3 745 3 1 199 2 436 3 513 3 1 147 2 324 3 555
output:
3 1 3 3 3 3 3 1 3 1
result:
ok 10 lines
Test #3:
score: 5
Accepted
time: 0ms
memory: 18116kb
input:
10 3 31 64 74 3 1 68 2 83 3 98 3 1 1 2 81 3 102 3 1 98 2 140 3 247 3 1 20 2 76 3 276 3 1 276 2 384 3 592 3 1 25 2 275 3 361 3 1 597 2 632 3 764 3 1 72 2 151 3 455 3 1 224 2 546 3 834
output:
3 3 1 1 1 3 1 3 1 1
result:
ok 10 lines
Test #4:
score: 5
Accepted
time: 4ms
memory: 18232kb
input:
10 3 24 62 82 3 1 19 2 28 3 145 3 1 98 2 198 3 278 3 1 25 2 67 3 278 3 1 20 2 254 3 262 3 1 110 2 175 3 585 3 1 87 2 369 3 584 3 1 222 2 524 3 604 3 1 11 2 27 3 420 3 1 241 2 495 3 838
output:
3 1 3 1 3 1 1 3 1 1
result:
ok 10 lines
Test #5:
score: 5
Accepted
time: 3ms
memory: 18228kb
input:
10 10 3 9 37 42 43 55 55 67 69 95 10 1 10 2 15 3 75 4 121 5 129 6 140 7 157 8 158 9 165 10 172 10 1 2 2 34 3 44 4 48 5 129 6 166 7 169 8 170 9 253 10 295 10 1 29 2 65 3 147 4 177 5 208 6 267 7 295 8 306 9 360 10 386 10 1 64 2 131 3 133 4 151 5 186 6 245 7 259 8 324 9 347 10 422 10 1 32 2 52 3 101 4 ...
output:
7 7 5 7 7 5 7 7 5 7
result:
ok 10 lines
Test #6:
score: 5
Accepted
time: 0ms
memory: 18224kb
input:
10 10 1 11 17 21 40 51 54 75 83 91 10 1 27 2 44 3 46 4 52 5 72 6 81 7 125 8 130 9 167 10 175 10 1 14 2 56 3 66 4 68 5 95 6 133 7 164 8 269 9 271 10 274 10 1 60 2 64 3 78 4 111 5 123 6 176 7 210 8 311 9 353 10 354 10 1 25 2 89 3 149 4 172 5 281 6 283 7 338 8 437 9 463 10 470 10 1 129 2 168 3 201 4 34...
output:
5 5 5 5 7 7 5 7 7 5
result:
ok 10 lines
Test #7:
score: 5
Accepted
time: 0ms
memory: 18260kb
input:
10 10 4 13 20 58 62 67 74 77 93 93 10 1 10 2 34 3 58 4 67 5 81 6 87 7 98 8 143 9 152 10 193 10 1 35 2 80 3 100 4 106 5 171 6 173 7 184 8 240 9 278 10 297 10 1 17 2 46 3 48 4 317 5 328 6 364 7 378 8 383 9 384 10 399 10 1 22 2 34 3 58 4 96 5 99 6 100 7 156 8 190 9 414 10 443 10 1 57 2 63 3 78 4 170 5 ...
output:
7 5 7 7 3 7 7 7 7 7
result:
ok 10 lines
Test #8:
score: 5
Accepted
time: 3ms
memory: 18228kb
input:
10 10 4 18 36 41 50 58 59 78 84 92 10 1 42 2 43 3 54 4 54 5 67 6 152 7 153 8 161 9 182 10 190 10 1 9 2 49 3 58 4 64 5 82 6 185 7 258 8 272 9 277 10 286 10 1 10 2 141 3 151 4 169 5 198 6 240 7 282 8 284 9 353 10 387 10 1 3 2 73 3 158 4 196 5 245 6 265 7 311 8 324 9 378 10 448 10 1 26 2 45 3 156 4 157...
output:
7 5 5 7 7 5 5 7 3 5
result:
ok 10 lines
Test #9:
score: 5
Accepted
time: 5ms
memory: 16180kb
input:
10 2000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 8 ...
output:
1226 1222 1227 1231 1245 1189 1237 1219 1224 1255
result:
ok 10 lines
Test #10:
score: 5
Accepted
time: 2ms
memory: 18224kb
input:
10 2000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 8 8 8 8 ...
output:
1231 1239 1228 1233 1213 1233 1242 1255 1223 1261
result:
ok 10 lines
Test #11:
score: 5
Accepted
time: 5ms
memory: 18160kb
input:
10 2000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 8 ...
output:
1236 1236 1201 1213 1232 1235 1214 1243 1257 1229
result:
ok 10 lines
Test #12:
score: 5
Accepted
time: 46ms
memory: 20368kb
input:
10 50000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
30512 30779 30949 30796 30946 30847 30807 30937 30867 30808
result:
ok 10 lines
Test #13:
score: 5
Accepted
time: 44ms
memory: 20368kb
input:
10 50000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
30619 30660 30793 30727 30877 30771 30846 30589 30800 30975
result:
ok 10 lines
Test #14:
score: 5
Accepted
time: 43ms
memory: 18500kb
input:
10 50000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
30435 30814 30682 30922 30855 30868 30851 31023 30968 30951
result:
ok 10 lines
Test #15:
score: 5
Accepted
time: 199ms
memory: 38856kb
input:
10 1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
609762 609762 609762 613003 613003 613003 613003 613003 613003 609165
result:
ok 10 lines
Test #16:
score: 5
Accepted
time: 191ms
memory: 40800kb
input:
10 1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
609891 609892 609892 609892 609892 609892 609892 618092 618092 618092
result:
ok 10 lines
Test #17:
score: 5
Accepted
time: 208ms
memory: 40884kb
input:
10 1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
609983 609983 609983 609984 609984 609984 609984 609070 609070 609071
result:
ok 10 lines
Test #18:
score: 5
Accepted
time: 193ms
memory: 40868kb
input:
10 1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
610259 610259 610259 613586 613586 613586 613586 616676 616676 616677
result:
ok 10 lines
Test #19:
score: 5
Accepted
time: 197ms
memory: 38852kb
input:
10 1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
610386 610386 610386 613680 613680 613680 613680 618492 618492 618493
result:
ok 10 lines
Test #20:
score: 5
Accepted
time: 192ms
memory: 36704kb
input:
10 1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
610138 610138 610138 613036 613036 613036 613036 613036 613036 609198
result:
ok 10 lines
Extra Test:
score: 0
Extra Test Passed