QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#116354#5094. 小 H 分糖果lgvc#0 2ms7920kbC++232.4kb2023-06-28 15:56:572024-05-31 18:28:31

Judging History

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

  • [2024-05-31 18:28:31]
  • 管理员手动重测本题所有提交记录
  • 测评结果:0
  • 用时:2ms
  • 内存:7920kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-28 15:57:10]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:5932kb
  • [2023-06-28 15:56:57]
  • 提交

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,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();
	while(Q--) {
		int op=read();
		if(op==1) {
			int x=read(),v=read();
			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 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("0\n");
				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));
		}
	}
    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: 2ms
memory: 7920kb

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:

9583803
13180285
17509104
2455597
13999981
4820571
17446478
2557426
2073697
6296998
2222887
11461155
18566527
7013592
12109416
16425750
8793427
9394786
13795216
20892214
14526998
18578913
7682249
9083307
18909129
16067125
4153603
3033979
6284873
8456379
13750189
17898990
14581028
8793094
10807969
19...

result:

wrong answer 1st lines differ - expected: '285125508', found: '9583803'

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:

-861757028885219604
3849130054425045066
-6052941077934162339
-7850239294365247434
4215213996990776934
-7157634602132007875
2786026790786889371
7241654150358347182
2810818673915022790
-3531731805133935439
1597273943751780770
3632211244763361051
-5060468553603925002
-1038627343864301988
53201303767630...

result:


Subtask #4:

score: 0
Skipped

Dependency #1:

0%