QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#382289 | #2070. Heavy Stones | chenxinyang2006 | RE | 529ms | 106268kb | C++14 | 3.8kb | 2024-04-08 11:09:52 | 2024-04-08 11:09:52 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define SZ(S) (int)S.size()
//#define mod 998244353
//#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;
template <class T>
void chkmax(T &x,T y){
if(x < y) x = y;
}
template <class T>
void chkmin(T &x,T y){
if(x > y) x = y;
}
inline int popcnt(int x){
return __builtin_popcount(x);
}
inline int ctz(int x){
return __builtin_ctz(x);
}
/*ll power(ll p,int k = mod - 2){
ll ans = 1;
while(k){
if(k % 2 == 1) ans = ans * p % mod;
p = p * p % mod;
k /= 2;
}
return ans;
}*/
int n,m;
int a[200005];
pll P[800005];
ll ssum;
bool cmp(pll s,pll t){//s 放在前面,好吗
return s.second * t.first >= t.second * s.first;
}
vector <int> SS[200005][2];
vector <int> sta;
ll ans;
ll _ans[200005][2];
void emplace(int i,int op){
P[++m] = mkp(a[i],1);
sta.eb(m);
SS[i][op].eb(m);
int px,py;
while(SZ(sta) >= 2 && cmp(P[sta[SZ(sta) - 2]],P[sta.back()])){
py = sta.back();
sta.pop_back();
px = sta.back();
sta.pop_back();
ans += P[py].second * P[px].first;
P[++m] = mkp(P[px].first + P[py].first,P[px].second + P[py].second);
sta.eb(m);
SS[i][op].eb(-px);SS[i][op].eb(-py);SS[i][op].eb(m);
}
}
int ord[800005],rk[800005];
bool cmp2(int x,int y){
return cmp(P[x],P[y]);
}
struct node{
ll ans,sums,suma;
}tree[3200005];
#define ls (rt * 2)
#define rs (rt * 2 + 1)
int b[800005];
void pushup(int rt){
tree[rt].ans = tree[ls].ans + tree[rs].ans + tree[ls].sums * tree[rs].suma;
tree[rt].sums = tree[ls].sums + tree[rs].sums;
tree[rt].suma = tree[ls].suma + tree[rs].suma;
}
void build(int rt,int l,int r){
if(l == r){
if(!b[ord[l]]){
tree[rt].sums = tree[rt].suma = 0;
}else{
tree[rt].sums = P[ord[l]].second;
tree[rt].suma = P[ord[l]].first;
}
return;
}
int mid = (l + r) >> 1;
build(ls,l,mid);build(rs,mid+1,r);
pushup(rt);
}
void modify(int rt,int l,int r,int pos){
if(l == r){
if(!b[ord[l]]){
tree[rt].sums = tree[rt].suma = 0;
}else{
tree[rt].sums = P[ord[l]].second;
tree[rt].suma = P[ord[l]].first;
}
return;
}
int mid = (l + r) >> 1;
if(pos <= mid) modify(ls,l,mid,pos);
else modify(rs,mid+1,r,pos);
pushup(rt);
}
int main(){
// freopen("test.in","r",stdin);
scanf("%d",&n);
rep(i,1,n){
scanf("%d",&a[i]);
ssum += a[i];
}
rep(i,1,n){
emplace(i,0);
_ans[i][0] = ans;
}
ans = 0;
sta.clear();
per(i,n,2){
emplace(i,1);
_ans[i][1] = ans;
}
/* rep(i,1,m) printf("pair %d (%lld,%lld)\n",i,P[i].first,P[i].second);
printf("\n");
printf("Left to Right:\n");
rep(i,1,n){
printf("i=%d:",i);
for(int id:SS[i][0]) printf("%d ",id);
printf("\n");
}
printf("Right to Left:\n");
per(i,n,1){
printf("i=%d:",i);
for(int id:SS[i][1]) printf("%d ",id);
printf("\n");
}*/
rep(i,1,m) ord[i] = i;
sort(ord + 1,ord + m + 1,cmp2);
rep(i,1,m) rk[ord[i]] = i;
for(int id:sta) b[id] = 1;
build(1,1,m);
rep(k,1,n){
printf("%lld ",ssum * (n - 1) - _ans[k - 1][0] - _ans[k + 1][1] - tree[1].ans);
for(int id:SS[k][0]){
if(id < 0){
b[-id] = 0;
modify(1,1,m,rk[-id]);
}else{
b[id] = 1;
modify(1,1,m,rk[id]);
}
}
reverse(SS[k + 1][1].begin(),SS[k + 1][1].end());
for(int id:SS[k + 1][1]){
if(id < 0){
b[-id] = 1;
modify(1,1,m,rk[-id]);
}else{
b[id] = 0;
modify(1,1,m,rk[id]);
}
}
// printf("k=%d\n",k);
// rep(i,1,m) printf("%d",b[i]);
// printf("\n");
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 24356kb
input:
5 2 1 3 5 4
output:
35 35 36 43 49
result:
ok single line: '35 35 36 43 49 '
Test #2:
score: 0
Accepted
time: 0ms
memory: 24356kb
input:
10 18 37 81 6 58 99 87 34 75 9
output:
2637 2637 2657 2657 2695 2949 2995 2905 2880 2880
result:
ok single line: '2637 2637 2657 2657 2695 2949 2995 2905 2880 2880 '
Test #3:
score: 0
Accepted
time: 496ms
memory: 104228kb
input:
200000 479735 430060 863649 878892 889364 241972 927862 32858 714406 674598 88114 438434 167733 457299 951288 510096 635193 504974 649221 617914 223711 812277 364169 746142 836563 825312 994240 198961 567906 905208 509572 744710 891294 928176 833980 985385 858440 50835 86130 324862 796245 935992 383...
output:
9992833979971052 9992833979971052 9992833980354966 9992779245594768 9992703452732543 9992625566170070 9992625565960956 9992591568400874 9992591568400874 9992591568189384 9992591567396390 9992591567396390 9992591567476009 9992591567864059 9992591571455644 9992591572452874 9992591574009688 99925915745...
result:
ok single line: '9992833979971052 9992833979971...203005830427 10004203006781811 '
Test #4:
score: 0
Accepted
time: 529ms
memory: 104244kb
input:
200000 754184 13065 865956 768626 744822 919059 583237 600724 524170 165425 246285 226816 966566 610515 550388 715978 549675 83917 323652 423422 266395 285394 470160 472551 743112 879255 493014 992502 158286 301973 857254 395231 282559 806597 243952 205846 976027 598783 69632 165916 622634 620757 34...
output:
10014997841701475 10014947015238274 10014947015238274 10014947015993835 10014917512559448 10014868558588544 10014784759644306 10014768120716895 10014747984710856 10014743158715252 10014743158715252 10014743158776643 10014743160298065 10014743161445632 10014743159820460 10014743158450587 100147431338...
result:
ok single line: '10014997841701475 100149470152...7021303093862 9987021303093862 '
Test #5:
score: 0
Accepted
time: 499ms
memory: 104252kb
input:
200000 783905 465734 702646 342070 382378 612468 565748 741917 648664 523500 182013 89445 129572 26912 175340 537820 717500 718402 563606 124584 111640 830294 957543 449869 563613 901195 496363 918492 226878 429682 770972 654243 222706 539682 471463 654386 31958 381760 352938 783523 851106 354268 75...
output:
9985525267421517 9985468293020605 9985468291830972 9985434229308153 9985434229308153 9985434229224741 9985434226842360 9985434224335794 9985404337013738 9985374417560553 9985369520866620 9985369520652405 9985369520589872 9985369520589872 9985369520721535 9985369522444873 9985369525429091 99853695285...
result:
ok single line: '9985525267421517 9985468293020...5790145914810 9975830720773589 '
Test #6:
score: 0
Accepted
time: 515ms
memory: 104320kb
input:
200000 853686 20716 174697 869738 857025 507882 375300 849975 893238 468077 184722 535631 383301 657603 49942 235054 316530 521594 464021 979922 188332 335907 114903 261684 434608 966750 619976 793830 275183 498775 690216 769588 589049 958997 995520 845297 350658 198715 707600 18882 203867 132974 16...
output:
10007482900924066 10007412205735064 10007412205735064 10007412206584086 10007412208102723 10007412205041250 10007412203774418 10007412203774418 10007381409966150 10007302822767145 10007302821693099 10007302821693099 10007302821528524 10007302820980147 10007302819330353 10007302819330353 100073028195...
result:
ok single line: '10007482900924066 100074122057...782048899392 10000853953946590 '
Test #7:
score: 0
Accepted
time: 520ms
memory: 106268kb
input:
200000 282721 513944 210659 728001 402993 628298 260323 376301 404417 439890 298253 575700 991264 735782 387209 874869 995018 778731 247456 286146 598879 216939 91609 177310 82415 36330 265803 953105 564707 201163 357501 390048 142474 266916 46616 539260 570794 792662 270237 67158 511870 166602 9035...
output:
10008509175990736 10008509175918674 10008509175918674 10008509176578011 10008509171139661 10008509170903880 10008509157826476 10008509157826476 10008509157970570 10008509158067444 10008509158067444 10008509158889313 10008509162066449 10008509131249736 10008509108213966 10008509107556161 100084882028...
result:
ok single line: '10008509175990736 100085091759...908130262195 10006908130262195 '
Test #8:
score: 0
Accepted
time: 283ms
memory: 101044kb
input:
200000 22 25 28 34 59 61 68 80 108 116 119 121 121 123 131 131 141 143 152 166 167 174 184 215 228 231 264 279 307 309 313 314 327 339 341 362 381 399 414 421 430 449 477 486 490 500 502 508 529 529 562 566 569 571 585 597 641 650 658 675 680 684 698 721 723 724 731 732 737 755 784 785 810 813 817 8...
output:
10003490282328154 10003490282328154 10003490282328160 10003490282328181 10003490282328283 10003490282328418 10003490282328590 10003490282328841 10003490282329300 10003490282329851 10003490282330437 10003490282331046 10003490282331657 10003490282332292 10003490282333033 10003490282333782 100034902823...
result:
ok single line: '10003490282328154 100034902823...436775206431 10023436775206431 '
Test #9:
score: 0
Accepted
time: 299ms
memory: 104264kb
input:
200000 38 11 44 65 78 56 92 134 177 153 183 211 163 119 196 219 225 251 246 221 279 286 262 297 287 223 312 209 333 354 332 350 310 368 317 419 405 426 426 433 399 446 454 452 460 435 489 376 508 475 510 463 493 518 544 524 520 568 580 572 564 580 541 595 469 607 644 652 606 681 669 632 700 682 709 ...
output:
9998421200211521 9998421200211521 9998421200211527 9998421200211608 9998421200211749 9998421200211815 9998421200212039 9998421200212551 9998421200213406 9998421200214112 9998421200215064 9998421200216326 9998421200217088 9998421200217274 9998421200218417 9998421200219959 9998421200221614 99984212002...
result:
ok single line: '9998421200211521 9998421200211...237707981667 10024237707982278 '
Test #10:
score: -100
Runtime Error
input:
200000 27 7 48 45 53 47 79 72 25 93 99 140 55 141 75 129 147 205 239 210 259 194 272 277 213 350 369 102 210 35 410 376 387 277 109 341 488 480 515 428 536 536 496 551 70 498 569 611 598 563 299 590 630 425 620 659 562 659 614 682 679 648 522 680 667 795 675 764 709 819 808 597 698 651 828 845 859 7...