Submission #105255

# Submission time Handle Problem Language Result Execution time Memory
105255 2019-04-11T04:34:33 Z he_____he Construction of Highway (JOI18_construction) C++14
16 / 100
2000 ms 4580 KB
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n;
int a[100005],c[100005],fa[100005],p[100005];

int lowbit(int x){return x&(-x);}
void add(int x){for(;x<=n;x+=lowbit(x))c[x]++;}
int ask(int x){int ret=0;for(;x;x-=lowbit(x))ret+=c[x];return ret;}

int main(){
	n=readint();
	for(int i=1;i<=n;i++) p[i]=a[i]=readint();
	sort(p+1,p+n+1);
	for(int i=1;i<=n;i++) a[i]=lower_bound(p+1,p+n+1,a[i])-p;
	int x,y,tx,nans;
	for(int i=1;i<=n-1;i++){
		tx=x=readint(); y=readint();
		memset(c,0,sizeof(c)); nans=0;
		while(x){
			nans+=ask(a[x]-1);
			add(a[x]);
			x=fa[x];
		}
		printf("%d\n",nans);
		fa[y]=tx,x=tx;
		while(x){
			a[x]=a[y];
			x=fa[x];
		}
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 768 KB Output is correct
2 Correct 3 ms 768 KB Output is correct
3 Correct 5 ms 768 KB Output is correct
4 Correct 10 ms 768 KB Output is correct
5 Correct 13 ms 768 KB Output is correct
6 Correct 13 ms 768 KB Output is correct
7 Correct 12 ms 740 KB Output is correct
8 Correct 14 ms 768 KB Output is correct
9 Correct 14 ms 768 KB Output is correct
10 Correct 14 ms 768 KB Output is correct
11 Correct 14 ms 768 KB Output is correct
12 Correct 13 ms 768 KB Output is correct
13 Correct 12 ms 768 KB Output is correct
14 Correct 14 ms 768 KB Output is correct
15 Correct 12 ms 768 KB Output is correct
16 Correct 12 ms 768 KB Output is correct
17 Correct 15 ms 768 KB Output is correct
18 Correct 14 ms 768 KB Output is correct
19 Correct 14 ms 768 KB Output is correct
20 Correct 13 ms 768 KB Output is correct
21 Correct 12 ms 768 KB Output is correct
22 Correct 14 ms 768 KB Output is correct
23 Correct 14 ms 768 KB Output is correct
24 Correct 13 ms 768 KB Output is correct
25 Correct 13 ms 768 KB Output is correct
26 Correct 12 ms 768 KB Output is correct
27 Correct 14 ms 768 KB Output is correct
28 Correct 13 ms 768 KB Output is correct
29 Correct 13 ms 768 KB Output is correct
30 Correct 13 ms 768 KB Output is correct
31 Correct 12 ms 768 KB Output is correct
32 Correct 15 ms 768 KB Output is correct
33 Correct 12 ms 768 KB Output is correct
34 Correct 13 ms 768 KB Output is correct
35 Correct 13 ms 740 KB Output is correct
36 Correct 15 ms 896 KB Output is correct
37 Correct 13 ms 768 KB Output is correct
38 Correct 13 ms 768 KB Output is correct
39 Correct 14 ms 788 KB Output is correct
40 Correct 14 ms 768 KB Output is correct
41 Correct 13 ms 768 KB Output is correct
42 Correct 13 ms 768 KB Output is correct
43 Correct 12 ms 768 KB Output is correct
44 Correct 11 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 768 KB Output is correct
2 Correct 3 ms 768 KB Output is correct
3 Correct 5 ms 768 KB Output is correct
4 Correct 10 ms 768 KB Output is correct
5 Correct 13 ms 768 KB Output is correct
6 Correct 13 ms 768 KB Output is correct
7 Correct 12 ms 740 KB Output is correct
8 Correct 14 ms 768 KB Output is correct
9 Correct 14 ms 768 KB Output is correct
10 Correct 14 ms 768 KB Output is correct
11 Correct 14 ms 768 KB Output is correct
12 Correct 13 ms 768 KB Output is correct
13 Correct 12 ms 768 KB Output is correct
14 Correct 14 ms 768 KB Output is correct
15 Correct 12 ms 768 KB Output is correct
16 Correct 12 ms 768 KB Output is correct
17 Correct 15 ms 768 KB Output is correct
18 Correct 14 ms 768 KB Output is correct
19 Correct 14 ms 768 KB Output is correct
20 Correct 13 ms 768 KB Output is correct
21 Correct 12 ms 768 KB Output is correct
22 Correct 14 ms 768 KB Output is correct
23 Correct 14 ms 768 KB Output is correct
24 Correct 13 ms 768 KB Output is correct
25 Correct 13 ms 768 KB Output is correct
26 Correct 12 ms 768 KB Output is correct
27 Correct 14 ms 768 KB Output is correct
28 Correct 13 ms 768 KB Output is correct
29 Correct 13 ms 768 KB Output is correct
30 Correct 13 ms 768 KB Output is correct
31 Correct 12 ms 768 KB Output is correct
32 Correct 15 ms 768 KB Output is correct
33 Correct 12 ms 768 KB Output is correct
34 Correct 13 ms 768 KB Output is correct
35 Correct 13 ms 740 KB Output is correct
36 Correct 15 ms 896 KB Output is correct
37 Correct 13 ms 768 KB Output is correct
38 Correct 13 ms 768 KB Output is correct
39 Correct 14 ms 788 KB Output is correct
40 Correct 14 ms 768 KB Output is correct
41 Correct 13 ms 768 KB Output is correct
42 Correct 13 ms 768 KB Output is correct
43 Correct 12 ms 768 KB Output is correct
44 Correct 11 ms 768 KB Output is correct
45 Correct 23 ms 768 KB Output is correct
46 Correct 83 ms 888 KB Output is correct
47 Correct 81 ms 768 KB Output is correct
48 Correct 83 ms 988 KB Output is correct
49 Correct 215 ms 888 KB Output is correct
50 Correct 204 ms 892 KB Output is correct
51 Correct 213 ms 884 KB Output is correct
52 Correct 161 ms 888 KB Output is correct
53 Correct 165 ms 888 KB Output is correct
54 Correct 155 ms 880 KB Output is correct
55 Correct 162 ms 896 KB Output is correct
56 Correct 157 ms 888 KB Output is correct
57 Correct 83 ms 896 KB Output is correct
58 Correct 85 ms 1016 KB Output is correct
59 Correct 82 ms 888 KB Output is correct
60 Correct 91 ms 1016 KB Output is correct
61 Correct 162 ms 888 KB Output is correct
62 Correct 166 ms 988 KB Output is correct
63 Correct 147 ms 1020 KB Output is correct
64 Correct 84 ms 1016 KB Output is correct
65 Correct 74 ms 768 KB Output is correct
66 Correct 81 ms 992 KB Output is correct
67 Correct 75 ms 768 KB Output is correct
68 Correct 225 ms 896 KB Output is correct
69 Correct 136 ms 768 KB Output is correct
70 Correct 140 ms 896 KB Output is correct
71 Correct 136 ms 888 KB Output is correct
72 Correct 81 ms 840 KB Output is correct
73 Correct 81 ms 1016 KB Output is correct
74 Correct 140 ms 764 KB Output is correct
75 Correct 118 ms 888 KB Output is correct
76 Correct 105 ms 876 KB Output is correct
77 Correct 100 ms 924 KB Output is correct
78 Correct 107 ms 888 KB Output is correct
79 Correct 110 ms 768 KB Output is correct
80 Correct 101 ms 892 KB Output is correct
81 Correct 127 ms 888 KB Output is correct
82 Correct 107 ms 920 KB Output is correct
83 Correct 94 ms 896 KB Output is correct
84 Correct 113 ms 856 KB Output is correct
85 Correct 101 ms 856 KB Output is correct
86 Correct 102 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 768 KB Output is correct
2 Correct 3 ms 768 KB Output is correct
3 Correct 5 ms 768 KB Output is correct
4 Correct 10 ms 768 KB Output is correct
5 Correct 13 ms 768 KB Output is correct
6 Correct 13 ms 768 KB Output is correct
7 Correct 12 ms 740 KB Output is correct
8 Correct 14 ms 768 KB Output is correct
9 Correct 14 ms 768 KB Output is correct
10 Correct 14 ms 768 KB Output is correct
11 Correct 14 ms 768 KB Output is correct
12 Correct 13 ms 768 KB Output is correct
13 Correct 12 ms 768 KB Output is correct
14 Correct 14 ms 768 KB Output is correct
15 Correct 12 ms 768 KB Output is correct
16 Correct 12 ms 768 KB Output is correct
17 Correct 15 ms 768 KB Output is correct
18 Correct 14 ms 768 KB Output is correct
19 Correct 14 ms 768 KB Output is correct
20 Correct 13 ms 768 KB Output is correct
21 Correct 12 ms 768 KB Output is correct
22 Correct 14 ms 768 KB Output is correct
23 Correct 14 ms 768 KB Output is correct
24 Correct 13 ms 768 KB Output is correct
25 Correct 13 ms 768 KB Output is correct
26 Correct 12 ms 768 KB Output is correct
27 Correct 14 ms 768 KB Output is correct
28 Correct 13 ms 768 KB Output is correct
29 Correct 13 ms 768 KB Output is correct
30 Correct 13 ms 768 KB Output is correct
31 Correct 12 ms 768 KB Output is correct
32 Correct 15 ms 768 KB Output is correct
33 Correct 12 ms 768 KB Output is correct
34 Correct 13 ms 768 KB Output is correct
35 Correct 13 ms 740 KB Output is correct
36 Correct 15 ms 896 KB Output is correct
37 Correct 13 ms 768 KB Output is correct
38 Correct 13 ms 768 KB Output is correct
39 Correct 14 ms 788 KB Output is correct
40 Correct 14 ms 768 KB Output is correct
41 Correct 13 ms 768 KB Output is correct
42 Correct 13 ms 768 KB Output is correct
43 Correct 12 ms 768 KB Output is correct
44 Correct 11 ms 768 KB Output is correct
45 Correct 23 ms 768 KB Output is correct
46 Correct 83 ms 888 KB Output is correct
47 Correct 81 ms 768 KB Output is correct
48 Correct 83 ms 988 KB Output is correct
49 Correct 215 ms 888 KB Output is correct
50 Correct 204 ms 892 KB Output is correct
51 Correct 213 ms 884 KB Output is correct
52 Correct 161 ms 888 KB Output is correct
53 Correct 165 ms 888 KB Output is correct
54 Correct 155 ms 880 KB Output is correct
55 Correct 162 ms 896 KB Output is correct
56 Correct 157 ms 888 KB Output is correct
57 Correct 83 ms 896 KB Output is correct
58 Correct 85 ms 1016 KB Output is correct
59 Correct 82 ms 888 KB Output is correct
60 Correct 91 ms 1016 KB Output is correct
61 Correct 162 ms 888 KB Output is correct
62 Correct 166 ms 988 KB Output is correct
63 Correct 147 ms 1020 KB Output is correct
64 Correct 84 ms 1016 KB Output is correct
65 Correct 74 ms 768 KB Output is correct
66 Correct 81 ms 992 KB Output is correct
67 Correct 75 ms 768 KB Output is correct
68 Correct 225 ms 896 KB Output is correct
69 Correct 136 ms 768 KB Output is correct
70 Correct 140 ms 896 KB Output is correct
71 Correct 136 ms 888 KB Output is correct
72 Correct 81 ms 840 KB Output is correct
73 Correct 81 ms 1016 KB Output is correct
74 Correct 140 ms 764 KB Output is correct
75 Correct 118 ms 888 KB Output is correct
76 Correct 105 ms 876 KB Output is correct
77 Correct 100 ms 924 KB Output is correct
78 Correct 107 ms 888 KB Output is correct
79 Correct 110 ms 768 KB Output is correct
80 Correct 101 ms 892 KB Output is correct
81 Correct 127 ms 888 KB Output is correct
82 Correct 107 ms 920 KB Output is correct
83 Correct 94 ms 896 KB Output is correct
84 Correct 113 ms 856 KB Output is correct
85 Correct 101 ms 856 KB Output is correct
86 Correct 102 ms 896 KB Output is correct
87 Correct 180 ms 1096 KB Output is correct
88 Correct 583 ms 1756 KB Output is correct
89 Correct 1873 ms 4580 KB Output is correct
90 Correct 1884 ms 4528 KB Output is correct
91 Correct 1890 ms 4504 KB Output is correct
92 Execution timed out 2033 ms 3336 KB Time limit exceeded
93 Halted 0 ms 0 KB -