Submission #56355

# Submission time Handle Problem Language Result Execution time Memory
56355 2018-07-11T07:03:02 Z 정원준(#1601) Construction of Highway (JOI18_construction) C++11
16 / 100
2000 ms 10832 KB
#include <bits/stdc++.h>
#define L long long

using namespace std;

L n;

L a[100010];
L s[100010],e[100010];
L go[100010];

vector<L>v[100010],v2[100010],values;

map<L,L>back;

L tr[400040];

void init(L now,L s,L e){
	tr[now]=0;
	if(s==e) return;
	L mid=(s+e)/2;
	init(now*2,s,mid);
	init(now*2+1,mid+1,e);
}

void update(L now,L S,L E,L loc,L val){
	if(S>loc||E<loc) return;
	tr[now]+=val;
	if(S==E)
	{
		return;
	}
	L mid=(S+E)/2;
	update(now*2,S,mid,loc,val);
	update(now*2+1,mid+1,E,loc,val);
}

L sum(L now,L S,L E,L s,L e){
	if(S>e||E<s) return 0;
	if(s<=S&&E<=e) return tr[now];
	L mid=(S+E)/2;
	return sum(now*2,S,mid,s,e)+sum(now*2+1,mid+1,E,s,e);
}

int main()
{
	scanf("%lld",&n);
	L i,j;
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		values.push_back(a[i]);
	}
	sort(values.begin(),values.end());
	values.erase(unique(values.begin(),values.end()),values.end());
	for(i=0;i<values.size();i++)
	{
		go[i+1]=values[i];
		back[values[i]]=i+1;
	}
	for(i=1;i<=n;i++)
	{
		a[i]=back[a[i]];
	}
	for(i=1;i<n;i++)
	{
		scanf("%lld %lld",&s[i],&e[i]);
		v[s[i]].push_back(e[i]);
		v2[e[i]].push_back(s[i]);
	}
	for(i=1;i<n;i++)
	{
		L temp=s[i],temp2=0,color=a[e[i]];
		init(1,1,n);
		while(v2[temp].size())
		{
			temp2+=sum(1,1,n,1,a[temp]-1);
			update(1,1,n,a[temp],1);
			temp=v2[temp][0];
		}
		temp2+=sum(1,1,n,1,a[temp]-1);
		printf("%lld\n",temp2);
		temp=s[i];
		while(v2[temp].size())
		{
			a[temp]=color;
			temp=v2[temp][0];
		}
		a[temp]=color;
	}
}

Compilation message

construction.cpp: In function 'int main()':
construction.cpp:56:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0;i<values.size();i++)
          ~^~~~~~~~~~~~~~
construction.cpp:48:6: warning: unused variable 'j' [-Wunused-variable]
  L i,j;
      ^
construction.cpp:47:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld",&n);
  ~~~~~^~~~~~~~~~~
construction.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld",&a[i]);
   ~~~~~^~~~~~~~~~~~~~
