QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#116348#5094. 小 H 分糖果lgvc#0 1ms7776kbC++232.4kb2023-06-28 15:49:452023-06-28 15:49:46

Judging History

你现在查看的是测评时间为 2023-06-28 15:49:46 的历史记录

  • [2024-05-31 18:28:31]
  • 管理员手动重测本题所有提交记录
  • 测评结果:0
  • 用时:0ms
  • 内存:7868kb
  • [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:49:46]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:7776kb
  • [2023-06-28 15:49:45]
  • 提交

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(a[i]>=md) as+=a[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<=N;i++) {
				if(a[i]>=l) as+=a[i]-l,aq+=l*l;else aq+=a[i]*a[i];
			}
			printf("%lld\n",aq-(v-as)*(2*l-1));
		}
	}
    return 0;
}


详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 7776kb

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:

284389488
284744385
285829664
268307653
283718882
282292117
283984925
244281931
269956784
283599140
279542133
283488049
287117015
286642521
283881143
284793820
283031969
284682615
284223559
286012567
288621313
286140292
285395267
288145688
286121405
287240301
286904454
282840401
287266848
287202217
...

result:

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

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:

8508740296034034132
-4711813884792662976
5790452312595792047
-5788040607456996779
8316690927258774021
-4759470548137344046
-8551099013013764204
8206272145992874904
8116519899110825260
-7913511267081415505
6306646798997310395
7469983403247786396
6706408565635909503
-4704836568630056724
49384153136431...

result:


Subtask #4:

score: 0
Skipped

Dependency #1:

0%