QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#318004 | #4055. 整数序列 | chy12321 | 20 | 2030ms | 21828kb | C++14 | 1.8kb | 2024-01-30 10:16:39 | 2024-01-30 10:16:40 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
constexpr int N = 3e5 + 10, L = 500;
constexpr ll inf = 1e18;
int n, q, b[N];
vector<int> p[N];
namespace SS {
int cnt, a[N], c[N];
unordered_map<int, ll> mn;
ll solve(int x, int y) {
cnt = 0; int i = 0, j = 0;
while (i < p[x].size() && j < p[y].size()) {
cnt++;
if (p[x][i] < p[y][j]) a[cnt] = p[x][i++], c[cnt] = 1;
else a[cnt] = p[y][j++], c[cnt] = -1;
}
while (i < p[x].size()) a[++cnt] = p[x][i++], c[cnt] = 1;
while (j < p[y].size()) a[++cnt] = p[y][j++], c[cnt] = -1;
int s = 0; ll sum = 0, ans = -inf;
mn.clear(), mn[0] = 0;
for (int i = 1; i <= cnt; i++) {
s += c[i], sum += b[a[i]];
if (mn.find(s) != mn.end()) {
ans = max(ans, sum - mn[s]);
mn[s] = min(mn[s], sum);
} else mn[s] = sum;
}
return ans;
}
}
namespace BB {
int cnt, a[N], c[N];
map<pii, ll> mem;
ll solve(int x, int y) {
if (mem.find(pii(x, y)) != mem.end()) return mem[pii(x, y)];
return mem[pii(x, y)] = SS::solve(x, y);
}
}
int main() {
// freopen("ex_sequence2.in", "r", stdin), freopen("sequence.out", "w", stdout);
ios_base::sync_with_stdio(0); cin.tie(nullptr), cout.tie(nullptr);
cin >> n >> q;
for (int i = 1, a; i <= n; i++) cin >> a, p[a].emplace_back(i);
for (int i = 1; i <= n; i++) cin >> b[i];
while (q--) {
int x, y; cin >> x >> y;
if (p[x].size() > p[y].size()) swap(x, y);
if (p[y].size() <= L) cout << SS::solve(x, y) << '\n';
else if (p[x].size() > L) cout << BB::solve(x, y) << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5
Accepted
time: 16ms
memory: 15980kb
input:
5000 4999 1242 1550 3974 121 3049 2220 2031 3596 4083 346 2893 1242 2610 4935 4633 4195 4937 3783 1241 1867 4633 3519 660 4861 3616 1628 4633 3519 137 2347 4634 1242 1469 781 1632 1051 3147 288 3154 4633 1993 288 780 1242 4086 4312 4924 328 137 3154 2738 756 1952 98 1524 3974 3072 3519 3346 1242 165...
output:
1654077332 586562376 1647677275 9480498939 4337498611 2321392596 684160122 2961273810 3652261363 5768409888 2141765733 3446798022 1013520529 2585196873 1880556733 1082439832 2973800608 3395319881 -719609264 3650012737 1335753656 2356743437 2467991607 2774173366 1830795793 4127732589 1953952920 19319...
result:
ok 4999 numbers
Test #2:
score: 5
Accepted
time: 11ms
memory: 13848kb
input:
4999 5000 3440 4463 103 3377 2009 1045 2434 2920 2434 1564 2870 2732 749 1324 1178 4353 2127 1161 2482 853 1835 1830 3673 294 4750 4809 676 676 1374 1324 4039 2870 3962 788 4839 3204 1324 3440 3220 703 3440 391 2870 221 3440 4655 1461 2097 2612 4253 1865 2275 4011 3395 2612 829 1559 4216 2434 2434 1...
output:
2431371641 3504197188 2801830916 2708894780 2142511353 3560512545 1488249705 3944797080 7305163029 813723164 3307776497 1517843290 1767435435 2607802220 1042973982 3222063247 1375218761 1983436411 3991174125 1011628113 1482720392 1752276707 1867793702 2912803142 1586320530 1874783255 -532744293 5437...
result:
ok 5000 numbers
Test #3:
score: 5
Accepted
time: 11ms
memory: 13856kb
input:
5000 4999 721 2854 978 3366 2366 2071 3792 3235 3235 4826 3204 2352 2296 3204 2038 3159 3204 507 2366 1665 2338 2504 2247 3342 4826 4826 3456 1200 3204 2366 447 4608 1300 447 109 1933 162 3226 3258 74 3215 2951 2410 2262 721 4826 2808 1157 1180 1316 2421 481 3230 1316 3056 2359 322 3204 2262 3204 59...
output:
4168530749 3301336051 1328365521 1631901291 2469627282 4155007438 1208484545 2171379787 2301433988 3151307956 1580471032 2848621793 -134937345 1695300151 1403551326 872676430 1711924639 52205391 3566349635 1914704044 2818195255 4948501430 1477693277 1325417496 1180193991 2432291844 -343079851 460560...
result:
ok 4999 numbers
Test #4:
score: 5
Accepted
time: 11ms
memory: 15984kb
input:
4999 5000 1169 743 965 2404 2438 551 4692 337 743 1866 2453 743 1866 1157 3204 2181 1311 4867 3139 56 955 4635 3301 2569 1067 700 1866 1165 4224 743 3620 2360 689 4746 1177 1157 2569 4357 4765 1043 2601 1169 1866 4044 4224 4727 743 743 3191 700 1675 1866 551 3301 4224 4217 2204 3735 1871 689 743 700...
output:
3238411667 422996002 3009692904 2023457310 1697128767 1732840951 -771798243 -147296037 1663332547 -145057279 3153350823 656351788 1141898611 5198597934 1219203999 3609030959 2021751936 -192679403 -743424200 2503805266 3157480950 1801414071 8251501917 3994954212 2265920218 2263046979 1152268009 17149...
result:
ok 5000 numbers
Test #5:
score: 0
Wrong Answer
time: 1117ms
memory: 17060kb
input:
300000 1000000 210616 109093 194161 18266 74476 222692 179435 112558 155417 194161 60442 219569 121583 64920 210616 119012 79775 84215 18266 109093 18266 197546 74044 194161 162053 233329 119012 74476 8047 126329 194161 201328 189361 194161 112200 99319 74044 201328 289127 119012 179435 283375 19512...
output:
4219197017 4554888226 4604171163 32314484666 26764270945 4857537785 4127652115 1012704318 3951500069 26194054668 3828302916 4805755198 3967375531 25497531513 3805726339 3979250323 24474967319 43214940859 53455936977 27815310752 3427954635 36207955009 3967778826 4601441126 24781195394 4405815803 4148...
result:
wrong answer 18th numbers differ - expected: '751331816', found: '43214940859'
Test #6:
score: 0
Wrong Answer
time: 1137ms
memory: 18032kb
input:
299999 1000000 215543 183462 57241 150146 75108 2589 28359 104656 85936 49139 272845 26114 183462 92642 110658 2589 218311 231610 144686 2589 161638 92555 130256 91926 28344 272662 51005 105130 131618 89779 28359 28420 172552 218311 92555 131618 144364 188255 2589 215543 57241 110658 25236 28344 131...
output:
2510540872 1052440958 27314264168 4304554906 4846424545 -31509146 4291394952 7232630075 4916538807 5136416553 46596960029 35441936879 4702622729 4139838277 142852489392 4195091059 21679319871 4281270365 45177923 5396629188 3637850635 77218236240 17691645749 106239495406 1334837412 2192210606 4676873...
result:
wrong answer 5th numbers differ - expected: '1772422921', found: '4846424545'
Test #7:
score: 0
Wrong Answer
time: 639ms
memory: 19848kb
input:
150000 500000 132436 8515 14753 132436 44442 132436 63224 132436 132436 132436 10776 132436 132436 132436 106000 132436 132436 138973 18627 139106 106971 132436 132436 126363 135723 319 76472 10220 132436 132436 132436 132436 63083 48327 132436 81505 132436 132436 148574 132436 132436 132436 132436 ...
output:
1068142142 868747680 1172448570 607404535 958186621 1637953169 704758115 1694670347 834880692 811284305 803411134 624174098 1158502642 849260183 1084667559 1170838764 759331534 477915433 1321720662 1414359950 933337328 539575889 931446483 983599379 1080233152 1088554377 695998143 821091904 146738377...
result:
wrong answer 2nd numbers differ - expected: '1655225246', found: '868747680'
Test #8:
score: 0
Wrong Answer
time: 625ms
memory: 19112kb
input:
150000 500000 5202 5202 5202 36166 5202 5202 95724 5202 5202 92605 5202 5202 5202 5202 64052 5202 5202 51686 5202 94344 147952 134686 124500 5202 5202 5202 5202 5202 5202 5202 5202 19171 5202 107149 5202 10457 92605 10677 5202 5202 5202 90631 5202 5202 5202 5202 5202 5202 5202 97189 64052 16557 5202...
output:
1673860056 1103464182 589795308 1328374701 1483554900 1810054747 965017852 1680486213 673398808 1050718790 1040306277 1243088019 569633825 1618612730 897627861 1117885240 3714326970 1368263602 1634873062 402724896 1184509654 1561489526 719778852 1585598081 1480577130 1056259787 674962808 730542534 3...
result:
wrong answer 1st numbers differ - expected: '1282956208', found: '1673860056'
Test #9:
score: 0
Wrong Answer
time: 619ms
memory: 18132kb
input:
149999 500000 130539 130539 130539 135015 130539 68088 130539 135629 130539 130539 130539 130539 130539 129686 145610 73567 52505 130539 130539 130539 14931 38544 107261 130539 130539 51142 14931 68088 130539 35668 130539 130539 106082 61754 130539 65537 130539 130539 69769 130539 130539 20244 10074...
output:
139227247 -883411004 567566156 -1891019340 -99557367 1619439789 15600567 25646376669 1378605135 -457481883 -282045391 583352548 891094858 -766082263 -517387877 -44927258 -780746163 -233010732 279416931 1239706681 335674731 -1504586849 -237669800 229944959 888174251 -32418324 -514184197 309118428 115...
result:
wrong answer 1st numbers differ - expected: '-205375765', found: '139227247'
Test #10:
score: 0
Wrong Answer
time: 2030ms
memory: 21828kb
input:
200000 500000 18780 73334 73334 129506 73334 28788 73334 73334 73334 73334 26535 36488 73334 73334 73334 121456 129506 119075 190638 142411 111475 73334 73334 91293 73334 73334 73334 73334 73334 73334 184692 178784 118264 129506 116620 118404 122852 36488 73334 163977 73334 50087 10210 199390 73334 ...
output:
-804939046 1193756984 547556528 -945521626 149647259 1069992753 701680252 -316635544 -896377184 986510986 -29100558 940272819 -368844561 839341352 317613850 -1563656571 -229741390 1370685817 -294894484 -420108236 40210378 -608610545 -588960787 1526858123 -981292308 -247957735 -392962655 -561374819 9...
result:
wrong answer 1st numbers differ - expected: '971690580', found: '-804939046'
Test #11:
score: 0
Wrong Answer
time: 1521ms
memory: 20900kb
input:
200000 500000 117561 117561 108780 140071 76023 163608 147648 117561 117561 117561 117561 117561 146331 117561 117561 50485 117561 117561 117561 147648 169614 117561 117561 117561 117561 117561 134029 161477 117561 117561 74827 99188 117561 117561 117561 117561 186557 117561 117561 159944 50485 1244...
output:
578016403 -1440039327 1235173258 288940788 -724409102 1363775916 1248490263 -1345198951 974302145 518642429 1670855316 645264306 -1208214038 -1341901647 1150015949 -393591404 1752021127 -16543400 811684272 661408977 -1113179429 1138221911 -1482905880 -94880707 618055066 146643131 1048265615 11381921...
result:
wrong answer 1st numbers differ - expected: '745022908', found: '578016403'
Test #12:
score: 0
Wrong Answer
time: 1460ms
memory: 20556kb
input:
300000 1000000 56219 143695 226286 249694 160309 135267 279081 101944 14091 99207 27252 286872 97823 160309 153937 193629 195292 241817 48132 241817 191469 52905 239169 295659 88239 133799 133799 8234 50907 228407 95709 268342 241817 296967 135267 116559 100835 104182 39121 71692 191469 133799 24181...
output:
2 2 1492 674 2 1154 2 2 2 2 2 2 2 2 1132 2 2 1626 8 10 2 2 2 660 2 2 2 2 1466 2 2 2 994 2 2 2 8 1516 2 2 8 2 2 2 2 1622 812 1580 1290 2 2 1578 2 2 2 2 2 2 2 2 2 2 886 2 2 2 1640 2 1604 1196 2 2 2 2 2 1608 2 2 2 2 2 1152 2 2 2 2 2 1410 2 2 884 2 2 2 2 2 2 1618 2 2 2 2 2 2 2 728 2 2 2 2 2 2 1626 688 2...
result:
wrong answer 3rd numbers differ - expected: '2', found: '1492'
Test #13:
score: 0
Wrong Answer
time: 1471ms
memory: 19436kb
input:
300000 1000000 252427 92158 13474 286432 38970 155012 77876 141812 211941 90991 298722 187008 281303 130407 151235 239285 180713 183820 178795 151235 151161 286432 13474 126097 182453 225946 224795 126021 140814 123569 212222 183820 151235 248332 134648 27062 100877 3515 276112 138511 212687 13474 4...
output:
1240 2 1076 2 2 2 2 2 1150 2 2 742 10 2 2 2 2 2 2 2 1426 2 2 2 2 2 2 2 2 2 1176 2 2 2 1424 8 2 2 2 1620 2 2 2 2 2 2 2 2 1264 2 2 2 2 2 838 4 2 1532 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1654 2 2 2 2 2 852 8 1700 978 2 2 2 2 2 2 2 2 2 2 2 2 2 2 708 2 2 1366 812 2 1714 2 1676 1570 894 1214 2 2 2 1358 2 2 2 2 ...
result:
wrong answer 1st numbers differ - expected: '2', found: '1240'
Test #14:
score: 0
Wrong Answer
time: 1463ms
memory: 19936kb
input:
299999 1000000 102271 20892 168471 178536 165808 72575 225025 79470 180501 268666 197798 145975 243581 255187 142045 197006 30081 242593 83648 170294 86352 78447 177452 275062 165294 113565 142413 293611 280979 4033 272066 195915 122234 86343 79470 261560 26913 221328 168471 78447 18922 296613 10213...
output:
1696 2 2 2 2 2 2 2 2 2 1456 1282 2 1654 2 2 2 2 2 2 2 8 2 2 2 2 2 2 2 2 2 2 2 2 2 1448 2 2 2 2 2 2 2 2 2 2 2 2 2 1672 2 1402 1350 2 2 2 548 2 2 2 2 1522 2 1648 1590 8 2 2 1520 2 1462 2 2 850 932 2 2 646 2 2 2 2 1514 2 2 1322 2 2 1694 2 2 2 2 2 8 2 2 2 2 2 1060 1714 2 1206 2 1034 2 2 2 688 2 8 2 2 2 ...
result:
wrong answer 1st numbers differ - expected: '2', found: '1696'
Test #15:
score: 0
Wrong Answer
time: 1481ms
memory: 19996kb
input:
299999 1000000 151289 14535 244254 290111 288090 130841 27455 106184 47286 236908 173179 159601 134454 134838 14535 203110 92926 274608 87246 215015 245740 295574 123490 290111 134838 216821 114378 188238 134454 188365 234630 2226 97676 134838 290111 2226 44319 241093 115893 134838 43192 179884 1385...
output:
534299024 989074415 650173770407 1187382235 518515379103 1233977548 540568790 1184360372 429307885 809709371858 1069740304 907398748 1300775934 610242686 737958935 680998463868 1325894411 780011062 624200397 1758874765 1551188819 318668572 1458346548 451308808303 1211009447 451263406 571126633 95015...
result:
wrong answer 1st numbers differ - expected: '1797459939', found: '534299024'
Test #16:
score: 0
Wrong Answer
time: 1467ms
memory: 19004kb
input:
300000 1000000 147825 195767 150390 77132 239532 278774 160659 276921 115387 7629 183295 110547 290985 115387 91975 103610 40841 207522 145488 91975 111180 16525 178046 16950 295408 243529 247392 267715 278774 217808 16525 115387 194968 91975 77824 139035 253468 295408 32471 153777 237234 104953 147...
output:
764686467 569405192 367812642 425337103 516360244 709079593 941331650 1118056672 1842524075 691591625325 933668532 1036504492 562916699724 620297676 574823688 325788360743 1323667513 703268782 1174197129 1856823155 1405520753 1474508918 1528746621 796499753576 1289621561 680752531503 1647994325 2231...
result:
wrong answer 1st numbers differ - expected: '1056898397', found: '764686467'
Test #17:
score: 0
Wrong Answer
time: 1508ms
memory: 19372kb
input:
300000 1000000 92527 298213 72198 196854 158708 76270 195790 236817 208173 208173 71266 17759 29102 195790 247368 262696 97153 164699 97153 106281 257441 210052 195790 111950 239957 179014 150594 241963 112387 273448 151221 150594 208173 136209 129633 46494 46494 84383 72786 162998 46494 46494 17291...
output:
871008434 -1401082460 292041445 596574177 313620704 1747288813 -315429294 -979353071 1732038271 -1075536941 30902161503 -328828237 871585594 -1319654524 -1887620436 1237467601 -888638054 28330809909 -74169247 192801817 72240873 -870617149 18916703948 -1375074272 536971771 650779077 518755960 2246631...
result:
wrong answer 1st numbers differ - expected: '862648951', found: '871008434'
Test #18:
score: 0
Wrong Answer
time: 1473ms
memory: 19876kb
input:
299999 1000000 174942 205062 214513 219196 259901 19736 239253 95131 119460 179415 8195 48699 123674 252242 179415 204410 61013 276817 145744 121754 204410 182272 255628 274322 137057 82468 231315 122482 222185 63411 123674 186416 161540 77373 206186 23868 112918 123674 95131 236420 204496 178859 11...
output:
79110342 928922373 28954071644 1503945196 -87719654 16697942978 15936120013 188418066 20712366623 89695495 805527870 1014237188 -939823245 -379532215 34603038220 25190869297 145232644 167325507 13985278180 -133571440 29308471 -1073218039 344827195 57156297 20055742533 17554760730 -251124818 91335771...
result:
wrong answer 1st numbers differ - expected: '447181519', found: '79110342'
Test #19:
score: 0
Wrong Answer
time: 1482ms
memory: 19204kb
input:
300000 1000000 229819 100462 229819 78236 229819 249816 70315 167375 157866 183526 100462 116410 105610 50013 71906 100462 1512 168934 147968 58495 52997 92028 291180 30449 218217 299205 90916 100462 69006 290092 36728 261594 1512 142526 228482 1512 272954 1512 142691 123023 1512 47880 50013 76498 1...
output:
808073317 14936480569 1287572304 -510313264 -684187077 611443505 32752887918 153872487 701865483 17614393966 -557079627 37227460255 21602281539 43198139 416135708 -880439231 -1604335829 804774926 1219190467 581374028 11900840184 1000755250 908118937 -767298490 -320143059 31512637019 340267607 -22517...
result:
wrong answer 1st numbers differ - expected: '-357819734', found: '808073317'
Test #20:
score: 0
Wrong Answer
time: 1479ms
memory: 19268kb
input:
300000 1000000 135822 88561 243121 279557 10947 146084 66559 172695 40359 288955 234013 187141 288955 187141 271817 84283 208724 139740 288955 266331 15885 59084 225069 124976 187141 103698 288955 187141 92132 238696 291003 23394 40340 109700 88561 86940 51845 266331 255230 288955 229039 239891 1871...
output:
-752676521 1641897014 33028076773 630831040 -1019545514 19014500964 136406761 -983793716 15387901008 -626071293 269869716 16542753809 -738883398 1218799529 1593483132 -1431833612 -529907763 -92807665 614903470 16190677898 552691936 -636621208 25306351592 -398535433 19115089822 -405911577 -451383276 ...
result:
wrong answer 1st numbers differ - expected: '192239551', found: '-752676521'