construction.cpp:67:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld",&s[i],&e[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4984 KB Output is correct
2 Correct 8 ms 5096 KB Output is correct
3 Correct 7 ms 5172 KB Output is correct
4 Correct 9 ms 5336 KB Output is correct
5 Correct 11 ms 5336 KB Output is correct
6 Correct 8 ms 5336 KB Output is correct
7 Correct 12 ms 5336 KB Output is correct
8 Correct 28 ms 5336 KB Output is correct
9 Correct 33 ms 5336 KB Output is correct
10 Correct 29 ms 5416 KB Output is correct
11 Correct 16 ms 5416 KB Output is correct
12 Correct 15 ms 5416 KB Output is correct
13 Correct 16 ms 5416 KB Output is correct
14 Correct 16 ms 5416 KB Output is correct
15 Correct 12 ms 5416 KB Output is correct
16 Correct 9 ms 5416 KB Output is correct
17 Correct 11 ms 5416 KB Output is correct
18 Correct 9 ms 5416 KB Output is correct
19 Correct 17 ms 5488 KB Output is correct
20 Correct 16 ms 5488 KB Output is correct
21 Correct 14 ms 5488 KB Output is correct
22 Correct 11 ms 5488 KB Output is correct
23 Correct 8 ms 5488 KB Output is correct
24 Correct 7 ms 5488 KB Output is correct
25 Correct 9 ms 5488 KB Output is correct
26 Correct 22 ms 5488 KB Output is correct
27 Correct 16 ms 5488 KB Output is correct
28 Correct 16 ms 5488 KB Output is correct
29 Correct 16 ms 5488 KB Output is correct
30 Correct 8 ms 5488 KB Output is correct
31 Correct 11 ms 5488 KB Output is correct
32 Correct 15 ms 5488 KB Output is correct
33 Correct 18 ms 5488 KB Output is correct
34 Correct 10 ms 5488 KB Output is correct
35 Correct 12 ms 5488 KB Output is correct
36 Correct 13 ms 5488 KB Output is correct
37 Correct 12 ms 5488 KB Output is correct
38 Correct 13 ms 5488 KB Output is correct
39 Correct 13 ms 5488 KB Output is correct
40 Correct 12 ms 5488 KB Output is correct
41 Correct 10 ms 5488 KB Output is correct
42 Correct 15 ms 5504 KB Output is correct
43 Correct 16 ms 5504 KB Output is correct
44 Correct 10 ms 5504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4984 KB Output is correct
2 Correct 8 ms 5096 KB Output is correct
3 Correct 7 ms 5172 KB Output is correct
4 Correct 9 ms 5336 KB Output is correct
5 Correct 11 ms 5336 KB Output is correct
6 Correct 8 ms 5336 KB Output is correct
7 Correct 12 ms 5336 KB Output is correct
8 Correct 28 ms 5336 KB Output is correct
9 Correct 33 ms 5336 KB Output is correct
10 Correct 29 ms 5416 KB Output is correct
11 Correct 16 ms 5416 KB Output is correct
12 Correct 15 ms 5416 KB Output is correct
13 Correct 16 ms 5416 KB Output is correct
14 Correct 16 ms 5416 KB Output is correct
15 Correct 12 ms 5416 KB Output is correct
16 Correct 9 ms 5416 KB Output is correct
17 Correct 11 ms 5416 KB Output is correct
18 Correct 9 ms 5416 KB Output is correct
19 Correct 17 ms 5488 KB Output is correct
20 Correct 16 ms 5488 KB Output is correct
21 Correct 14 ms 5488 KB Output is correct
22 Correct 11 ms 5488 KB Output is correct
23 Correct 8 ms 5488 KB Output is correct
24 Correct 7 ms 5488 KB Output is correct
25 Correct 9 ms 5488 KB Output is correct
26 Correct 22 ms 5488 KB Output is correct
27 Correct 16 ms 5488 KB Output is correct
28 Correct 16 ms 5488 KB Output is correct
29 Correct 16 ms 5488 KB Output is correct
30 Correct 8 ms 5488 KB Output is correct
31 Correct 11 ms 5488 KB Output is correct
32 Correct 15 ms 5488 KB Output is correct
33 Correct 18 ms 5488 KB Output is correct
34 Correct 10 ms 5488 KB Output is correct
35 Correct 12 ms 5488 KB Output is correct
36 Correct 13 ms 5488 KB Output is correct
37 Correct 12 ms 5488 KB Output is correct
38 Correct 13 ms 5488 KB Output is correct
39 Correct 13 ms 5488 KB Output is correct
40 Correct 12 ms 5488 KB Output is correct
41 Correct 10 ms 5488 KB Output is correct
42 Correct 15 ms 5504 KB Output is correct
43 Correct 16 ms 5504 KB Output is correct
44 Correct 10 ms 5504 KB Output is correct
45 Correct 11 ms 5504 KB Output is correct
46 Correct 86 ms 6148 KB Output is correct
47 Correct 103 ms 6148 KB Output is correct
48 Correct 83 ms 6148 KB Output is correct
49 Correct 1494 ms 6176 KB Output is correct
50 Correct 1471 ms 6176 KB Output is correct
51 Correct 1546 ms 6320 KB Output is correct
52 Correct 779 ms 6320 KB Output is correct
53 Correct 747 ms 6320 KB Output is correct
54 Correct 790 ms 6320 KB Output is correct
55 Correct 749 ms 6320 KB Output is correct
56 Correct 743 ms 6320 KB Output is correct
57 Correct 86 ms 6320 KB Output is correct
58 Correct 103 ms 6320 KB Output is correct
59 Correct 88 ms 6320 KB Output is correct
60 Correct 99 ms 6320 KB Output is correct
61 Correct 879 ms 6320 KB Output is correct
62 Correct 820 ms 6320 KB Output is correct
63 Correct 749 ms 6320 KB Output is correct
64 Correct 80 ms 6320 KB Output is correct
65 Correct 115 ms 6320 KB Output is correct
66 Correct 98 ms 6320 KB Output is correct
67 Correct 90 ms 6320 KB Output is correct
68 Correct 1652 ms 6320 KB Output is correct
69 Correct 858 ms 6320 KB Output is correct
70 Correct 790 ms 6320 KB Output is correct
71 Correct 777 ms 6320 KB Output is correct
72 Correct 89 ms 6320 KB Output is correct
73 Correct 84 ms 6320 KB Output is correct
74 Correct 929 ms 6320 KB Output is correct
75 Correct 513 ms 6320 KB Output is correct
76 Correct 322 ms 6320 KB Output is correct
77 Correct 268 ms 6320 KB Output is correct
78 Correct 509 ms 6320 KB Output is correct
79 Correct 320 ms 6320 KB Output is correct
80 Correct 304 ms 6320 KB Output is correct
81 Correct 372 ms 6320 KB Output is correct
82 Correct 292 ms 6320 KB Output is correct
83 Correct 224 ms 6320 KB Output is correct
84 Correct 455 ms 6320 KB Output is correct
85 Correct 309 ms 6320 KB Output is correct
86 Correct 272 ms 6320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4984 KB Output is correct
2 Correct 8 ms 5096 KB Output is correct
3 Correct 7 ms 5172 KB Output is correct
4 Correct 9 ms 5336 KB Output is correct
5 Correct 11 ms 5336 KB Output is correct
6 Correct 8 ms 5336 KB Output is correct
7 Correct 12 ms 5336 KB Output is correct
8 Correct 28 ms 5336 KB Output is correct
9 Correct 33 ms 5336 KB Output is correct
10 Correct 29 ms 5416 KB Output is correct
11 Correct 16 ms 5416 KB Output is correct
12 Correct 15 ms 5416 KB Output is correct
13 Correct 16 ms 5416 KB Output is correct
14 Correct 16 ms 5416 KB Output is correct
15 Correct 12 ms 5416 KB Output is correct
16 Correct 9 ms 5416 KB Output is correct
17 Correct 11 ms 5416 KB Output is correct
18 Correct 9 ms 5416 KB Output is correct
19 Correct 17 ms 5488 KB Output is correct
20 Correct 16 ms 5488 KB Output is correct
21 Correct 14 ms 5488 KB Output is correct
22 Correct 11 ms 5488 KB Output is correct
23 Correct 8 ms 5488 KB Output is correct
24 Correct 7 ms 5488 KB Output is correct
25 Correct 9 ms 5488 KB Output is correct
26 Correct 22 ms 5488 KB Output is correct
27 Correct 16 ms 5488 KB Output is correct
28 Correct 16 ms 5488 KB Output is correct
29 Correct 16 ms 5488 KB Output is correct
30 Correct 8 ms 5488 KB Output is correct
31 Correct 11 ms 5488 KB Output is correct
32 Correct 15 ms 5488 KB Output is correct
33 Correct 18 ms 5488 KB Output is correct
34 Correct 10 ms 5488 KB Output is correct
35 Correct 12 ms 5488 KB Output is correct
36 Correct 13 ms 5488 KB Output is correct
37 Correct 12 ms 5488 KB Output is correct
38 Correct 13 ms 5488 KB Output is correct
39 Correct 13 ms 5488 KB Output is correct
40 Correct 12 ms 5488 KB Output is correct
41 Correct 10 ms 5488 KB Output is correct
42 Correct 15 ms 5504 KB Output is correct
43 Correct 16 ms 5504 KB Output is correct
44 Correct 10 ms 5504 KB Output is correct
45 Correct 11 ms 5504 KB Output is correct
46 Correct 86 ms 6148 KB Output is correct
47 Correct 103 ms 6148 KB Output is correct
48 Correct 83 ms 6148 KB Output is correct
49 Correct 1494 ms 6176 KB Output is correct
50 Correct 1471 ms 6176 KB Output is correct
51 Correct 1546 ms 6320 KB Output is correct
52 Correct 779 ms 6320 KB Output is correct
53 Correct 747 ms 6320 KB Output is correct
54 Correct 790 ms 6320 KB Output is correct
55 Correct 749 ms 6320 KB Output is correct
56 Correct 743 ms 6320 KB Output is correct
57 Correct 86 ms 6320 KB Output is correct
58 Correct 103 ms 6320 KB Output is correct
59 Correct 88 ms 6320 KB Output is correct
60 Correct 99 ms 6320 KB Output is correct
61 Correct 879 ms 6320 KB Output is correct
62 Correct 820 ms 6320 KB Output is correct
63 Correct 749 ms 6320 KB Output is correct
64 Correct 80 ms 6320 KB Output is correct
65 Correct 115 ms 6320 KB Output is correct
66 Correct 98 ms 6320 KB Output is correct
67 Correct 90 ms 6320 KB Output is correct
68 Correct 1652 ms 6320 KB Output is correct
69 Correct 858 ms 6320 KB Output is correct
70 Correct 790 ms 6320 KB Output is correct
71 Correct 777 ms 6320 KB Output is correct
72 Correct 89 ms 6320 KB Output is correct
73 Correct 84 ms 6320 KB Output is correct
74 Correct 929 ms 6320 KB Output is correct
75 Correct 513 ms 6320 KB Output is correct
76 Correct 322 ms 6320 KB Output is correct
77 Correct 268 ms 6320 KB Output is correct
78 Correct 509 ms 6320 KB Output is correct
79 Correct 320 ms 6320 KB Output is correct
80 Correct 304 ms 6320 KB Output is correct
81 Correct 372 ms 6320 KB Output is correct
82 Correct 292 ms 6320 KB Output is correct
83 Correct 224 ms 6320 KB Output is correct
84 Correct 455 ms 6320 KB Output is correct
85 Correct 309 ms 6320 KB Output is correct
86 Correct 272 ms 6320 KB Output is correct
87 Correct 698 ms 7340 KB Output is correct
88 Execution timed out 2055 ms 10832 KB Time limit exceeded
89 Halted 0 ms 0 KB -