QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#54831 | #2103. Termity | AFewSuns# | AC ✓ | 91ms | 15412kb | C++ | 2.3kb | 2022-10-10 19:21:16 | 2022-10-10 19:21:19 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace my_std{
#define ll long long
#define bl bool
ll my_pow(ll a,ll b,ll mod){
ll res=1;
if(!b) return 1;
while(b){
if(b&1) res=(res*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return res;
}
ll qpow(ll a,ll b){
ll res=1;
if(!b) return 1;
while(b){
if(b&1) res*=a;
a*=a;
b>>=1;
}
return res;
}
#define db double
#define pf printf
#define pc putchar
#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
#define go(u) for(ll i=head[u];i;i=e[i].nxt)
#define enter pc('\n')
#define space pc(' ')
#define fir first
#define sec second
#define MP make_pair
#define il inline
#define inf 8e18
#define random(x) rand()*rand()%(x)
#define inv(a,mod) my_pow((a),(mod-2),(mod))
il ll read(){
ll sum=0,f=1;
char ch=0;
while(!isdigit(ch)){
if(ch=='-') f=-1;
ch=getchar();
}
while(isdigit(ch)){
sum=sum*10+(ch^48);
ch=getchar();
}
return sum*f;
}
il void write(ll x){
if(x<0){
x=-x;
pc('-');
}
if(x>9) write(x/10);
pc(x%10+'0');
}
il void writeln(ll x){
write(x);
enter;
}
il void writesp(ll x){
write(x);
space;
}
}
using namespace my_std;
ll n,a[1000010],b[1000010],cnt=0,st[1000010],top=0,tot=0,sum=0,ans=0;
void solve(ll l,ll r){
if(l>r) return;
top=0;
fr(i,l,r){
st[++top]=a[i];
while(top>2&&st[top-1]>=st[top]&&st[top-1]>=st[top-2]){
top-=2;
st[top]=st[top]+st[top+2]-st[top+1];
}
}
if(l==1){
ll now=1;
while(now<top&&st[now]>=st[now+1]){
if(tot&1) ans+=st[now]-st[now+1];
else ans-=st[now]-st[now+1];
now+=2;
}
fr(i,now,top) b[++cnt]=st[i];
}
else if(r==n){
while(top>1&&st[top]>=st[top-1]){
if(tot&1) ans+=st[top]-st[top-1];
else ans-=st[top]-st[top-1];
top-=2;
}
fr(i,1,top) b[++cnt]=st[i];
}
else{
fr(i,1,top) b[++cnt]=st[i];
}
}
int main(){
n=read();
fr(i,1,n) a[i]=read();
fr(i,1,n){
sum+=a[i];
if(a[i]) tot++;
}
ll lst=0;
fr(i,1,n){
if(!a[i]){
solve(lst+1,i-1);
lst=i;
}
}
solve(lst+1,n);
if(!lst){
write(0);
return 0;
}
sort(b+1,b+cnt+1);
pfr(i,cnt,1){
if((cnt-i)&1) ans-=b[i];
else ans+=b[i];
}
writesp((sum+ans)>>1);
write((sum-ans)>>1);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
input:
1 0
output:
0 0
result:
ok single line: '0 0'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
2 0 17
output:
17 0
result:
ok single line: '17 0'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3556kb
input:
3 0 13 0
output:
13 0
result:
ok single line: '13 0'
Test #4:
score: 0
Accepted
time: 2ms
memory: 3524kb
input:
8 1 2 0 3 7 4 0 9
output:
17 9
result:
ok single line: '17 9'
Test #5:
score: 0
Accepted
time: 2ms
memory: 3692kb
input:
10 0 0 0 1 0 0 0 5 0 0
output:
5 1
result:
ok single line: '5 1'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
24 55 33 93 169 237 0 219 125 39 13 96 166 200 278 0 99 2 18 110 0 58 57 0 42
output:
1125 984
result:
ok single line: '1125 984'
Test #7:
score: 0
Accepted
time: 2ms
memory: 3560kb
input:
17 805750847 0 100661314 433925858 0 84353896 0 0 998898815 548233368 610515435 585990365 374344044 760313751 477171088 356426809 945117277
output:
4023568786 3058134081
result:
ok single line: '4023568786 3058134081'
Test #8:
score: 0
Accepted
time: 2ms
memory: 3596kb
input:
19 0 294702568 726956430 336465783 861021531 278722863 233665124 145174068 468703136 101513930 801979803 315634023 635723059 369133070 0 59961394 89018457 628175012 656478043
output:
2586842805 4416185489
result:
ok single line: '2586842805 4416185489'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3744kb
input:
21 859484422 914544920 608413785 756898538 734575199 0 149798316 38664371 129566414 184803527 412776092 424268981 0 749241874 137806863 42999171 982906997 0 511702306 84420926 937477085
output:
4059679871 4600669916
result:
ok single line: '4059679871 4600669916'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
20 804289384 846930887 681692778 714636916 957747794 424238336 719885387 649760493 596516650 189641422 25202363 0 783368691 102520060 44897764 967513927 365180541 540383427 304089173 303455737
output:
6380056138 3641895592
result:
ok single line: '6380056138 3641895592'
Test #11:
score: 0
Accepted
time: 2ms
memory: 3520kb
input:
67 690 445 620 441 730 32 118 98 772 482 676 710 928 568 857 0 498 354 587 966 307 684 220 625 529 872 733 830 504 0 20 271 369 709 716 341 150 797 724 619 246 847 452 922 556 380 489 0 765 229 842 351 194 501 35 765 125 915 988 857 744 492 228 366 860 937 433
output:
17181 17930
result:
ok single line: '17181 17930'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3668kb
input:
136 991 304 34 364 498 254 893 687 126 153 997 976 189 158 730 437 461 415 922 461 305 29 28 51 749 557 903 795 698 700 44 40 3 429 404 501 682 648 539 160 152 536 135 340 693 216 128 505 630 50 965 286 430 344 336 178 901 239 972 950 290 368 989 293 0 796 744 145 830 391 683 341 542 570 827 233 262...
output:
30192 32764
result:
ok single line: '30192 32764'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3464kb
input:
141 1872 1860 1773 1755 1676 1620 1575 1568 1532 1490 1414 1330 1240 1200 1116 1050 1024 929 839 771 758 685 626 530 431 350 251 188 128 34 73 132 141 177 187 229 316 322 323 336 408 429 484 503 602 623 627 666 677 717 784 789 817 844 894 978 1036 1056 1080 1102 1171 1267 1348 1378 1462 1554 1626 16...
output:
66031 66354
result:
ok single line: '66031 66354'
Test #14:
score: 0
Accepted
time: 2ms
memory: 3596kb
input:
200 814 858 495 182 82 604 721 434 983 182 488 416 297 826 0 723 893 552 298 33 135 0 507 416 58 709 596 1000 963 298 484 0 155 978 310 588 0 383 22 0 564 861 683 212 0 87 286 931 991 0 315 477 117 821 893 526 529 840 526 491 137 361 619 644 0 0 583 622 311 956 889 226 816 0 438 854 9 0 784 351 658 ...
output:
43498 42858
result:
ok single line: '43498 42858'
Test #15:
score: 0
Accepted
time: 2ms
memory: 3596kb
input:
200 912 128 951 237 561 819 106 564 50 245 712 806 935 292 376 956 615 590 769 994 919 806 883 823 983 718 31 94 575 127 594 487 254 544 75 815 714 180 378 763 776 89 920 711 733 295 18 347 236 138 692 154 944 574 0 926 292 711 19 218 837 964 56 91 859 131 905 572 662 634 686 790 74 605 852 806 251 ...
output:
49121 45904
result:
ok single line: '49121 45904'
Test #16:
score: 0
Accepted
time: 2ms
memory: 3668kb
input:
100 0 530498339 873524567 37487771 541027285 232056857 745790418 251300607 959372261 25125850 137100238 126107206 159473060 376035218 282648519 478034946 471990784 353436874 983228459 584710874 993967638 941804290 826620484 45826608 37770479 930772758 647149315 716334472 152645730 470591101 25533460...
output:
24979181322 21081522362
result:
ok single line: '24979181322 21081522362'
Test #17:
score: 0
Accepted
time: 2ms
memory: 3584kb
input:
100 186452552 244316438 971899229 476153276 213975408 139901475 626276122 653468859 130794396 239036030 884661238 605908236 350573794 76065819 605894429 789366144 987231012 875335929 784639530 103318777 597322405 939964444 112255764 432114614 67854539 352118607 782436841 909002905 165344819 39523512...
output:
24240077298 21243698472
result:
ok single line: '24240077298 21243698472'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
474 4427 4367 4269 4210 4181 4151 4146 4098 4013 3920 3840 3766 3740 3687 3646 3628 3532 3435 3402 3377 3315 3258 3185 3113 3026 2949 2866 2850 2832 2825 2751 2749 2718 2650 2648 2619 2527 2515 2448 2437 2371 2296 2215 2159 2155 2112 2079 2060 1977 1901 1850 1812 1743 1699 1610 1591 1532 1508 1466 1...
output:
507770 511012
result:
ok single line: '507770 511012'
Test #19:
score: 0
Accepted
time: 1ms
memory: 3552kb
input:
1000 630 764 101 0 398 417 776 983 545 541 321 827 519 566 0 500 135 547 909 854 63 304 687 0 433 535 808 0 835 0 0 0 985 0 325 383 466 0 717 362 344 38 0 0 603 982 0 89 880 621 942 0 925 629 136 0 163 0 871 0 164 0 0 501 0 488 235 333 291 951 694 634 340 881 495 294 214 855 0 445 476 324 739 752 95...
output:
206486 205459
result:
ok single line: '206486 205459'
Test #20:
score: 0
Accepted
time: 2ms
memory: 3472kb
input:
1000 0 79 197 274 190 853 834 594 775 997 788 98 645 538 781 272 895 235 580 33 415 678 629 124 24 181 525 505 590 488 577 885 918 125 158 108 977 343 53 104 691 841 201 336 378 981 607 272 567 539 657 981 568 637 457 591 169 981 95 759 820 23 995 89 148 504 196 476 198 601 579 889 793 131 224 170 4...
output:
245705 242601
result:
ok single line: '245705 242601'
Test #21:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
1000 164 818 235 340 935 353 550 894 819 443 505 6 905 914 693 303 945 188 5 362 257 102 527 749 328 51 55 940 797 810 446 312 627 681 3 913 33 553 158 204 347 662 561 251 928 253 554 872 441 558 585 49 11 112 149 338 514 555 278 662 364 75 325 343 755 327 255 140 879 765 343 226 778 903 828 705 155...
output:
247371 242089
result:
ok single line: '247371 242089'
Test #22:
score: 0
Accepted
time: 2ms
memory: 3752kb
input:
1000 809908776 832077980 92295432 315859325 770016229 696739072 228756838 48426762 449631210 972740482 240738544 184177382 114060443 379931498 278893609 832106134 865543723 514127926 23421466 143288219 887372904 984078613 693149221 84538076 835707305 954882015 261817690 114928238 131871223 98247531 ...
output:
222855153147 221652607448
result:
ok single line: '222855153147 221652607448'
Test #23:
score: 0
Accepted
time: 2ms
memory: 3608kb
input:
2000 675365724 0 0 247906198 545042418 0 626717775 112718117 234815956 696779466 30245416 377970869 171029950 552604754 354321180 0 373026857 0 644210802 242660716 0 0 189059477 0 0 497905612 0 0 233983203 0 833639404 761865278 0 650076586 9771476 685622012 0 0 798340128 0 0 0 0 0 0 0 130324324 6067...
output:
281582543785 281784474195
result:
ok single line: '281582543785 281784474195'
Test #24:
score: 0
Accepted
time: 1ms
memory: 3544kb
input:
2000 0 735030707 239079909 783122046 0 0 0 596488876 0 44805129 581296003 682679471 457384565 0 707321101 74961687 0 0 627423305 349672636 821281469 0 130812281 126497923 0 0 0 646927302 0 0 555501256 0 0 0 0 0 0 291248360 0 0 188569840 0 367651185 0 0 927488637 0 117165684 643465975 0 319354672 317...
output:
281704826998 280699038290
result:
ok single line: '281704826998 280699038290'
Test #25:
score: 0
Accepted
time: 67ms
memory: 15412kb
input:
1000000 201586286 0 416430488 0 978137396 0 789522972 0 236793095 0 710795253 0 262917289 0 556681937 0 860227851 0 556210053 0 514135834 0 360739836 0 594048446 0 199332799 0 747011474 0 636503898 0 774599077 0 899255998 0 555366032 0 812445254 0 144600126 0 929101428 0 989865586 0 109775039 0 4268...
output:
117639050447030 117638549281772
result:
ok single line: '117639050447030 117638549281772'
Test #26:
score: 0
Accepted
time: 38ms
memory: 11364kb
input:
1000000 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 100000...
output:
500000000000000 499999
result:
ok single line: '500000000000000 499999'
Test #27:
score: 0
Accepted
time: 91ms
memory: 11872kb
input:
1000000 713115457 408187027 969481833 589156845 755100257 411636174 226349521 10719046 638450035 902574022 661331871 830343004 500885925 152194128 964166887 180108577 595807806 775037932 5292949 910291148 573143120 546733139 664293647 937673570 170669250 907548006 47400411 328063029 826984298 929042...
output:
233013683820657 233022939318001
result:
ok single line: '233013683820657 233022939318001'
Test #28:
score: 0
Accepted
time: 32ms
memory: 11468kb
input:
1000000 811015121 382728104 20091485 989199233 9396401 17362763 81608748 94033484 321901901 319796228 139108590 707552323 212932029 464540077 344105643 708090211 820312757 567508612 742828516 330786018 834767819 616301450 150950231 111996022 690173662 262941572 638711487 897678935 410431249 37146567...
output:
235173412664470 235197598443273
result:
ok single line: '235173412664470 235197598443273'
Test #29:
score: 0
Accepted
time: 58ms
memory: 11556kb
input:
1000000 248854431 804708287 378708443 171793522 127623522 980595599 796955393 218170327 528950933 394114582 157737036 34575819 647761444 863999145 15491159 181265671 890996999 278164608 372816728 956962045 353785545 820841106 103918487 960034308 25563383 891339990 401068717 37063052 740691798 212666...
output:
235309085530688 235242602763974
result:
ok single line: '235309085530688 235242602763974'