QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#731623 | #8951. 澡堂 | 5k_sync_closer | 20 | 491ms | 384460kb | C++14 | 2.6kb | 2024-11-10 10:03:46 | 2024-11-10 10:03:48 |
Judging History
answer
#include <cstdio>
#include <algorithm>
#define int long long
using namespace std;
int n, m, q, l, T, Z, a[1000050], b[1000050], s[1000050], f[1000050][23], g[1000050][23];
void F(int l, int r, int d, int &u, int &o, int &z)
{
int v = l;
if (b[v] - d * T >= o)
{
for (int j = __lg(n); j >= 0; --j)
if (b[f[v][j]] - d * T >= o)
v = f[v][j];
v = f[v][0];
}
if (v <= r)
{
z += o * (v - d - u), u = v;
for (int j = __lg(n); j >= 0; --j)
if (f[u][j] <= r)
z += g[u][j] - d * T * (f[u][j] - u), u = f[u][j];
o = b[u] - d * T, u -= d;
}
}
signed main()
{
scanf("%lld%lld%lld%lld", &n, &m, &q, &T);
for (int i = 1; i <= n + 1; ++i)
for (int j = 0; j <= 21; ++j)
f[i][j] = n + 1;
for (int i = 1; i <= n; ++i)
{
scanf("%lld", a + i), b[i] = i * T - a[i], Z += b[i];
while (l && b[i] < b[s[l]])
f[s[l]][0] = i, g[s[l]][0] = b[s[l]] * (i - s[l]), --l;
s[++l] = i;
}
b[n + 1] = -1e18;
for (int j = 1; 1 << j <= n; ++j)
for (int i = 1; i <= n; ++i)
f[i][j] = f[f[i][j - 1]][j - 1], g[i][j] = g[i][j - 1] + g[f[i][j - 1]][j - 1];
for (int i = 0, x, w; i < q; ++i)
{
scanf("%lld%lld", &x, &w);
int y = lower_bound(a + 1, a + n + 1, w) - a, _ = w;
if (y > x)
{
w = (y - 1) * T - w;
int u, o, z = 0;
if (x != 1)
u = 1, o = b[1], F(1, x - 1, 0, u, o, z);
else if (y != 2)
u = 1, o = b[2] - T;
else
u = 1, o = w;
F(x + 1, y - 1, 1, u, o, z);
if (w < o)
z += o * (y - 1 - u), u = y - 1, o = w;
F(y, n, 0, u, o, z);
z += o * (n - u + 1);
printf("%lld\n", Z + a[x] - _ - z);
}
else
{
w = y * T - w;
int u, o, z = 0;
if (y != 1)
{
u = 1, o = b[1];
for (int j = __lg(n); j >= 0; --j)
if (f[u][j] < y)
z += g[u][j], u = f[u][j];
o = b[u];
}
else
u = 1, o = w;
if (w < o)
z += o * (y - u), u = y, o = w;
F(y, x - 1, -1, u, o, z);
F(x + 1, n, 0, u, o, z);
z += o * (n - u + 1);
printf("%lld\n", Z + a[x] - _ - z);
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 10004kb
input:
1000 5 1000 1969617 59993 133807 154199 240894 438118 483699 540258 892751 922552 1049554 1092961 1153394 1287745 1315664 1372758 1550447 1634967 1817853 1825455 2023239 2064188 2117896 2250036 2453036 2492474 2794776 2917935 3047993 3153958 3163156 3237767 3443614 3664074 3716235 3801008 3822067 40...
output:
933174498561 933101766227 933105109405 933146329454 933140299260 933138339685 933106603626 933155511734 933162055060 933159866214 933134782440 933161214184 933103063660 933062469939 933188020289 933153158980 933127568756 933070267847 933085875160 933093764215 933216150562 933138725077 933172534610 9...
result:
wrong answer 1st lines differ - expected: '145473107761', found: '933174498561'
Subtask #2:
score: 20
Accepted
Test #6:
score: 20
Accepted
time: 455ms
memory: 384432kb
input:
1000000 1 100000 1165 83 197 266 277 299 529 538 601 629 760 792 1081 1208 1211 1387 1726 1873 1932 2198 2437 2448 2584 2715 2813 3113 3169 3207 3386 3934 4013 4032 4057 4137 4213 4396 4666 4754 4786 4856 4917 4966 5054 5124 5151 5196 5505 5548 5583 5730 5763 6031 6161 6169 6372 6446 6517 6712 6744 ...
output:
532526465394304 532526382684731 532526432382169 532526335149396 532526336776485 532526441654485 532526419072018 532526448365904 532526461590885 532526446716107 532526451559614 532526448428416 532526467783803 532526436578785 532526455446447 532526418608776 532526437618228 532526421765463 532526361938...
result:
ok 100000 lines
Test #7:
score: 20
Accepted
time: 461ms
memory: 384288kb
input:
1000000 1 100000 320 81 176 196 266 277 418 437 447 561 667 671 686 708 916 945 987 1077 1147 1343 1447 1459 1622 1739 1821 1907 2052 2211 2334 2483 2502 2553 2681 2879 2899 2996 3003 3075 3089 3141 3197 3312 3411 3450 3488 3525 3711 3870 4033 4066 4103 4216 4290 4341 4406 4500 4578 4600 4655 4697 4...
output:
110078125101649 110078095701794 110078065549730 110078084700891 110078055599406 110078147872941 110078125921229 110078050034681 110078131570282 110078020684010 110078081392840 110078123741061 110078124999461 110078092777746 110078093138994 110078104230505 110078088736720 110078130160314 110078088020...
result:
ok 100000 lines
Test #8:
score: 20
Accepted
time: 440ms
memory: 380336kb
input:
1000000 1 100000 6 1 7 13 19 25 31 37 43 49 55 61 67 73 79 85 91 97 103 109 115 121 127 133 139 145 151 157 163 169 175 181 187 193 199 205 211 217 223 229 235 241 247 253 259 265 271 277 283 289 295 301 307 313 319 325 331 337 343 349 355 361 367 373 379 385 391 397 403 409 415 421 427 433 439 445 ...
output:
5553833 8401453 8535183 8590839 6718701 6182541 5451207 4876437 6914671 6145580 8711335 8930675 5425001 5823370 6065908 7711946 7515358 5634147 4547534 5257419 6534174 5697110 6912866 4423285 8364102 6852541 6022633 6206653 5816343 6654555 6229974 8683850 5257837 5409556 4751045 5008105 6904326 4916...
result:
ok 100000 lines
Test #9:
score: 20
Accepted
time: 458ms
memory: 380648kb
input:
1000000 1 100000 16 16 32 48 64 80 96 112 128 144 160 176 192 208 224 240 256 272 288 304 320 336 352 368 384 400 416 432 448 464 480 496 512 528 544 560 576 592 608 624 640 656 672 688 704 720 736 752 768 784 800 816 832 848 864 880 896 912 928 944 960 976 992 1008 1024 1040 1056 1072 1088 1104 112...
output:
22191202 14316263 14215908 12574050 16955717 13552137 12066124 20974476 13340915 17693977 14052719 24225895 16771725 13796572 20050839 23326520 17991222 14412732 20532603 23738604 21615231 20091979 17370185 12410457 17205185 19921674 18529918 11452550 17698666 15112642 12609850 11971897 14779852 168...
result:
ok 100000 lines
Test #10:
score: 20
Accepted
time: 454ms
memory: 382308kb
input:
1000000 1 100000 7 5 12 19 26 33 40 47 54 61 68 75 82 89 96 103 110 117 124 131 138 145 152 159 166 173 180 187 194 201 208 215 222 229 236 243 250 257 264 271 278 285 292 299 306 313 320 327 334 341 348 355 362 369 376 383 390 397 404 411 418 425 432 439 446 453 460 467 474 481 488 495 502 509 516 ...
output:
6897928 10959197 5040880 7975693 6574287 5036014 10306570 9137913 8958373 4228311 7449261 9379706 9146142 10274232 4463961 10029845 7326894 7032260 6825277 5928071 8814749 4913978 8495037 6832887 4636661 12079588 3444995 7897528 7682909 5806085 10906552 7559878 8880934 10407655 7267429 3731886 11463...
result:
ok 100000 lines
Test #11:
score: 20
Accepted
time: 443ms
memory: 384460kb
input:
1000000 1 100000 54 10 62 114 166 218 270 322 374 426 478 530 582 634 686 738 790 842 894 946 998 1050 1102 1154 1206 1258 1310 1362 1414 1466 1518 1570 1622 1674 1726 1778 1830 1882 1934 1986 2038 2090 2142 2194 2246 2298 2350 2402 2454 2506 2558 2610 2662 2714 2766 2818 2870 2922 2974 3026 3078 31...
output:
999990099478 1000020712128 1000023784105 1000000426030 999967051898 1000028186354 1000005137696 1000007459992 999999989667 999972101077 1000003394026 1000016044861 1000002942535 999992373042 1000012218653 1000015238310 1000007382600 1000004402650 999992394498 999986392430 999993975864 1000011983527 ...
result:
ok 100000 lines
Test #12:
score: 20
Accepted
time: 491ms
memory: 384356kb
input:
1000000 1 100000 40 17 56 95 134 173 212 251 290 329 368 407 446 485 524 563 602 641 680 719 758 797 836 875 914 953 992 1031 1070 1109 1148 1187 1226 1265 1304 1343 1382 1421 1460 1499 1538 1577 1616 1655 1694 1733 1772 1811 1850 1889 1928 1967 2006 2045 2084 2123 2162 2201 2240 2279 2318 2357 2396...
output:
500000527303 500000746017 499967503978 500007250648 500005291749 500004629820 499983324151 499980266264 499966351112 499993188438 500015774244 500004766707 499984969155 500018391637 500014807762 500009826386 500035131469 500022545533 499984841379 500022609759 499990934990 499995147709 500010680726 4...
result:
ok 100000 lines
Test #13:
score: 20
Accepted
time: 445ms
memory: 384360kb
input:
1000000 1 100000 54 35 88 141 194 247 300 353 406 459 512 565 618 671 724 777 830 883 936 989 1042 1095 1148 1201 1254 1307 1360 1413 1466 1519 1572 1625 1678 1731 1784 1837 1890 1943 1996 2049 2102 2155 2208 2261 2314 2367 2420 2473 2526 2579 2632 2685 2738 2791 2844 2897 2950 3003 3056 3109 3162 3...
output:
500002386443 499998979458 500011664725 500011341783 499993738944 500004137954 499981112418 499987830081 499991311719 500004379267 499986707484 500042817877 499981806306 500036313060 500006113447 499999655472 499958926623 499989600304 499950957577 499984617021 500009243539 500021262926 500017351824 4...
result:
ok 100000 lines
Test #14:
score: 20
Accepted
time: 445ms
memory: 384356kb
input:
1000000 1 100000 15 4 18 32 46 60 74 88 102 116 130 144 158 172 186 200 214 228 242 256 270 284 298 312 326 340 354 368 382 396 410 424 438 452 466 480 494 508 522 536 550 564 578 592 606 620 634 648 662 676 690 704 718 732 746 760 774 788 802 816 830 844 858 872 886 900 914 928 942 956 970 984 998 ...
output:
499999793763 500007843697 500005513979 500003594502 499996074937 499998537725 500004096012 500008735454 500004152454 500000568751 500010494658 500002699071 500012815225 499998928026 499999283522 500001200708 499997849850 499998173565 500000907455 499995094179 499996774856 500006115706 499997754467 4...
result:
ok 100000 lines
Test #15:
score: 20
Accepted
time: 420ms
memory: 384456kb
input:
1000000 1 100000 76 2 77 152 227 302 377 452 527 602 677 752 827 902 977 1052 1127 1202 1277 1352 1427 1502 1577 1652 1727 1802 1877 1952 2027 2102 2177 2252 2327 2402 2477 2552 2627 2702 2777 2852 2927 3002 3077 3152 3227 3302 3377 3452 3527 3602 3677 3752 3827 3902 3977 4052 4127 4202 4277 4352 44...
output:
499996922050 500001749644 499980553306 500033080378 499998189130 500013317917 500020273296 500036473243 499964461766 499993953371 499959801684 499968725060 499992480175 500055261991 499970920571 499967171328 500029720775 500055057585 500023488143 500020848450 499964139384 500021829831 499986689677 4...
result:
ok 100000 lines
Subtask #3:
score: 0
Wrong Answer
Dependency #2:
100%
Accepted
Test #16:
score: 0
Wrong Answer
time: 436ms
memory: 384456kb
input:
1000000 2 100000 1216 85 163 231 310 406 408 702 751 766 809 902 1012 1108 1232 1268 1688 1758 1824 1864 1865 1895 2035 2113 2140 2178 2298 2381 2634 2697 2784 2842 2853 3003 3120 3195 3204 3583 3586 3676 3680 3718 3826 3829 3870 3955 4042 4054 4100 4148 4252 4265 4369 4556 4575 4620 4661 4720 4875 ...
output:
558084351246421 558084405514764 558084252531315 558084345142563 558084370477840 558084296263872 558084283181731 558084308041244 558084395280345 558084335896618 558084316545069 558084323882291 558084361729316 558084262746015 558084365602665 558084312045759 558084304174263 558084279809635 558084282500...
result:
wrong answer 1st lines differ - expected: '254084390246421', found: '558084351246421'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Wrong Answer
Test #36:
score: 0
Wrong Answer
time: 449ms
memory: 384424kb
input:
1000000 5 100000 1887 112 168 223 393 535 558 577 631 631 678 682 1043 1099 1268 1337 1396 1437 1472 1510 1587 1804 1984 2013 2290 2294 2392 2474 2547 2694 2717 2742 2841 2880 2906 2985 3030 3047 3064 3108 3275 3375 3440 3451 3488 3950 3957 3963 4047 4086 4335 4378 4448 4490 4544 4622 4864 4875 4897...
output:
893584968991754 893584984212509 893585051083652 893584930600924 893584944776960 893584938734741 893584885638322 893584910752748 893584955056978 893584898092366 893584916284906 893585000107446 893585030346881 893585014845551 893584957084055 893584956579155 893584930255009 893584989576264 893584952954...
result:
wrong answer 1st lines differ - expected: '138785143191754', found: '893584968991754'
Subtask #6:
score: 0
Skipped
Dependency #3:
0%