QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#65490 | #5094. 小 H 分糖果 | skin_to | 0 | 0ms | 5964kb | C++14 | 1.1kb | 2022-12-01 12:37:04 | 2023-10-04 02:48:11 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int _=1e5+7;
int s[_],top,n,q,val[_],op,u,b,v,m,sum,fl;
vector<int>g[_];
void dfs(int x,int fa,int t){
s[++top]=x;
if(t==x){fl=1;return;}
for(int v:g[x]){
if(v==fa)continue;
dfs(v,x,t);if(fl)return;
}top--;
}
signed main(){
scanf("%lld%lld",&n,&q);
for(int i=1,u,v;i<n;i++)
scanf("%lld%lld",&u,&v),g[u].push_back(v),g[v].push_back(u);
for(int i=1;i<=n;i++)
scanf("%lld",&val[i]),sum+=val[i]*val[i];
while(q--){
scanf("%lld",&op);
if(op==1)
scanf("%lld%lld",&u,&b),sum-=val[u]*val[u]-b*b,val[u]=b;
else {
scanf("%lld%lld%lld",&u,&v,&m);
fl=0;top=0;dfs(u,0,v);
int ans=sum,S=0;
for(int i=1;i<=top;i++)
S+=val[s[i]]*val[s[i]];
ans-=S;
int l=0,r=m;
while(l<r){
int mid=(l+r)>>1;
int ss=0;
for(int i=1;i<=top;i++)
if(val[s[i]]>mid)ss+=val[s[i]]-mid;
if(ss>m)l=mid+1;
else r=mid;
}
for(int i=1;i<=top;i++)
ans+=min(val[s[i]],l)*min(val[s[i]],l);
printf("%lld\n",ans);
}
}
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: 0ms
memory: 5964kb
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:
282602326 281291755 268959893 285074893 283559006 283347467 283766047 284936099 283898525 282246988 285020820 284657627 271808282 281477841 284891890 279885942 284891811 280898372 282042385 265703250 274104309 286966778 287203965 280403834 286940745 284965132 286557691 288195055 285548172 288640124 ...
result:
wrong answer 1st lines differ - expected: '285125508', found: '282602326'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
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:
8517265284434159388 4286815772003786373 6738441886006047855 1746916256536869404 -8347135555700315544 5554949647931058147 -8546080399512887644 8694456540679265700 8128348490769825698 -7888309181661801272 -7406422038772800803 7478045711873903172 6737041627810423013 5770466857672125299 8026169314157275...
result:
Subtask #4:
score: 0
Skipped
Dependency #1:
0%