Submission #334661

# Submission time Handle Problem Language Result Execution time Memory
334661 2020-12-09T17:04:01 Z Kerim Birthday gift (IZhO18_treearray) C++17
100 / 100
2158 ms 67012 KB
#include "bits/stdc++.h"
#define MAXN 200009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
vector<int>adj[MAXN];
const int LOGN=18;
int P[MAXN][LOGN],lvl[MAXN],arr[MAXN];
set<PII>s,t;
void dfs(int nd,int pr){
	tr(it,adj[nd]){
		if(*it==pr)continue;
		P[*it][0]=nd;lvl[*it]=lvl[nd]+1;
		dfs(*it,nd);
	}
}
int lca(int x,int y){
	if(lvl[x]<lvl[y])
		swap(x,y);
	for(int i=LOGN-1;i>=0;i--)
		if(lvl[P[x][i]]>=lvl[y])
			x=P[x][i];
	if(x==y)return x;
	for(int i=LOGN-1;i>=0;i--)
		if(P[x][i] and P[y][i]!=P[x][i])
			x=P[x][i],y=P[y][i];
	return P[x][0];	
}
int main(){
  //  freopen("file.in", "r", stdin);
    int n,m,q;
    scanf("%d%d%d",&n,&m,&q);
    for(int i=1;i<n;i++){
    	int u,v;
		scanf("%d%d",&u,&v);
		adj[u].pb(v);
		adj[v].pb(u);	
    }
    dfs(1,-1);
    for(int i=1;i<=m;i++)
    	scanf("%d",arr+i);
    for(int j=1;j<LOGN;j++)
    	for(int i=1;i<=n;i++)
    		if(P[i][j-1])
    			P[i][j]=P[P[i][j-1]][j-1];
    t.insert(mp(arr[m],m));
    for(int i=1;i<m;i++){
    	s.insert(mp(lca(arr[i],arr[i+1]),i));
    	t.insert(mp(arr[i],i));
    }
    while(q--){
    	int tp;
		scanf("%d",&tp);
		if(tp==2){
			int l,r,v;
			scanf("%d%d%d",&l,&r,&v);
			__typeof((t).begin())itt=t.lower_bound(mp(v,l));
			
			if(itt!=t.end() and itt->ff==v and itt->ss<=r)
				printf("%d %d\n",itt->ss,itt->ss);
			else{
				__typeof((s).begin())it=s.lower_bound(mp(v,l));
				if(it!=s.end() and it->ff==v and it->ss<r)
					printf("%d %d\n",it->ss,(it->ss)+1);
				else
					puts("-1 -1");
			}
		}
		else{
			int p,v;
			scanf("%d%d",&p,&v);
			t.erase(mp(arr[p],p));
			t.insert(mp(v,p));
			if(p>1){
				s.erase(mp(lca(arr[p-1],arr[p]),p-1));
				s.insert(mp(lca(arr[p-1],v),p-1));	
			}
			if(p<m){
				s.erase(mp(lca(arr[p+1],arr[p]),p));
				s.insert(mp(lca(arr[p+1],v),p));	
			}
			arr[p]=v;	
		}
    }
	return 0;
}

Compilation message

