QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#116358 | #5094. 小 H 分糖果 | lgvc# | 10 | 2ms | 7900kb | C++23 | 2.5kb | 2023-06-28 16:04:38 | 2023-06-28 16:04:41 |
Judging History
answer
//这回只花了114514min就打完了。
//真好。记得多手造几组。
#include <bits/stdc++.h>
#define int long long
#define pai 3.141592653589793238462643383279502884197169399375105820
#define MOD 1000000007
#define eps 0.00000001
inline int min(int a,int b) {return a<b?a:b;}
inline int max(int a,int b) {return a>b?a:b;}
#define ULL unsigned long long
#define LL long long
#define INF 0x3f3f3f3f
#define INF_LL 0x3f3f3f3f3f3f3f3f
static char buf[1000000],*paa=buf,*pd=buf;
static char buf2[1000000],*pp=buf2;
#define getchar() paa==pd&&(pd=(paa=buf)+fread(buf,1,1000000,stdin),paa==pd)?EOF:*paa++
inline void pc(char ch){
if(pp-buf2==1000000) fwrite(buf2,1,1000000,stdout),pp=buf2;
*pp++=ch;
}
inline void pcc(){
fwrite(buf2,1,pp-buf2,stdout);
pp=buf2;
}
inline int read(void) {
int w=1;
register int x(0);register char c(getchar());
while(c<'0'||c>'9') {if(c=='-') w=-1;c=getchar();}
while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return w*x;
}
void write(int x) {
if(x<0) pc('-'),x=-x;
static int sta[20];
int top=0;
do {
sta[top++]=x%10,x/=10;
} while(x);
while(top) pc(sta[--top]+48);
}
void we(int x) {
write(x);
pc('\n');
}
inline bool cmp_xi(int a,int b) {return a<b;}
inline bool cmp_da(int a,int b) {return a>b;}
int N,Q,su,hd[100009],pa[100009],dep[100009],a[100009],nxt[200009],to[200009],k,b[100009];
inline void l(int u,int v) {nxt[++k]=hd[u],to[k]=v,hd[u]=k;}
void dfs(int n,int f) {
pa[n]=f;dep[n]=dep[f]+1;
for(int i=hd[n];i;i=nxt[i]) {
if(to[i]==f) continue;
dfs(to[i],n);
}
}
signed main(void) {
//freopen("m.in","r",stdin);
//freopen("m.out","w",stdout);
N=read();Q=read();
for(int i=1;i<N;i++) {
int u=read(),v=read();
l(u,v),l(v,u);
}
dfs(1,0);
for(int i=1;i<=N;i++) a[i]=read(),su+=a[i]*a[i];
while(Q--) {
int op=read();
if(op==1) {
int x=read(),v=read();
su-=a[x]*a[x];
su+=v*v;
a[x]=v;
} else {
int m=read(),n=read(),v=read(),k=0;
while(m!=n) {
if(dep[m]<dep[n]) std::swap(m,n);
b[++k]=a[m];
m=pa[m];
}
b[++k]=a[m];
int qq=su;
for(int i=1;i<=k;i++) qq-=b[i]*b[i];
int l=0,r=INF,md;
while(l<r) {
md=(l+r)>>1;
int as=0;
for(int i=1;i<=k;i++) {
if(b[i]>=md) as+=b[i]-md;
}
if(as<=v) r=md;else l=md+1;
}
if(l==0) {
printf("%lld\n",qq);
continue;
}
int as=0,aq=0;
for(int i=1;i<=k;i++) {
if(b[i]>=l) as+=b[i]-l,aq+=l*l;else aq+=b[i]*b[i];
}
printf("%lld\n",aq-(v-as)*(2*l-1)+qq);
}
}
return 0;
}
详细
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 1ms
memory: 7900kb
input:
866 841 1 864 4 153 9 559 10 410 11 336 12 417 14 666 18 241 21 184 22 849 23 40 25 783 26 189 28 329 29 216 31 864 34 581 40 131 42 625 45 744 47 723 50 633 51 447 52 454 53 88 55 619 60 259 62 680 67 126 72 371 73 742 80 196 81 536 82 647 85 254 87 172 88 489 93 708 94 227 95 340 96 7 7 91 97 594 ...
output:
285125508 285374449 285871392 285072359 284419704 284843737 284692039 284936099 285944374 285174668 285019779 284651455 287282253 287175619 284878507 285369672 284880507 285404741 284913527 286053317 288622563 286960150 287194443 288326074 286937403 287883097 288535226 288195055 288643208 288632989 ...
result:
ok 419 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 7692kb
input:
951 896 6 886 8 809 9 392 12 590 13 643 16 322 17 613 37 605 42 354 44 594 47 905 49 623 53 240 56 546 58 751 60 919 62 74 63 303 64 105 68 578 69 41 41 110 71 402 74 528 75 616 76 83 77 230 83 289 84 354 88 340 89 65 91 785 92 831 93 286 96 101 97 841 99 556 100 700 101 574 102 652 103 534 105 107 ...
output:
323762325 323477550 323340853 323950611 323726768 322803839 322828150 323927499 323452292 322435378 323945420 323767611 322557229 323137116 322736140 322900873 322078759 322286746 322383436 322825503 321513631 320299707 320738958 320752861 319979668 320430841 319960294 319658294 317899682 318822085 ...
result:
ok 443 lines
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #3:
score: 0
Wrong Answer
time: 2ms
memory: 7712kb
input:
903 809 2 4 5 604 6 396 10 637 12 593 22 855 26 586 29 170 34 64 37 559 42 413 44 789 46 584 49 83 52 642 55 688 59 899 61 614 68 572 74 707 79 278 80 32 83 315 86 779 87 323 89 901 91 720 92 463 93 592 98 348 99 644 100 465 102 377 103 835 104 479 107 757 111 207 112 458 116 43 43 623 121 538 124 1...
output:
103902478522974282 -2826929753687814296 716063541255406145 -174808375049721290 -603188831837580581 299465326125192708 -1341119657373865854 854110714688013875 -1673770605080614149 -1341164599893104546 -2712481467066822022 751606926746490546 3016182845548359759 643200052420414317 -404326210148257208 -...
result:
wrong answer 1st lines differ - expected: '276805063584166248522', found: '103902478522974282'
Subtask #3:
score: 0
Time Limit Exceeded
Test #6:
score: 0
Time Limit Exceeded
input:
87080 98363 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 52...
output:
8517265276512564616 -4711117430166474150 6738441719794742341 -5787008674628346905 -8347135657805738539 -4759199759503207078 -8546080435213919398 8694456326443808770 8128348316596409754 -7888309531780523147 -7406422080607190301 7478044765537627738 6737041363265155939 -4704778091396264234 802616912979...
result:
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%