QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#382663 | #7973. 括号 | valeriu# | 40 | 82ms | 7912kb | C++20 | 1.6kb | 2024-04-08 17:33:41 | 2024-07-04 03:33:48 |
Judging History
answer
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using ld = long double;
#define int ll
#define sz(x) ((int)(x).size())
using pii = pair<int,int>;
using tii = tuple<int,int,int>;
ll mk_query(vector<int> v, string s) {
int n = sz(v) - 1;
auto cmp = [&](int a, int b) { return v[a] > v[b]; };
priority_queue<int, vector<int>, decltype(cmp)> heap(cmp);
int cnt = 0;
ll total = 0;
for(int i = 1; i < sz(s); i++) {
if(s[i] == '(') cnt++;
else cnt--, heap.emplace(i);
if(cnt < 0) {
cnt += 2;
int t = heap.top();
heap.pop();
s[t] ^= '(' ^ ')';
total += v[t];
}
}
while(!heap.empty()) heap.pop();
cnt = 0;
for(int i = n; i > 0; i--) {
if(s[i] == ')') cnt++;
else cnt--, heap.emplace(i);
if(cnt < 0) {
cnt += 2;
int t = heap.top();
heap.pop();
s[t] ^= '(' ^ ')';
total += v[t];
}
}
//cerr << s << '\n';
return total;
}
signed main() {
cin.tie(0) -> sync_with_stdio(0);
int n, q;
cin >> n >> q;
n *= 2;
vector<int> v(n + 1);
for(auto &x : v | views::drop(1)) cin >> x;
string s;
cin >> s;
s = "$" + s;
int ans = mk_query(v, s);
cout << ans << '\n';
for(int i = 0, p, x; i < q; i++) {
cin >> p >> x;
if(v[p] == x);
else v[p] = x, ans = mk_query(v, s);
cout << ans << '\n';
}
}
/**
Anul asta nu se da centroid
-- Rugaciunile mele
*/
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 15
Accepted
Test #1:
score: 15
Accepted
time: 1ms
memory: 3768kb
input:
100 100 655884441 790777510 663667368 332762945 67681448 458058488 445481314 200508190 812326927 374891900 320371513 765529851 490260632 588113266 286392696 888016940 214376080 894477437 944447014 386015667 956960774 692332579 606560669 561835357 887377361 130572961 550186106 193341110 4130416 66982...
output:
1883520337 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 193...
result:
ok 101 lines
Test #2:
score: 0
Accepted
time: 1ms
memory: 3832kb
input:
100 100 833141622 854468469 367770104 350280219 461621010 985561079 287746098 833893180 365597420 618761946 416883128 838478689 419500348 996463737 903782689 176582886 101963967 728502271 222282338 808921916 744579730 171837013 508527221 141613052 233501822 501818380 143462266 206528940 451714614 68...
output:
140782913 140782913 140782913 140782913 140782913 140782913 140782913 140782913 140782913 140782913 140782913 140782913 140782913 140782913 140782913 140782913 140782913 140782913 140782913 140782913 140782913 140782913 140782913 140782913 140782913 140782913 140782913 140782913 140782913 140782913 ...
result:
ok 101 lines
Test #3:
score: 0
Accepted
time: 1ms
memory: 3824kb
input:
100 100 897203289 398741091 737994838 918141180 881683740 708870393 569981059 825462339 575892019 654430241 400748227 892258264 55868417 318639212 157441109 208939722 240809609 552556736 89466637 625250145 859111121 925840769 588412874 550260548 581965340 250456136 598142176 155996841 785774919 7347...
output:
16311332636 16311332636 16483179675 16483179675 16483179675 16891186615 16891186615 16891186615 17128610519 17533284483 17533284483 17533284483 17350707595 17252386332 16872696130 16872696130 16872696130 16854944528 16854944528 16854944528 16455983084 16455983084 16455983084 16450177820 16520502221 ...
result:
ok 101 lines
Test #4:
score: 0
Accepted
time: 1ms
memory: 3540kb
input:
100 100 779493178 536060978 737064866 935658454 907027082 236372983 485874770 753814620 129162512 898300287 907325259 965207103 690140842 432022392 406234882 497505669 791961008 755177790 662269254 416752612 983166566 478974131 490379426 835070952 928089802 548072627 191418336 832748183 896922627 38...
output:
10068455511 10068455511 9859559743 9859559743 9832855564 9869366615 9869366615 9869366615 9869366615 9869366615 9869366615 10090141889 10090141889 10090141889 10090141889 10090141889 9921505636 9921505636 9921505636 9921505636 10012459628 10312147623 10678895964 10678895964 10678895964 10621969654 1...
result:
ok 101 lines
Subtask #2:
score: 10
Accepted
Test #5:
score: 10
Accepted
time: 38ms
memory: 3656kb
input:
1000 1000 851064227 277152131 421722407 126468670 510326499 619107836 287335428 653386549 173788833 304176934 21753544 293653999 493165671 887566717 813114839 976556173 459946448 939807420 605205411 920860669 545229689 895277168 777349694 126341157 564711820 892644312 314220085 125767094 816813109 9...
output:
2793453944 2784207960 2784207960 2784207960 2784207960 2784207960 2784207960 2784207960 2784207960 2784207960 2784207960 2784207960 2784207960 2784207960 2784207960 2784207960 2784207960 2784207960 2784207960 2784207960 2784207960 2784207960 2784207960 2800727160 2800727160 2800727160 2800727160 280...
result:
ok 1001 lines
Test #6:
score: 0
Accepted
time: 40ms
memory: 3596kb
input:
1000 1000 28321407 414472019 420792436 143985944 535669841 441577718 424567503 950335050 22026618 548046980 528330577 366602837 496034315 949896 61908611 265122119 642501627 142428473 178008027 417395845 669285134 784847019 974283538 706118853 910836282 895293511 612528954 138954924 632993525 257003...
output:
596032630 596032630 596032630 596032630 596032630 596032630 596032630 596032630 596032630 596032630 596032630 596032630 596032630 596032630 596032630 596032630 596032630 596032630 617635185 617635185 617635185 617635185 617635185 617635185 617635185 617635185 617635185 617635185 617635185 617635185 ...
result:
ok 1001 lines
Test #7:
score: 0
Accepted
time: 39ms
memory: 3612kb
input:
1000 1000 910611297 551791906 756298953 161503217 929609402 969080309 971864996 583720039 575297111 791917027 329874901 144584384 793870252 482929295 679298604 258720774 193653026 976453308 750810644 840302093 88307871 337980381 876250090 990929257 256960743 561506222 910837823 815706266 375545013 5...
output:
1302828551 1302828551 1302828551 1302828551 1302828551 1302828551 1302828551 1302828551 1302828551 1302828551 1302828551 1302828551 1302828551 1302828551 1302828551 1302828551 1302828551 1302828551 1302828551 1302828551 1302828551 1302828551 1302828551 1302828551 1302828551 1302828551 1302828551 130...
result:
ok 1001 lines
Test #8:
score: 0
Accepted
time: 39ms
memory: 3660kb
input:
1000 1000 87868477 984079086 755368982 252649419 323548963 160146410 182725998 807039612 423534896 35787072 836451933 217533223 91706187 596312474 928092377 915882941 81240913 884107071 618580552 336837269 580959536 891113744 778216643 570706952 308117913 227718932 504113983 123861387 781660014 5843...
output:
339639846 339639846 339639846 339639846 339639846 339639846 339639846 339639846 339639846 339639846 339639846 339639846 339639846 339639846 339639846 339639846 339639846 339639846 339639846 339639846 339639846 339639846 339639846 339639846 339639846 339639846 339639846 339639846 339639846 339639846 ...
result:
ok 1001 lines
Test #9:
score: 0
Accepted
time: 40ms
memory: 3892kb
input:
1000 1000 265125658 121398972 90875499 270166692 643859596 687649001 24990781 440424601 271772680 279657118 637996257 331951258 389542123 373259164 545482370 204448887 337425021 718131905 191383168 128339737 999982274 444247105 311586975 224113575 654242375 893931643 802422853 432016509 524211502 60...
output:
687885921 687885921 687885921 687885921 687885921 687885921 687885921 687885921 687885921 687885921 687885921 687885921 687885921 687885921 687885921 687885921 687885921 687885921 687885921 687885921 687885921 687885921 687885921 687885921 687885921 687885921 687885921 687885921 687885921 687885921 ...
result:
ok 1001 lines
Test #10:
score: 0
Accepted
time: 42ms
memory: 3684kb
input:
1000 1000 548128056 441225402 761967190 564609899 852880563 823157429 641141746 629787151 616668574 577066803 69836786 93676479 203431404 509933456 650720812 174452863 871545396 214373078 621114769 241640835 986559596 851553632 190250091 622066605 2568901 853815524 574972830 136093266 533513533 1474...
output:
1883343838 1883343838 1883343838 1883343838 1883343838 1883343838 1883343838 1883343838 1883343838 1883343838 1883343838 1883343838 1883343838 1883343838 1883343838 1883343838 1883343838 1883343838 1883343838 1883343838 1883343838 1883343838 1883343838 1883343838 1883343838 1883343838 1883343838 188...
result:
ok 1001 lines
Subtask #3:
score: 10
Accepted
Dependency #2:
100%
Accepted
Test #11:
score: 10
Accepted
time: 47ms
memory: 3588kb
input:
1000 1000 255328503 8749818 864612982 273251865 49873999 72997339 857189970 713151172 304609682 819579103 564316097 313244962 955684020 927830088 767752086 348501243 446193423 51111663 744514329 376292040 427141806 81187456 599688623 116201038 349800454 334494169 95780428 724155984 638745426 5484300...
output:
188003528703 187655937319 187655937319 187655937319 187720370511 187720370511 187658487385 187658487385 187658487385 187795287953 187556895895 187556895895 187233316714 187233316714 187223220869 187627933190 187958903710 188111867751 188084409094 188084409094 187805444467 187771142712 187726450094 1...
result:
ok 1001 lines
Test #12:
score: 0
Accepted
time: 46ms
memory: 3652kb
input:
1000 1000 137618392 146069706 863683011 290769139 443813561 600499930 773083682 936470745 152847466 727012660 70893128 91226508 253519955 41213266 385142078 637067190 997344822 958765426 612284237 167794508 214760763 265724599 206687884 401011442 695924916 706879 394089297 32311105 381296914 5646084...
output:
178516266142 178907517987 178926206974 178859597513 178885816932 179255352193 179629623267 179856129630 179778601224 180076794079 180076794079 180308239822 179878708280 179489992850 179145373619 179145373619 179075144850 179427630824 179427630824 179417736169 179491008797 179491008797 179491008797 1...
result:
ok 1001 lines
Test #13:
score: 0
Accepted
time: 39ms
memory: 3532kb
input:
1000 1000 784932307 779556137 727017545 322194428 297506806 774261420 536532316 414843994 866414636 308676941 105873538 17555703 801971920 882242725 134294569 408746924 861436082 790076510 929457202 952584728 317256734 142357499 896149749 771465108 745974995 893922853 469899436 429154851 793327730 4...
output:
1034742159 1034742159 935708547 935708547 935708547 935708547 935708547 935708547 935708547 935708547 935708547 935708547 935708547 935708547 935708547 935708547 935708547 935708547 935708547 935708547 935708547 935708547 935708547 935708547 935708547 935708547 935708547 935708547 935708547 93570854...
result:
ok 1001 lines
Subtask #4:
score: 5
Accepted
Test #14:
score: 5
Accepted
time: 82ms
memory: 3652kb
input:
1000 1000 49658 21707 94558 56676 18487 74906 55206 78654 54538 14591 105694 138 3148 106151 90191 67461 90337 86524 39272 78899 111590 3181 67245 47146 1958 34378 6544 74125 93643 44483 2159 16309 41619 24332 1519 85340 25811 55827 51528 89913 71355 103446 97370 44299 107887 105014 44419 62592 1965...
output:
13395019 13351991 13351991 13351991 13351991 13351991 13351991 13351991 13351991 13381782 13345375 13349826 13338684 13322461 13322461 13322461 13322461 13322461 13306716 13289968 13289968 13289968 13290694 13282032 13302932 13286589 13317058 13317058 13360189 13360189 13360189 13360189 13390898 133...
result:
ok 1001 lines
Test #15:
score: 0
Accepted
time: 41ms
memory: 3548kb
input:
1000 1000 48741 78915 65982 52179 49201 75885 71026 47007 75592 105723 58292 60053 94233 34736 3710 50633 88449 99895 6144 61740 40074 112109 81809 59449 27344 83326 27661 35015 77525 23183 80535 33235 2240 78293 2764 106350 97971 96527 35415 39791 85893 54169 7133 70924 78499 65993 50156 97046 1068...
output:
681032 681032 681032 681032 681032 681032 681032 681032 681032 681032 681032 681032 681032 681032 681032 681032 681032 681032 681032 681032 681032 681032 681032 682276 682276 682276 682276 682276 679002 679002 679002 679002 679002 679002 679002 679002 679002 679002 679002 679002 679002 679002 679002...
result:
ok 1001 lines
Test #16:
score: 0
Accepted
time: 39ms
memory: 3672kb
input:
1000 1000 76312 85088 66287 101457 27652 113578 8522 27466 987 58477 35566 78626 108889 44590 16599 47446 67053 39487 52617 87121 78483 19460 4800 15209 108770 6107 94056 36407 4650 86935 13645 2732 4654 88828 32502 62313 15892 31506 81748 52589 103711 76765 98121 40569 110053 46753 8316 22781 54642...
output:
195202 195202 195202 195202 195202 195202 195202 195202 195202 195202 195202 195202 195202 195202 195202 195202 195202 195202 195202 195202 195202 195202 195202 195202 195202 195202 195202 195202 195202 195202 195202 195202 195202 195202 195202 195202 195202 195202 195202 195202 195202 195202 195202...
result:
ok 1001 lines
Subtask #5:
score: 0
Time Limit Exceeded
Dependency #3:
100%
Accepted
Test #17:
score: 25
Accepted
time: 23ms
memory: 7912kb
input:
100000 100000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 31689 ...
result:
ok 100001 lines
Test #18:
score: 0
Accepted
time: 29ms
memory: 7708kb
input:
100000 100000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 62183 ...
result:
ok 100001 lines
Test #19:
score: -25
Time Limit Exceeded
input:
100000 100000 459157508 412983858 974524549 704224673 583575161 380576439 580690108 81789954 596804726 278451883 849516784 891112612 822916555 560785021 663753156 851844277 904601193 998474001 719278072 204328737 250272364 988004490 976753386 490194153 527198204 909233886 837278938 985110836 3560328...
output:
result:
Subtask #6:
score: 0
Skipped
Dependency #5:
0%