QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#419678#7973. 括号kkkgjyismine45 96ms3988kbC++141.0kb2024-05-24 09:06:272024-05-24 09:06:29

Judging History

你现在查看的是最新测评结果

  • [2024-05-24 09:06:29]
  • 评测
  • 测评结果:5
  • 用时:96ms
  • 内存:3988kb
  • [2024-05-24 09:06:27]
  • 提交

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(){
	while(pq.size())pq.pop();
	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: 15
Accepted
time: 1ms
memory: 3948kb

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: 15
Accepted
time: 0ms
memory: 3800kb

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
Wrong Answer
time: 1ms
memory: 3988kb

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:

-868536548
-868536548
-696689509
-696689509
-696689509
-288682569
-288682569
-288682569
-51258665
353415299
353415299
353415299
170838411
72517148
-307173054
-307173054
-307173054
-324924656
-324924656
-324924656
-723886100
-723886100
-723886100
-729691364
-659366963
-891941082
-1176279295
-14505630...

result:

wrong answer 1st lines differ - expected: '16311332636', found: '-868536548'

Subtask #2:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 56ms
memory: 3876kb

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
-1510759336
-1510759336
-1510759336
-1510759336
-1510759336
-1510759336
-1510759336
-1510759336
-1510759336
-1510759336
-1510759336
-1510759336
-1510759336
-1510759336
-1510759336
-1510759336
-1510759336
-1510759336
-1510759336
-1510759336
-1510759336
-1510759336
-1494240136
-1494240136
...

result:

wrong answer 1st lines differ - expected: '2793453944', found: '-1501513352'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 5
Accepted

Test #14:

score: 5
Accepted
time: 96ms
memory: 3836kb

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: 5
Accepted
time: 63ms
memory: 3876kb

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
Accepted
time: 45ms
memory: 3880kb

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
Skipped

Dependency #3:

0%

Subtask #6:

score: 0
Skipped

Dependency #5:

0%