QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#419676 | #7973. 括号 | kkkgjyismine4 | 0 | 91ms | 3980kb | C++14 | 1011b | 2024-05-24 09:04:41 | 2024-05-24 09:04:44 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,q,a[200005],pos,vis[200005];char s[200005];
priority_queue<int,vector<int>,greater<int> >pq;
int calc(){
ll ans=0;
for(int i=1;i<=pos;++i){
if(s[i]==')')pq.push(a[i]);
if(vis[i])ans+=1ll*pq.top(),pq.pop();
}
while(pq.size())pq.pop();
for(int i=(n<<1);i>pos;--i){
if(s[i]=='(')pq.push(a[i]);
if(vis[i])ans+=1ll*pq.top(),pq.pop();
}return ans;
}
int main(){
cin>>n>>q;
for(int i=1;i<=(n<<1);++i)scanf("%d",&a[i]);
scanf("%s",s+1);int sum=0,mn=0;
for(int i=1;i<=(n<<1);++i){
if(s[i]=='(')++sum;else --sum;
if(sum<=mn)pos=i,mn=sum;
}sum=0;
for(int i=1;i<=pos;++i){
if(s[i]=='(')++sum;
else{
if(!sum)vis[i]=1,sum=1;
else --sum;
}
}sum=0;
for(int i=(n<<1);i>pos;--i){
if(s[i]==')')++sum;
else{
if(!sum)vis[i]=1,sum=1;
else --sum;
}
}
printf("%d\n",calc());
while(q--){
int p,x;scanf("%d%d",&p,&x),a[p]=x;
printf("%d\n",calc());
}
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: 1ms
memory: 3824kb
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 1483210458 1483210458 1483210458 1483210458 1483210458 1483210458 1483210458 1483210458 1483210458 1483210458 1483210458 1483210458 1483210458 1483210458 1483210458 1483210458 1483210458 1483210458 1483210458 1483210458 1483210458 1483210458 1483210458 1483210458 1483210458 1483210458 148...
result:
wrong answer 2nd lines differ - expected: '1938040724', found: '1483210458'
Subtask #2:
score: 0
Wrong Answer
Test #5:
score: 0
Wrong Answer
time: 56ms
memory: 3768kb
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:
-1501513352 -2011127485 -2011127485 -2011127485 -2011127485 -2011127485 -2011127485 -2011127485 -2011127485 -2011127485 -2011127485 -2011127485 -2011127485 -2011127485 -2011127485 -2011127485 -2011127485 -2011127485 -2011127485 -2011127485 -2011127485 -2011127485 -2011127485 -1994608285 -1994608285 ...
result:
wrong answer 1st lines differ - expected: '2793453944', found: '-1501513352'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #14:
score: 5
Accepted
time: 91ms
memory: 3980kb
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: 58ms
memory: 3792kb
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: -5
Wrong Answer
time: 54ms
memory: 3784kb
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 123710 123710 123710 123710 123710 123710 123710 123710 123710 123710 123710 123710 123710 123710 123710 123710 123710 123710 123710 123710 123710 123710 123710 123710 123710 123710 123710 123710 123710 123710 123710 123710 123710 123710 123710 123710 123710 123710 123710 123710 123710 123710...
result:
wrong answer 2nd lines differ - expected: '195202', found: '123710'
Subtask #5:
score: 0
Skipped
Dependency #3:
0%
Subtask #6:
score: 0
Skipped
Dependency #5:
0%