QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#364904 | #8314. Jewel Grab | 口嗨战神 (Binyang Jiang, Dayu Wang, Hejun Dong) | AC ✓ | 762ms | 39036kb | C++20 | 3.4kb | 2024-03-24 17:16:32 | 2024-03-24 17:16:33 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define Mp make_pair
#define mk make_pair
#define SZ(x) (int((x).size()))
typedef double db;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MAXN = 2e5 + 5;
int n, m, c[MAXN], v[MAXN];
int last[MAXN];
set<int> pos[MAXN];
ll sum[MAXN];
void add(int x, int v) {
for(; x < MAXN; x += x & -x)
sum[x] += v;
}
ll ask(int x) {
ll ans = 0;
for(; x; x -= x & -x)
ans += sum[x];
return ans;
}
int Max[MAXN << 2];
void upd(int x, int l, int r, int pos, int val) {
if(l == r) {
Max[x] = val;
return ;
}
int mid = l + r >> 1;
if(pos <= mid) upd(x << 1, l, mid, pos, val);
else upd(x << 1 | 1, mid + 1, r, pos, val);
Max[x] = max(Max[x << 1], Max[x << 1 | 1]);
}
int get(int x, int l, int r, int ql, int val) {
if(Max[x] < val) return r;
if(l == r) return l - 1;
int mid = l + r >> 1;
if(ql > mid) return get(x << 1 | 1, mid + 1, r, ql, val);
else {
int t = get(x << 1, l, mid, ql, val);
if(t == mid) return get(x << 1 | 1, mid + 1, r, ql, val);
else return t;
}
}
void calc(int l, int k) {
// set<int> a; a.clear();
// int now = l, r = l, cnt = 0;
// while(r < n) {
// if(last[r + 1] < l || cnt + 1 <= k) r++;
// else break;
// if(last[r] >= l) cnt++, a.insert(c[r]);
// }
set<int> a; a.clear();
int now = l, r = l;
for(int i = 0; i <= k; i++) {
if(now > n) {
r = n;
break;
}
int p = get(1, 1, n, now, l);
now = p + 2, r = p;
if(r == n) break;
if(i != k) a.insert(c[p + 1]);
}
ll ans = ask(r) - ask(l - 1);
for(auto o : a) {
int Max = 0;
for(auto it = pos[o].lower_bound(l); it != pos[o].end() && *it <= r; it++)
ans -= v[*it], Max = max(v[*it], Max);
ans += Max;
}
cout << ans << '\n';
}
void solve() {
cin >> n >> m;
for(int i = 1; i <= n; i++) pos[i].insert(0);
for(int i = 1; i <= n; i++) {
cin >> c[i] >> v[i];
last[i] = *pos[c[i]].rbegin();
pos[c[i]].insert(i), upd(1, 1, n, i, last[i]), add(i, v[i]);
}
for(int i = 1; i <= m; i++) {
int opt;
cin >> opt;
if(opt == 1) {
int x, co, vo;
cin >> x >> co >> vo;
{
pos[c[x]].erase(x);
auto o = pos[c[x]].upper_bound(x);
if(o != pos[c[x]].end()) {
int t = *o;
last[t] = last[x], upd(1, 1, n, t, last[t]);
}
}
add(x, vo - v[x]), c[x] = co, v[x] = vo;
{
auto o = pos[c[x]].upper_bound(x);
if(o != pos[c[x]].end()) {
int t = *o;
last[t] = x, upd(1, 1, n, t, last[t]);
}
last[x] = *--o, upd(1, 1, n, x, last[x]);
pos[c[x]].insert(x);
}
} else {
int s, k;
cin >> s >> k;
calc(s, k);
}
}
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int t = 1;
// cin >> t;
while(t--) solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 15928kb
input:
5 6 1 3 2 4 3 1 2 2 3 5 2 1 0 2 1 1 2 1 2 1 4 3 3 2 3 1 2 2 2
output:
8 8 12 3 9
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 12ms
memory: 18320kb
input:
1000 20000 1 239175301 1 434896725 1 217110598 1 844028891 1 111154065 1 406736051 1 1016220 1 221593688 1 321632211 1 533100136 1 77920925 1 902708090 1 468673426 1 211315972 1 859308383 1 835428878 1 863423318 1 866577304 1 479787823 1 231949916 1 961418811 1 506030912 1 648768620 1 130344511 1 14...
output:
938696260 987740870 971059911 808984632 919148989 942586434 991209684 902708090 620727233 746359090 832380885 661217055 979453571 772664664 471866201 927063277 789893508 961418811 853907262 993668527 854784618 475055253 956418619 27266795 887593306 773465845 946457950 563748328 907980573 832572288 9...
result:
ok 13334 lines
Test #3:
score: 0
Accepted
time: 19ms
memory: 18056kb
input:
1000 20000 4 368468632 4 393563283 2 934626531 1 19122754 3 408321192 4 268360030 5 274605539 4 335693164 5 226434715 2 413775604 1 640101253 2 339837727 3 443994566 2 347589410 1 69209462 5 156878289 1 734154898 4 892232140 3 368880995 5 852078179 3 133535486 4 706490480 5 442538077 1 717824928 5 8...
output:
4040099474 3033057615 3682912857 2732099999 4054571179 3270049193 3965138929 3842760414 3443277479 3458335772 3544327917 3497578521 714207351 1236976694 2102202941 2688950284 3114966364 2382936119 2645274582 1416354023 3841957183 2458731729 4218903764 3691366645 3747447205 4162743476 1412598975 3871...
result:
ok 13334 lines
Test #4:
score: 0
Accepted
time: 16ms
memory: 18092kb
input:
1000 20000 71 972823931 31 583594501 13 578962859 53 221180625 21 421760060 63 406720444 16 735654564 44 720980938 27 747574151 69 35438889 65 317837373 64 854973543 28 956431972 73 522073670 70 763247400 13 180874758 65 861877444 63 586868457 4 227940566 32 485546012 36 450638070 30 353711667 28 82...
output:
17815821501 16530320565 11053098980 11208743241 3081878975 7303357757 19774731386 17146338404 20806627045 16526945806 14442825647 5124531567 11082934187 19163008687 8839254920 6900571240 15721643134 12777854952 15769554374 13638273980 19317368303 15862625341 22372117997 12140583364 6650295099 109527...
result:
ok 13334 lines
Test #5:
score: 0
Accepted
time: 363ms
memory: 39036kb
input:
200000 200000 1 652507684 3 459291005 2 473763761 4 181507161 1 438476605 3 438255135 2 344617915 4 611754003 3 839451458 4 377311036 2 739156322 4 595459201 3 633048919 2 626711773 3 369048080 5 52002323 1 149359802 3 650945023 3 87450704 3 485674474 1 193829592 4 623550777 5 754075851 1 284158633 ...
output:
1212558677 3030233764 1563800994 1227013292 2181259772 3944094082 3282625458 3459807968 3416461538 2574283766 1762501763 3130727734 2287092555 1382256743 2778887621 3341403504 1571188909 1016802961 3022193931 2713378353 2641257404 2492233918 1475857530 3905367049 2265731306 3219024701 3196057909 266...
result:
ok 150000 lines
Test #6:
score: 0
Accepted
time: 485ms
memory: 38784kb
input:
200000 200000 56 175960257 41 512191011 58 647105026 57 557926244 25 986749714 59 537888291 32 969071136 62 102346697 75 761923748 70 546070172 26 357785356 75 267259941 60 612616490 3 457694507 66 644770087 78 121614678 49 177667380 76 778626896 29 267402905 61 494333759 72 599011639 13 843260789 2...
output:
18345515845 14785049062 9557077958 19026838128 16826985333 18319228581 21583546521 19199091964 20633403267 16277348066 14672350271 6392385983 16250589676 10987301422 19985335646 9378444735 15761125667 18824844694 2920876306 10578025141 12004401380 11418410832 15999448723 8507794248 10513137749 13770...
result:
ok 150000 lines
Test #7:
score: 0
Accepted
time: 493ms
memory: 38724kb
input:
200000 200000 281 905270846 38 483661513 292 660585654 242 353015021 211 659775309 216 899386446 58 21026364 276 221830943 5 166269230 205 151348992 215 813450045 120 541075237 200 615535954 211 681670942 111 750593843 35 616153225 110 675599138 9 814230360 308 137189243 222 697517686 113 659757317 ...
output:
28429457227 19299148035 22270598919 24209429917 38490851248 29473824110 29815914574 18738400900 29209719984 14541422946 39895376445 12562766086 29885713678 37070517828 22072892016 22811329615 16120701157 38541290768 11787709389 30364267139 21136822877 36101336552 10986133201 33467982650 8050809968 1...
result:
ok 150000 lines
Test #8:
score: 0
Accepted
time: 447ms
memory: 38688kb
input:
200000 200000 1027 66264069 5728 186413105 4378 910396578 4008 757418150 2047 662078679 2843 322916786 1640 965507950 888 98120699 521 33102153 4954 968096529 5293 679457461 872 506516934 4867 202224610 3087 435476326 1749 334032938 5918 675593997 840 830348521 2970 867524068 3415 59669820 1940 2837...
output:
106755867173 69840586443 140935462914 134890591964 131263810051 20709965944 125063384332 55845604572 65262358357 221949075394 150658646453 157178602808 88968230491 186481241898 176889725013 119747925207 147677276861 178692804181 65997314775 101953203786 92306278753 191447415637 113055106514 12588902...
result:
ok 150000 lines
Test #9:
score: 0
Accepted
time: 414ms
memory: 38724kb
input:
200000 200000 5534 100912066 22640 124595001 3841 521864664 11626 368187347 5131 836963044 11192 604522205 16848 548094918 11742 128336355 13738 42773499 9509 798670445 16294 553940787 4735 284046021 13349 591865973 18329 640110028 21348 782321037 4245 415148850 204 682911749 9177 203334579 9152 307...
output:
240760052346 308667705243 71320032331 268742211439 125933447790 284901699713 110303505209 349044980338 95152638580 205366604450 374339507691 109476573545 119156720581 306787464703 235379295812 269222412899 125781742640 282201752389 124606649718 163597336098 222897723275 343586956487 152730654526 313...
result:
ok 150000 lines
Test #10:
score: 0
Accepted
time: 375ms
memory: 38960kb
input:
200000 200000 127832 276573651 157680 399401278 105675 823622545 124542 135999016 59192 344815535 190677 230292189 40725 743419476 72431 164863074 33926 130596720 40530 993048359 88232 41614837 185078 797941896 66480 981711697 97703 139085697 126023 49930296 145097 864865007 97109 782634498 30253 63...
output:
383638042653 762094431853 693971931517 585274381622 802513943313 571778603510 286578511968 360901639246 789566787612 594146107054 766047882656 1079302922186 1081561231495 377664780129 563247861750 551030312693 729169162142 1053776204461 723156705388 548098307866 1219774246341 929974008358 1101954220...
result:
ok 190000 lines
Test #11:
score: 0
Accepted
time: 762ms
memory: 39008kb
input:
200000 200000 5023 166697252 5303 730247839 9786 283854417 1474 591127264 6629 547281396 1651 41105661 294 122105870 8403 21601774 4896 165071959 2981 140742247 1771 804393762 2492 852298553 7271 737846033 8602 126311853 6741 814671619 8392 911780612 9032 125106641 717 191475938 1791 884781709 8343 ...
output:
205503294599 193958608631 290550339640 217834047652 238714650310 209545836029 216082579905 262993996578 231693237003 146334449486 172412413501 219501842553 243487544972 208789581882 257052329586 198358753517 212929406331 247742893478 218148858883 180216656575 311975299769 223644476349 193328858971 1...
result:
ok 196000 lines
Test #12:
score: 0
Accepted
time: 592ms
memory: 38972kb
input:
200000 200000 73977 401993863 61509 452999091 119496 190290135 33385 910927554 145095 68982784 193712 743979068 76352 755238101 196423 845392528 85229 640277495 16401 170566233 113359 677797843 42754 859845505 65201 317623894 94039 905863979 21653 798346656 7399 726956731 74107 811339456 159201 9784...
output:
860479826317 771659168022 776293971489 831288423023 854708862233 1252111527010 870287099628 1006372123421 942125473246 1055788515498 783760150156 1225713583747 1122037001787 946902767427 1271600836991 760670753261 1351233349522 1010671435515 880223141490 1183755002432 969691532023 1349559169324 1085...
result:
ok 196000 lines
Test #13:
score: 0
Accepted
time: 201ms
memory: 38796kb
input:
200000 200000 5564 449024882 158001 731971916 25860 697978897 148901 275583531 114224 876092317 141246 310164486 178987 7089444 79148 151467810 126292 120672549 138011 909897348 33277 179045652 72837 777330237 8611 459076266 196490 389349126 161813 681482408 181064 338229267 165078 676398782 107477 ...
output:
1363280696253 2429254777230 978161633736 563356209971 1231042207223 1695438133627 2556580424919 1368250129674 1352319378533 2411342134217 2093124687093 495003879154 1619509942560 2691451169071 2109792157605 804161591091 1200371113367 302989576573 2446670354556 2187723458739 960097997159 816266234791...
result:
ok 100000 lines
Test #14:
score: 0
Accepted
time: 190ms
memory: 38796kb
input:
200000 200000 116177 219807417 149635 284304017 137783 221366979 164482 588915184 13043 654751448 80456 903261548 50994 25240048 171652 928355040 123938 405691631 108923 724257285 41263 288943991 189630 93511159 105923 296421998 168386 652124421 104026 175124834 164421 268161536 63692 462233884 5909...
output:
3909957766053 17281328393391 10989937584357 5056210643272 15051663866521 22074072087921 19313665046050 15137427531290 9160705040991 17650203459350 20694559592233 4711392559350 23077343865962 11133954655334 23813935011230 11518918366831 23800273821643 20728119744622 10164655165668 13285156682078 7512...
result:
ok 100000 lines
Test #15:
score: 0
Accepted
time: 157ms
memory: 38768kb
input:
200000 200000 83527 976234776 197941 144400314 25785 413041151 46390 47799768 83925 710578064 60149 381110106 48958 280424763 194783 323997506 51501 969121411 38197 567673379 194355 664447495 1392 742110928 70514 869015405 155083 103209045 7551 764015134 97847 24952973 151950 434140134 37867 6453637...
output:
42954438066936 10579703637263 15786653961704 56692332791833 24753392920404 13836577907433 17070236261481 7554547895188 36779640419424 43036084963141 11306298679203 54777675521216 30712520788894 24525451693999 16796815398007 26951222029459 48562977431897 42207645874086 17752472430194 35527330939720 7...
result:
ok 100000 lines
Test #16:
score: 0
Accepted
time: 220ms
memory: 38792kb
input:
200000 200000 31920 555929339 73578 875332640 131455 27713920 64660 309798320 39888 532694029 125062 682091946 41973 439226588 5330 948458634 148746 948586675 123765 445549604 72679 236281241 54441 580215060 104128 815678549 57002 59476593 118960 337635332 127874 2617763 157968 464507837 159021 7692...
output:
970381615593 2377259860188 1394558624766 2152489165033 1799425202918 1445823271024 630074249507 1111669070093 1162855581326 2792003901474 119264055476 2836307870857 1441245537029 2540981532653 1101208682763 2598971755720 418812081563 878017481206 1194831380720 883860121417 1078752545973 110169299784...
result:
ok 100000 lines
Test #17:
score: 0
Accepted
time: 193ms
memory: 38764kb
input:
200000 200000 132224 880942890 167411 514392174 92445 780574242 133216 135777127 42296 225383522 196765 422008329 37755 234058187 88550 561882505 148252 796639277 71795 290375957 172635 608610871 79411 646918583 45615 832557974 68481 181950100 16786 316702500 151322 2827168 73274 480499077 168118 25...
output:
17133918544785 7097348650456 3185987635078 10856822517236 3492592183625 4790700161484 11301197270558 18511766416212 9104415565340 3374497164156 7616451601892 5581354039238 14288503823632 10641835712363 10838521955427 3901566868403 4351239987912 5048704035660 16564205856508 18404861165970 10998945519...
result:
ok 100000 lines
Test #18:
score: 0
Accepted
time: 173ms
memory: 38800kb
input:
200000 200000 122647 461279211 104012 268230123 187188 35050518 29215 141958443 159770 303101249 73186 559068379 26526 621755799 138913 943180663 44889 527941785 67517 810289823 97279 870489132 12508 502107664 42077 929361300 172005 457022427 17197 77627961 106489 436318814 47681 185895364 183315 63...
output:
47900155374312 49946444906040 34759075217952 13895609349294 32611746470633 815155300768 49962908541351 49930885371389 49927692457624 1282664323440 9347569333716 4190035673839 4622135279656 49914748911620 36332595143330 32330601174108 38499184916209 11449320094904 49935456793515 27996170375982 126215...
result:
ok 100000 lines
Extra Test:
score: 0
Extra Test Passed