QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#317232 | #8006. Dinosaur Bones Digging | ucup-team2307# | WA | 607ms | 36808kb | C++20 | 2.9kb | 2024-01-28 18:21:53 | 2024-01-28 18:21:55 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a;i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
#define fi first
#define se second
#define pb push_back
//#define int ll
struct Node {
int sm = 0, mx = 0;
Node(int x = 0) : sm(x), mx(max(0, x)) {}
friend Node operator+(const Node &a, const Node &b) {
Node r;
r.sm = a.sm + b.sm;
r.mx = max(a.mx, a.sm + b.mx);
return r;
}
};
struct SegTree {
int n;
vector<Node> tree;
SegTree(int N) : n(2<<__lg(N)), tree(2*n) {}
void add(int pos, int x) {
pos += n;
tree[pos] = Node(tree[pos].sm + x);
while(pos/=2) tree[pos] = tree[2*pos] + tree[2*pos + 1];
}
Node acc(int l, int r) {
Node L, R;
for(l += n, r += n; l < r; l>>=1,r>>=1) {
if(l & 1) L = L + tree[l++];
if(r & 1) R = tree[--r] + R;
}
return L + R;
}
int solve(int l, int r) {
Node pref = acc(0, l + 1);//base is l-th element
Node seg = acc(l + 1, r);//can change to l+1 ... r-1
return pref.sm + seg.mx;
}
};
signed main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int n, q;
cin >> n;
vector<array<int, 2>> vals(n);
for(int i = 0; i < n; i++) {
cin >> vals[i][0];
vals[i][1] = i;
}
sort(all(vals), greater<>());
cin >> q;
vector<array<int, 2>> queries(q);
for(auto &[l, r] : queries)
cin >> l >> r, l--, r--;
sort(all(queries));
{
vector<array<int, 2>> tmp;
int maxR = -1;
for(auto [l, r] : queries) {
if(r > maxR) {
maxR = r;
tmp.push_back({l, r});
}
}
queries = tmp;
q = tmp.size();
}
vector<array<int, 2>> ranges(n);
for(int l = 0, r = 0, i = 0; i < n; i++) {
while(l < q && queries[l][1] < i) l++;
while(r < q && queries[r][0] <= i) r++;
ranges[i] = {l, r};
// cout << i << " " << l << " " << r << endl;
}
SegTree st(q);
ll ans = 0;
vector<int> stupid(n);
for(auto [val, pos] : vals) {
auto [l, r] = ranges[pos];
ans = max(ans, st.solve(l, r) * 1ll * val);
// cout << val << " " << pos << " " << st.get() << endl;
st.add(l, 1);
st.add(r, -1);
// if(1) {
// for(int i = l; i < r; i++)
// stupid[i]++;
// for(int l = 0; l < q; l++) {
// int cur = 0;
// for(int r = l + 1; r <= q; r++) {
// cur = max(cur, stupid[r- 1]);
// assert(st.solve(l, r) == cur);
// }
// }
// }
}
cout << ans << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3528kb
input:
6 3 5 2 7 4 6 2 1 5 3 6
output:
9
result:
ok answer is '9'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
1 100 1 1 1
output:
0
result:
ok answer is '0'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
20 451541695 690066663 673479208 448269517 560111835 982439295 929007403 955125568 735150915 829197546 256554877 435297385 348361716 763574893 202875223 881879899 590527232 256896900 31383620 400212120 5 4 8 4 17 11 13 19 20 17 18
output:
4480894680
result:
ok answer is '4480894680'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
100 310791482 148245051 114541081 918781914 681485137 656214017 226939378 970492592 431199764 162399115 490488808 3059986 487892489 611730708 952388887 418021477 917893766 587279310 363995315 342188612 72531000 156997725 896382592 359419647 144773021 872005978 496280920 65840663 56171913 273988049 6...
output:
23457460782
result:
ok answer is '23457460782'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3624kb
input:
1000 653152089 378327983 557774751 390757038 4471201 856292034 205122039 30258841 396640873 159207453 703775065 793745674 681241216 876218560 582247644 205933914 957242345 112988670 939157518 525653622 262606938 993539583 451620719 700727137 142726078 430071359 426031860 471766448 94089907 167433741...
output:
242077104830
result:
ok answer is '242077104830'
Test #6:
score: 0
Accepted
time: 1ms
memory: 4020kb
input:
10000 760845880 236665988 765352292 817854026 789863420 399953246 270535243 932350041 48814223 670950468 456660682 416165008 999681497 666880584 56581573 134567049 403285848 144814129 973325555 23519957 518449311 738687225 345716065 2309498 477743569 555951695 911860717 920761968 569179690 349857557...
output:
2452630249040
result:
ok answer is '2452630249040'
Test #7:
score: 0
Accepted
time: 189ms
memory: 12424kb
input:
75000 64097076 228795807 236402963 795983877 911904460 793466611 195874572 123239434 599032119 741932 916254858 335612220 445268867 659313703 848780671 12116264 105543333 438293575 879273474 875134498 618135541 308227823 220867277 683811264 720576432 874505737 896095678 437505375 945318773 658945922...
output:
18740230889380
result:
ok answer is '18740230889380'
Test #8:
score: 0
Accepted
time: 193ms
memory: 12924kb
input:
100000 237252794 382693085 295147362 674980341 2958154 807156999 970437955 781426294 772360469 332498984 366981282 102374212 992836938 434644540 742598545 821844749 65037055 208304069 38844999 893543237 392739243 968841288 483750814 102524579 991416234 875749582 237552019 633704354 706506941 8051497...
output:
24967271468601
result:
ok answer is '24967271468601'
Test #9:
score: 0
Accepted
time: 29ms
memory: 5956kb
input:
100000 38413036 456923902 821971466 586909482 636298728 158178471 84422915 632002470 34405999 882453211 922025994 294603996 207311349 526030511 417456448 362917277 456078308 435018316 47342069 47738636 642863127 189926256 40263985 58857249 119358305 864464366 83617839 485428518 305918980 942395945 6...
output:
24903646283538
result:
ok answer is '24903646283538'
Test #10:
score: 0
Accepted
time: 50ms
memory: 8100kb
input:
193531 700185685 653403475 398038439 272114589 644859446 234924539 412364196 347296552 436428000 711722981 547258844 794359236 961133698 639407426 480555752 954373403 653187777 339413210 11632662 145811119 988611894 708168836 83399147 696410193 214277102 445328303 392328860 390290603 283682280 54718...
output:
48119967363993
result:
ok answer is '48119967363993'
Test #11:
score: 0
Accepted
time: 37ms
memory: 7516kb
input:
200000 946595722 271213712 915506504 843189857 889214784 150802916 47950504 875914997 813247785 35791160 36350165 271403304 553268056 642299504 824405101 760788345 582500756 810890307 844167937 517445752 954178007 539167422 956565909 640348492 772207312 776135104 355220770 409647150 406776930 754956...
output:
49398629253632
result:
ok answer is '49398629253632'
Test #12:
score: 0
Accepted
time: 57ms
memory: 8068kb
input:
200000 474676011 939912865 348389405 320057032 401730779 772694363 522559450 449397650 84577374 772638546 454036490 511546084 450152378 361510375 736170896 868337032 233134669 593272303 521368545 910823164 807700292 524313138 209216902 471719411 93601829 139239405 320779934 441796820 979537222 16444...
output:
49741688559332
result:
ok answer is '49741688559332'
Test #13:
score: 0
Accepted
time: 71ms
memory: 8596kb
input:
200000 109397543 143192033 948668698 815492316 724901105 620108314 698967424 360842287 755198103 180096873 94781007 498090054 977844902 23263014 766839886 91213121 401300673 360200922 31701400 481563828 71448349 278872261 492714526 983119401 499513604 154303065 208383011 942154652 116109138 50732665...
output:
49786042407145
result:
ok answer is '49786042407145'
Test #14:
score: 0
Accepted
time: 208ms
memory: 14824kb
input:
200000 261992073 430909777 926146925 252251819 677218593 568716743 908238045 661028536 139554984 409946901 500485900 106878666 866267660 873908781 889662294 441992527 580144564 430178452 766191560 763853446 251057656 399523045 657208230 289791746 758935460 495002956 936637415 295647787 117309049 752...
output:
49900955205738
result:
ok answer is '49900955205738'
Test #15:
score: 0
Accepted
time: 104ms
memory: 13708kb
input:
500000 543196303 520001257 135913319 141681743 72855073 102021396 17954772 995707282 533540003 144014914 804630833 49605709 207753044 457005411 880119304 425402060 566315173 703211964 652934484 672802538 674426047 85342051 819455751 579118746 150110202 364244420 947318917 16739938 751932263 60777782...
output:
124534814723946
result:
ok answer is '124534814723946'
Test #16:
score: 0
Accepted
time: 121ms
memory: 14568kb
input:
500000 971792225 794146129 785511712 194135736 44786844 284152939 194083613 817410592 373146814 22622070 711767340 635823706 921756845 722623917 642611556 926642211 92896466 995135854 734765984 941700506 602652059 987869882 834639871 519669444 336528375 96478137 76254564 60733961 164313053 748831540...
output:
124240327455168
result:
ok answer is '124240327455168'
Test #17:
score: 0
Accepted
time: 254ms
memory: 23532kb
input:
1000000 129069570 702294568 125097641 447480588 218836298 281325716 362050097 11943415 717507041 299560656 434156157 308361506 374777194 802395549 673723185 424560671 314086825 759987836 872157780 803022722 656075017 128973367 589636307 233569636 120180505 318294358 777728766 964983779 323489034 471...
output:
249813673995070
result:
ok answer is '249813673995070'
Test #18:
score: 0
Accepted
time: 243ms
memory: 25060kb
input:
1000000 281228710 985743097 719261722 552388573 897858624 645588802 714307780 510125843 246977559 766326585 543396467 190349116 653041693 598473776 903740393 572265166 927057923 343835616 770979563 225720546 217559745 929510118 474780354 824222648 347792658 927985985 890375867 612780336 853283317 19...
output:
249986866979625
result:
ok answer is '249986866979625'
Test #19:
score: 0
Accepted
time: 278ms
memory: 26564kb
input:
1000000 578612043 564158922 18458508 802520750 136689461 450043377 771598167 448499760 221158478 528059809 92828265 512528215 931306192 539776195 573949090 719969661 394804829 632716100 934642563 208226883 484077177 879789973 214700209 709842955 15596299 537677612 297990264 700768381 528301792 33505...
output:
249189618339640
result:
ok answer is '249189618339640'
Test #20:
score: 0
Accepted
time: 366ms
memory: 30520kb
input:
1000000 263709877 249145493 400170549 868915888 960002504 272680394 425758139 683024665 544365499 455242644 229535590 115994789 932297247 13518365 684834337 895852392 202945750 509480961 234126953 296485671 284011673 437262033 105473744 332199902 773743475 411091856 764394619 98779195 374616388 3310...
output:
249839772035172
result:
ok answer is '249839772035172'
Test #21:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
30 499096833 933417495 882103125 787425402 648972887 700946219 839122735 37379635 486445119 773907603 874486646 797822652 717107686 406388292 751203987 283378903 299862157 797984363 883292224 626917047 37657097 1815525 504484877 101245061 932308294 263386821 768674270 511612127 460995775 145889490 1...
output:
6489728870
result:
ok answer is '6489728870'
Test #22:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
200 34354700 862581412 59106770 676268610 653416907 983569753 403068219 792195902 270806575 41006271 692592611 884245279 201896291 582381918 565138036 64485820 4283571 879203200 591051007 906053877 705789716 764558261 766342520 154746153 331191193 309272399 920183863 109834686 613776895 710009063 36...
output:
31837335420
result:
ok answer is '31837335420'
Test #23:
score: 0
Accepted
time: 1ms
memory: 3628kb
input:
1000 268499703 957112864 455900330 100247751 404796282 488787131 505894877 758603162 232359976 974696772 939286817 343845003 213739473 21884711 890858141 963344620 749244311 485404222 838987281 61567940 263295859 176714075 432430926 830176845 20946608 329581250 520460985 432801398 261834350 34105207...
output:
121840338190
result:
ok answer is '121840338190'
Test #24:
score: 0
Accepted
time: 1ms
memory: 3652kb
input:
1000 700543916 173893013 580621135 886721124 484812637 686502044 872697499 731469794 607847992 690178016 646398170 33467773 211272946 784751438 523215447 423995211 383516946 544620997 335599991 267566999 85960564 107995035 827605805 617042784 826857671 661388057 188738435 988060375 17520655 11584281...
output:
126448553496
result:
ok answer is '126448553496'
Test #25:
score: 0
Accepted
time: 46ms
memory: 6116kb
input:
100000 935860805 985130033 782895781 739086796 859970843 504969873 982451813 339193953 830829630 960098998 479744296 32119815 336992875 584329585 21227100 413370515 253619426 879496633 736806966 888735291 778873833 229331239 929308203 742474269 799800137 23697530 170099575 333815481 559003343 660053...
output:
12435736939200
result:
ok answer is '12435736939200'
Test #26:
score: 0
Accepted
time: 49ms
memory: 6528kb
input:
157000 829866708 578710232 578289776 318538299 852913519 750677882 671283794 150002526 202571035 711505399 600531693 723375332 382097903 274922450 440273782 830226754 632134243 635449230 98899400 98846765 607974353 501804853 603503841 446897953 212568315 695165652 255658851 878141405 670359172 19477...
output:
19617637311024
result:
ok answer is '19617637311024'
Test #27:
score: 0
Accepted
time: 79ms
memory: 7956kb
input:
197000 117046507 294174572 130091424 361455370 367089920 175915150 104474173 300684917 324943689 141992180 1303636 455340314 433441682 747082801 558418241 85409130 630572010 154613176 76532966 286208507 725546275 39249761 342927912 676962313 289520982 815485928 655188848 493362160 623950940 54884798...
output:
24898591988536
result:
ok answer is '24898591988536'
Test #28:
score: 0
Accepted
time: 82ms
memory: 8064kb
input:
200000 775306878 714902016 126079769 960020951 847307730 884263017 744011557 571961339 150623360 477036617 557192213 315367538 196273137 457760307 315267149 705658455 873767204 394604142 958681349 911049148 649184041 237392756 509733064 766188582 692100007 936440949 344642549 178125068 220946776 775...
output:
25134733192140
result:
ok answer is '25134733192140'
Test #29:
score: 0
Accepted
time: 86ms
memory: 8792kb
input:
200000 904155963 520185740 644847155 871575325 294374731 94048298 312952828 854807693 991472846 104974095 592796905 250622749 947536108 810893755 13747453 386408887 25867296 584537378 854973132 915808764 723384507 244659758 345117185 987241148 543173984 759549498 371921370 653964927 448507270 511163...
output:
24907953621600
result:
ok answer is '24907953621600'
Test #30:
score: 0
Accepted
time: 90ms
memory: 9176kb
input:
200000 82253775 74881293 974408974 185548232 977618871 747230613 838457259 513295411 555444324 768452128 406841946 620197031 206915751 174102045 598672109 798693990 652148599 732556222 261949854 75254709 578641517 383254139 978007432 113285725 65814089 478334863 201035051 643213356 414742891 2196578...
output:
25142799477915
result:
ok answer is '25142799477915'
Test #31:
score: 0
Accepted
time: 357ms
memory: 23180kb
input:
1000000 216033365 58812309 877175367 80779196 549402777 529469759 154173178 815040512 65512323 390897758 146254891 85816775 467251072 363741329 766596244 888359178 538936884 435698637 304504672 188841814 971643126 792914649 458216623 173404750 732388175 634068432 606065688 141715495 368585599 445602...
output:
125139613420027
result:
ok answer is '125139613420027'
Test #32:
score: 0
Accepted
time: 418ms
memory: 24208kb
input:
1000000 586636667 11587116 944315485 844109983 758939094 607238415 447975208 239224537 172619489 586879836 897455253 484608716 645580748 523789893 600100926 500830499 622594365 312372624 743016562 84017245 886848971 415570966 252504755 214454095 174699652 246216260 410474553 5882273 878853992 331951...
output:
125192010301771
result:
ok answer is '125192010301771'
Test #33:
score: 0
Accepted
time: 480ms
memory: 26320kb
input:
1000000 557665492 416630929 774696033 499934580 485735365 463457259 538178939 833646725 262146556 32943620 341292664 44322607 88780995 627822566 141248141 925800822 695443926 756944430 394180768 661855282 584301029 176725390 754563531 28896142 601565973 50528076 761440221 714010505 440902528 4671876...
output:
125193812703795
result:
ok answer is '125193812703795'
Test #34:
score: 0
Accepted
time: 540ms
memory: 30104kb
input:
1000000 709824633 700079457 368860115 455099462 869790394 972944538 595469325 331829154 381551666 794676845 890724462 71534410 367045495 569124985 666232646 73505318 13447728 635759506 852811063 789585811 145785757 832037950 344740282 914516449 829178127 365252407 169054618 951741654 970696811 33922...
output:
125031054224004
result:
ok answer is '125031054224004'
Test #35:
score: 0
Accepted
time: 578ms
memory: 31896kb
input:
1000000 638806522 60416419 50815061 633635265 883352862 511983780 315562178 117115617 788579311 546122004 518397747 32520231 456445155 887995348 36441406 679433576 836645585 802241224 43080988 487311289 107368821 593165147 706891308 526165494 491040239 861442808 502587760 716629310 388464452 3438683...
output:
124806855869906
result:
ok answer is '124806855869906'
Test #36:
score: 0
Accepted
time: 607ms
memory: 36808kb
input:
1000000 400187744 531044439 513887769 364981404 605276983 675450596 638592035 358203100 826963898 97591752 596101731 818134199 609870691 13542392 920718703 339425740 964864130 677726300 419039984 586439405 770842555 379633233 326511653 916888224 398614150 899750440 828695135 399998881 186140590 1189...
output:
124743304825965
result:
ok answer is '124743304825965'
Test #37:
score: -100
Wrong Answer
time: 0ms
memory: 3800kb
input:
20 11 2 12 1 18 17 8 3 10 13 19 7 6 16 4 15 9 5 14 20 5 8 19 5 14 17 18 14 14 15 16
output:
60
result:
wrong answer expected '54', found '60'