QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#403647#8318. 白兰地厅的西瓜dingdingtang11514#100 ✓87ms34660kbC++142.6kb2024-05-02 16:22:062024-05-02 16:22:07

Judging History

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

  • [2024-05-02 16:22:07]
  • 评测
  • 测评结果:100
  • 用时:87ms
  • 内存:34660kb
  • [2024-05-02 16:22:06]
  • 提交

answer

#include <iostream>
#include <cstring> 
#include <map>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
// #include <map>
// #include <bits/stdc++.h>

// #define int long long
#define For(i,a,b) for(int i=(a);i<=(b);i++)
#define Rof(i,a,b) for(int i=(a);i>=(b);i--)
#define Grf(it,u,to) for(int it=he[u],to;(to=e[it],it);it=nxt[it]) 
#define In __inline 
#define OP operator
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
namespace Mine {
	// mt19937_64 wql(514);
	In ll read() {
		ll x=1,a=0;
		char ch=getchar();
		while(ch>'9' || ch<'0') x=(ch=='-')?-1:x,ch=getchar();
		while(ch>='0' && ch<='9') a=(a<<1)+(a<<3)+(ch-'0'),ch=getchar();
		return a*x;
	} const int N=1e5+100;
	int he[N],e[N<<1],nxt[N<<1]; namespace E {int idx=1;
		void adde(int a,int b){e[++idx]=b,nxt[idx]=he[a];he[a]=idx;}
	}using E::adde; int n,ans,a[N],b[N],root[N],len;
#define lc(u) tr[(u)].lc
#define rc(u) tr[(u)].rc
	In int gmax(int &x,int y){return (x=max(x,y));}struct node {
		int lc,rc,f[2];
	} tr[N*60]; int idx=1; void mdf(int &u,int pos,int val,int op,int l=1,int r=1e5) {
		if(!u) {u=++idx;} ans=max(ans,gmax(tr[u].f[op],val));
		int mid=(l+r)>>1;if(l==r) return ;
		if(pos<=mid) mdf(tr[u].lc,pos,val,op,l,mid);
		else mdf(tr[u].rc,pos,val,op,mid+1,r);
	} int merge(int x,int y) { if(!x || !y) return x+y;
		gmax(ans,max(tr[lc(x)].f[0]+tr[rc(y)].f[1],tr[lc(y)].f[0]+tr[rc(x)].f[1]));
		gmax(tr[x].f[0],tr[y].f[0]);gmax(tr[x].f[1],tr[y].f[1]);
		lc(x)=merge(lc(x),lc(y)); rc(x)=merge(rc(x),rc(y)); return x;
	} int qry(int u,int ql,int qr,int op,int l=1,int r=1e5) {
		if(!u) return 0;
		if(ql>qr) return 0;
		if(ql<=l && r<=qr) return tr[u].f[op];
		int mid=(l+r)>>1; if(qr<=mid) return qry(lc(u),ql,qr,op,l,mid);
		if(mid<ql) return qry(rc(u),ql,qr,op,mid+1,r);
		return max(qry(lc(u),ql,qr,op,l,mid),qry(rc(u),ql,qr,op,mid+1,r));
	} void dfs(int u,int fa) {
		 int mx1=0,mx0=0;Grf(it,u,to) { if(to==fa) continue;
			dfs(to,u); int t0=qry(root[to],1,a[u]-1,0),t1=qry(root[to],a[u]+1,1e5,1);
			gmax(ans,max(mx1+t0,mx0+t1)+1);gmax(mx0,t0);gmax(mx1,t1);
			root[u]=merge(root[u],root[to]);
		} mdf(root[u],a[u],mx0+1,0); mdf(root[u],a[u],mx1+1,1);
		// printf("%d :",u); print(root[u]);puts("");
	} signed main() {n=read(); For(i,1,n) {a[i]=b[i]=read();} sort(b+1,b+1+n);
		len=unique(b+1,b+1+n)-b-1; For(i,1,n) {a[i]=lower_bound(b+1,b+1+n,a[i])-b;}
		For(i,1,n-1) {int a=read(),b=read();adde(a,b);adde(b,a);}
		dfs(1,0); 
		return printf("%d",ans) , 0;
	}
}signed main() {
	// freopen("homework.in","r",stdin);
	// freopen("homework.out","w",stdout);
	return Mine::main();
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 1ms
memory: 3800kb

input:

100
153314338 599231681 858435749 723728532 852113215 378535625 215162690 923065539 951983654 189872202 340854577 762420560 247102481 58348011 381182670 225684974 727160244 17794042 176551091 74792743 815847597 25690481 708165027 806743934 878575557 892366013 619168311 110922692 910879195 115796937 ...

output:

8

result:

ok 1 number(s): "8"

Subtask #2:

score: 10
Accepted

Dependency #1:

100%
Accepted

Test #2:

score: 10
Accepted
time: 1ms
memory: 3968kb

input:

1000
78489921 969971487 825933116 372097611 4721729 316569942 977315119 632546018 270107640 166931760 987070325 74592266 79702886 208771995 223716883 428991179 886445793 820327751 528784039 362871691 328323831 491420678 946333794 428967373 177442537 569874407 792352850 453993155 880434421 654997821 ...

output:

11

result:

ok 1 number(s): "11"

Subtask #3:

score: 10
Accepted

Test #3:

score: 10
Accepted
time: 3ms
memory: 4748kb

input:

5000
3 4 1 4 4 1 4 3 2 2 1 2 4 1 4 2 1 2 4 2 1 4 1 3 1 3 4 4 3 2 4 1 1 1 1 1 1 4 3 2 1 3 3 4 3 2 1 4 3 1 1 4 4 1 2 4 4 1 4 2 3 3 3 3 3 3 3 3 2 1 4 2 4 2 1 2 4 2 1 2 2 1 1 1 2 3 1 1 3 4 2 1 2 4 4 1 2 2 3 3 3 3 4 2 4 1 3 3 2 4 1 3 4 1 3 1 3 3 1 2 2 3 2 4 2 1 4 4 3 2 2 1 4 2 2 4 2 4 2 3 3 2 1 3 3 3 3 1...

output:

4

result:

ok 1 number(s): "4"

Subtask #4:

score: 10
Accepted

Test #4:

score: 10
Accepted
time: 36ms
memory: 23336kb

input:

100000
1 1 1 2 2 1 2 1 1 1 1 1 2 1 1 2 1 2 2 2 2 1 1 1 1 2 1 2 1 1 2 1 2 2 2 1 2 1 1 2 1 1 2 1 2 2 2 2 2 2 2 1 2 2 1 2 1 1 1 1 2 2 1 1 1 1 1 2 1 1 2 2 1 1 2 2 1 1 2 2 2 1 2 1 2 2 1 1 2 1 1 1 1 2 1 1 2 1 1 2 1 2 1 2 2 2 1 2 1 2 1 2 2 2 1 2 1 1 2 1 1 2 1 1 1 2 2 2 2 2 2 1 1 2 2 2 2 2 2 2 2 2 1 1 2 1 2...

output:

2

result:

ok 1 number(s): "2"

Subtask #5:

score: 10
Accepted

Test #5:

score: 10
Accepted
time: 58ms
memory: 34660kb

input:

100000
513402173 905110107 1515964 765035952 73901932 836471400 638273851 141529265 534872932 51406447 890683116 47931908 38105393 980251419 528541651 947351982 893221503 90272203 405153875 343727573 238912737 33910798 528133613 280738156 612988056 313310885 65798230 856093442 398702229 181287213 88...

output:

3

result:

ok 1 number(s): "3"

Subtask #6:

score: 10
Accepted

Test #6:

score: 10
Accepted
time: 75ms
memory: 16236kb

input:

100000
830714990 589894538 943716562 157018548 696139650 392186560 878398600 121609777 598909611 482284158 271893438 701809635 751800960 313432974 666336108 18407929 776178328 4559353 746871036 133896190 239663762 1679167 391373768 219219820 540730189 5756262 599943931 186156412 806901497 778383641 ...

output:

625

result:

ok 1 number(s): "625"

Subtask #7:

score: 10
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Test #7:

score: 10
Accepted
time: 87ms
memory: 31872kb

input:

100000
989006465 273186777 686466908 828906673 784813825 129903897 437927186 855860409 151880008 205622303 52488329 121430183 146482373 989757946 751644599 972173501 118366377 209800585 7798826 850705724 903480939 118462706 38931862 99926861 380670474 857487147 194716288 458379589 947641379 40437503...

output:

16

result:

ok 1 number(s): "16"

Test #8:

score: 10
Accepted
time: 76ms
memory: 27084kb

input:

100000
376325316 423464118 514600155 128241303 617247807 496865863 247253324 397730766 83040054 441316052 791170426 116788240 778460279 333494614 308555803 191070073 611806436 717194899 949015790 76686346 545962957 406128775 26857589 105055762 836616415 737656112 232958186 476290877 309747842 886868...

output:

357

result:

ok 1 number(s): "357"

Test #9:

score: 10
Accepted
time: 73ms
memory: 27876kb

input:

100000
4315 39289 11073 46880 94635 37467 28769 75705 19206 6365 79945 90008 68068 82757 57256 76403 45594 51112 1981 77777 30585 64873 74623 33156 28681 25101 68167 10196 37307 58406 71560 50528 34580 82460 94137 38977 72485 91425 14850 11652 27519 19820 35046 49204 89985 74502 57486 71339 18923 45...

output:

354

result:

ok 1 number(s): "354"

Test #10:

score: 10
Accepted
time: 65ms
memory: 24684kb

input:

100000
35056 14076 32630 34042 2618 6242 12444 4075 43362 28868 22032 34321 3314 45828 36713 39900 1895 19568 27500 27395 12759 28131 33661 31442 11863 43204 22045 18597 40188 30493 20985 6246 1668 35561 10482 48006 33268 42621 27905 4546 48666 13232 29540 23218 25581 47996 14421 33207 16872 39178 1...

output:

50000

result:

ok 1 number(s): "50000"