treearray.cpp: In function 'int main()':
treearray.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   46 |     scanf("%d%d%d",&n,&m,&q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
treearray.cpp:49:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   49 |   scanf("%d%d",&u,&v);
      |   ~~~~~^~~~~~~~~~~~~~
treearray.cpp:55:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   55 |      scanf("%d",arr+i);
      |      ~~~~~^~~~~~~~~~~~
treearray.cpp:67:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   67 |   scanf("%d",&tp);
      |   ~~~~~^~~~~~~~~~
treearray.cpp:70:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   70 |    scanf("%d%d%d",&l,&r,&v);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~
treearray.cpp:85:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   85 |    scanf("%d%d",&p,&v);
      |    ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4972 KB n=5
2 Correct 4 ms 5100 KB n=100
3 Correct 3 ms 5100 KB n=100
4 Correct 4 ms 5100 KB n=100
5 Correct 4 ms 5100 KB n=100
6 Correct 3 ms 5100 KB n=100
7 Correct 3 ms 5100 KB n=100
8 Correct 4 ms 5100 KB n=100
9 Correct 3 ms 5100 KB n=100
10 Correct 4 ms 5120 KB n=100
11 Correct 4 ms 5100 KB n=100
12 Correct 4 ms 5228 KB n=100
13 Correct 4 ms 5100 KB n=100
14 Correct 4 ms 5100 KB n=100
15 Correct 4 ms 5100 KB n=100
16 Correct 4 ms 5100 KB n=100
17 Correct 4 ms 5100 KB n=100
18 Correct 4 ms 5100 KB n=100
19 Correct 4 ms 5100 KB n=100
20 Correct 4 ms 5100 KB n=100
21 Correct 3 ms 5100 KB n=100
22 Correct 4 ms 5100 KB n=100
23 Correct 4 ms 5100 KB n=100
24 Correct 4 ms 5100 KB n=100
25 Correct 3 ms 5100 KB n=100
26 Correct 4 ms 4972 KB n=12
27 Correct 4 ms 5100 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4972 KB n=5
2 Correct 4 ms 5100 KB n=100
3 Correct 3 ms 5100 KB n=100
4 Correct 4 ms 5100 KB n=100
5 Correct 4 ms 5100 KB n=100
6 Correct 3 ms 5100 KB n=100
7 Correct 3 ms 5100 KB n=100
8 Correct 4 ms 5100 KB n=100
9 Correct 3 ms 5100 KB n=100
10 Correct 4 ms 5120 KB n=100
11 Correct 4 ms 5100 KB n=100
12 Correct 4 ms 5228 KB n=100
13 Correct 4 ms 5100 KB n=100
14 Correct 4 ms 5100 KB n=100
15 Correct 4 ms 5100 KB n=100
16 Correct 4 ms 5100 KB n=100
17 Correct 4 ms 5100 KB n=100
18 Correct 4 ms 5100 KB n=100
19 Correct 4 ms 5100 KB n=100
20 Correct 4 ms 5100 KB n=100
21 Correct 3 ms 5100 KB n=100
22 Correct 4 ms 5100 KB n=100
23 Correct 4 ms 5100 KB n=100
24 Correct 4 ms 5100 KB n=100
25 Correct 3 ms 5100 KB n=100
26 Correct 4 ms 4972 KB n=12
27 Correct 4 ms 5100 KB n=100
28 Correct 4 ms 5100 KB n=500
29 Correct 4 ms 5100 KB n=500
30 Correct 5 ms 5100 KB n=500
31 Correct 5 ms 5100 KB n=500
32 Correct 5 ms 5100 KB n=500
33 Correct 5 ms 5100 KB n=500
34 Correct 5 ms 5100 KB n=500
35 Correct 5 ms 5100 KB n=500
36 Correct 4 ms 5100 KB n=500
37 Correct 4 ms 5100 KB n=500
38 Correct 5 ms 5232 KB n=500
39 Correct 4 ms 5100 KB n=500
40 Correct 4 ms 5100 KB n=500
41 Correct 4 ms 5100 KB n=500
42 Correct 4 ms 5100 KB n=500
43 Correct 5 ms 5100 KB n=500
44 Correct 5 ms 5100 KB n=500
45 Correct 6 ms 5100 KB n=500
46 Correct 5 ms 5100 KB n=500
47 Correct 5 ms 5100 KB n=500
48 Correct 5 ms 5100 KB n=500
49 Correct 5 ms 5100 KB n=500
50 Correct 4 ms 5100 KB n=500
51 Correct 5 ms 5100 KB n=500
52 Correct 5 ms 5356 KB n=500
53 Correct 5 ms 5100 KB n=500
54 Correct 5 ms 5228 KB n=500
55 Correct 4 ms 5100 KB n=278
56 Correct 5 ms 5228 KB n=500
57 Correct 4 ms 5228 KB n=500
58 Correct 4 ms 5100 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4972 KB n=5
2 Correct 4 ms 5100 KB n=100
3 Correct 3 ms 5100 KB n=100
4 Correct 4 ms 5100 KB n=100
5 Correct 4 ms 5100 KB n=100
6 Correct 3 ms 5100 KB n=100
7 Correct 3 ms 5100 KB n=100
8 Correct 4 ms 5100 KB n=100
9 Correct 3 ms 5100 KB n=100
10 Correct 4 ms 5120 KB n=100
11 Correct 4 ms 5100 KB n=100
12 Correct 4 ms 5228 KB n=100
13 Correct 4 ms 5100 KB n=100
14 Correct 4 ms 5100 KB n=100
15 Correct 4 ms 5100 KB n=100
16 Correct 4 ms 5100 KB n=100
17 Correct 4 ms 5100 KB n=100
18 Correct 4 ms 5100 KB n=100
19 Correct 4 ms 5100 KB n=100
20 Correct 4 ms 5100 KB n=100
21 Correct 3 ms 5100 KB n=100
22 Correct 4 ms 5100 KB n=100
23 Correct 4 ms 5100 KB n=100
24 Correct 4 ms 5100 KB n=100
25 Correct 3 ms 5100 KB n=100
26 Correct 4 ms 4972 KB n=12
27 Correct 4 ms 5100 KB n=100
28 Correct 4 ms 5100 KB n=500
29 Correct 4 ms 5100 KB n=500
30 Correct 5 ms 5100 KB n=500
31 Correct 5 ms 5100 KB n=500
32 Correct 5 ms 5100 KB n=500
33 Correct 5 ms 5100 KB n=500
34 Correct 5 ms 5100 KB n=500
35 Correct 5 ms 5100 KB n=500
36 Correct 4 ms 5100 KB n=500
37 Correct 4 ms 5100 KB n=500
38 Correct 5 ms 5232 KB n=500
39 Correct 4 ms 5100 KB n=500
40 Correct 4 ms 5100 KB n=500
41 Correct 4 ms 5100 KB n=500
42 Correct 4 ms 5100 KB n=500
43 Correct 5 ms 5100 KB n=500
44 Correct 5 ms 5100 KB n=500
45 Correct 6 ms 5100 KB n=500
46 Correct 5 ms 5100 KB n=500
47 Correct 5 ms 5100 KB n=500
48 Correct 5 ms 5100 KB n=500
49 Correct 5 ms 5100 KB n=500
50 Correct 4 ms 5100 KB n=500
51 Correct 5 ms 5100 KB n=500
52 Correct 5 ms 5356 KB n=500
53 Correct 5 ms 5100 KB n=500
54 Correct 5 ms 5228 KB n=500
55 Correct 4 ms 5100 KB n=278
56 Correct 5 ms 5228 KB n=500
57 Correct 4 ms 5228 KB n=500
58 Correct 4 ms 5100 KB n=500
59 Correct 8 ms 5484 KB n=2000
60 Correct 9 ms 5612 KB n=2000
61 Correct 9 ms 5612 KB n=2000
62 Correct 9 ms 5612 KB n=2000
63 Correct 8 ms 5484 KB n=2000
64 Correct 11 ms 5612 KB n=2000
65 Correct 9 ms 5484 KB n=2000
66 Correct 9 ms 5612 KB n=2000
67 Correct 9 ms 5484 KB n=2000
68 Correct 9 ms 5612 KB n=2000
69 Correct 7 ms 5484 KB n=2000
70 Correct 7 ms 5484 KB n=2000
71 Correct 7 ms 5484 KB n=2000
72 Correct 7 ms 5484 KB n=2000
73 Correct 8 ms 5484 KB n=2000
74 Correct 8 ms 5484 KB n=1844
75 Correct 8 ms 5484 KB n=2000
76 Correct 9 ms 5484 KB n=2000
77 Correct 9 ms 5484 KB n=2000
78 Correct 9 ms 5484 KB n=2000
79 Correct 8 ms 5484 KB n=2000
80 Correct 9 ms 5632 KB n=2000
81 Correct 9 ms 5612 KB n=2000
82 Correct 8 ms 5484 KB n=2000
83 Correct 9 ms 5612 KB n=2000
84 Correct 9 ms 5484 KB n=2000
85 Correct 9 ms 5612 KB n=2000
86 Correct 9 ms 5612 KB n=2000
87 Correct 10 ms 5484 KB n=2000
88 Correct 9 ms 5612 KB n=2000
89 Correct 8 ms 5612 KB n=2000
90 Correct 9 ms 5612 KB n=2000
91 Correct 7 ms 5484 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4972 KB n=5
2 Correct 4 ms 5100 KB n=100
3 Correct 3 ms 5100 KB n=100
4 Correct 4 ms 5100 KB n=100
5 Correct 4 ms 5100 KB n=100
6 Correct 3 ms 5100 KB n=100
7 Correct 3 ms 5100 KB n=100
8 Correct 4 ms 5100 KB n=100
9 Correct 3 ms 5100 KB n=100
10 Correct 4 ms 5120 KB n=100
11 Correct 4 ms 5100 KB n=100
12 Correct 4 ms 5228 KB n=100
13 Correct 4 ms 5100 KB n=100
14 Correct 4 ms 5100 KB n=100
15 Correct 4 ms 5100 KB n=100
16 Correct 4 ms 5100 KB n=100
17 Correct 4 ms 5100 KB n=100
18 Correct 4 ms 5100 KB n=100
19 Correct 4 ms 5100 KB n=100
20 Correct 4 ms 5100 KB n=100
21 Correct 3 ms 5100 KB n=100
22 Correct 4 ms 5100 KB n=100
23 Correct 4 ms 5100 KB n=100
24 Correct 4 ms 5100 KB n=100
25 Correct 3 ms 5100 KB n=100
26 Correct 4 ms 4972 KB n=12
27 Correct 4 ms 5100 KB n=100
28 Correct 4 ms 5100 KB n=500
29 Correct 4 ms 5100 KB n=500
30 Correct 5 ms 5100 KB n=500
31 Correct 5 ms 5100 KB n=500
32 Correct 5 ms 5100 KB n=500
33 Correct 5 ms 5100 KB n=500
34 Correct 5 ms 5100 KB n=500
35 Correct 5 ms 5100 KB n=500
36 Correct 4 ms 5100 KB n=500
37 Correct 4 ms 5100 KB n=500
38 Correct 5 ms 5232 KB n=500
39 Correct 4 ms 5100 KB n=500
40 Correct 4 ms 5100 KB n=500
41 Correct 4 ms 5100 KB n=500
42 Correct 4 ms 5100 KB n=500
43 Correct 5 ms 5100 KB n=500
44 Correct 5 ms 5100 KB n=500
45 Correct 6 ms 5100 KB n=500
46 Correct 5 ms 5100 KB n=500
47 Correct 5 ms 5100 KB n=500
48 Correct 5 ms 5100 KB n=500
49 Correct 5 ms 5100 KB n=500
50 Correct 4 ms 5100 KB n=500
51 Correct 5 ms 5100 KB n=500
52 Correct 5 ms 5356 KB n=500
53 Correct 5 ms 5100 KB n=500
54 Correct 5 ms 5228 KB n=500
55 Correct 4 ms 5100 KB n=278
56 Correct 5 ms 5228 KB n=500
57 Correct 4 ms 5228 KB n=500
58 Correct 4 ms 5100 KB n=500
59 Correct 8 ms 5484 KB n=2000
60 Correct 9 ms 5612 KB n=2000
61 Correct 9 ms 5612 KB n=2000
62 Correct 9 ms 5612 KB n=2000
63 Correct 8 ms 5484 KB n=2000
64 Correct 11 ms 5612 KB n=2000
65 Correct 9 ms 5484 KB n=2000
66 Correct 9 ms 5612 KB n=2000
67 Correct 9 ms 5484 KB n=2000
68 Correct 9 ms 5612 KB n=2000
69 Correct 7 ms 5484 KB n=2000
70 Correct 7 ms 5484 KB n=2000
71 Correct 7 ms 5484 KB n=2000
72 Correct 7 ms 5484 KB n=2000
73 Correct 8 ms 5484 KB n=2000
74 Correct 8 ms 5484 KB n=1844
75 Correct 8 ms 5484 KB n=2000
76 Correct 9 ms 5484 KB n=2000
77 Correct 9 ms 5484 KB n=2000
78 Correct 9 ms 5484 KB n=2000
79 Correct 8 ms 5484 KB n=2000
80 Correct 9 ms 5632 KB n=2000
81 Correct 9 ms 5612 KB n=2000
82 Correct 8 ms 5484 KB n=2000
83 Correct 9 ms 5612 KB n=2000
84 Correct 9 ms 5484 KB n=2000
85 Correct 9 ms 5612 KB n=2000
86 Correct 9 ms 5612 KB n=2000
87 Correct 10 ms 5484 KB n=2000
88 Correct 9 ms 5612 KB n=2000
89 Correct 8 ms 5612 KB n=2000
90 Correct 9 ms 5612 KB n=2000
91 Correct 7 ms 5484 KB n=2000
92 Correct 1209 ms 54444 KB n=200000
93 Correct 2115 ms 60932 KB n=200000
94 Correct 2120 ms 65536 KB n=200000
95 Correct 1175 ms 53984 KB n=200000
96 Correct 1121 ms 54112 KB n=200000
97 Correct 2158 ms 59832 KB n=200000
98 Correct 1176 ms 54240 KB n=200000
99 Correct 1512 ms 54508 KB n=200000
100 Correct 1151 ms 54244 KB n=200000
101 Correct 2081 ms 67012 KB n=200000
102 Correct 707 ms 55276 KB n=200000
103 Correct 700 ms 55404 KB n=200000
104 Correct 690 ms 55276 KB n=200000
105 Correct 697 ms 55788 KB n=200000
106 Correct 687 ms 55788 KB n=200000
107 Correct 690 ms 55648 KB n=200000
108 Correct 1394 ms 54252 KB n=200000
109 Correct 1347 ms 54380 KB n=200000
110 Correct 1360 ms 54252 KB n=200000
111 Correct 1057 ms 53728 KB n=200000
112 Correct 2061 ms 65804 KB n=200000
113 Correct 2120 ms 59880 KB n=200000
114 Correct 1058 ms 53728 KB n=200000
115 Correct 2115 ms 56796 KB n=200000
116 Correct 1144 ms 54496 KB n=200000
117 Correct 2105 ms 66284 KB n=200000
118 Correct 2136 ms 58336 KB n=200000
119 Correct 1177 ms 54240 KB n=200000
120 Correct 1900 ms 66068 KB n=200000
121 Correct 1853 ms 66028 KB n=200000
122 Correct 1924 ms 66388 KB n=200000
123 Correct 692 ms 55516 KB n=200000
124 Correct 421 ms 20076 KB n=25264