Submission #861232

# Submission time Handle Problem Language Result Execution time Memory
861232 2023-10-15T17:03:52 Z Trisanu_Das Birthday gift (IZhO18_treearray) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define mp make_pair
#define ff first
#define ss second
#define pii pair < int, int >

const int maxn = (int) 1e5 + 10;
using namespace std;
int par[20][200200], lift[200200];
vector<int> adj[200200];
int n, m, q;
 
void dfs(int u, int p){
	par[0][v] = p;
	for(int i = 1; i < 19; i++) par[i][u] = par[i - 1][par[i - 1][u]];
	lift[u] = lift[p] + 1;
	for(auto v : u) if(v != p) dfs(v, u);
}

int a[200200];
set<int> S[200200];
set<int> T[200200];
 
int lca(int u, int v){
	if(lift[u] < lift[v]) swap(u, v);
	for(int i = 18; i > -1; i--) if(lift[u] - (1 << i) >= lift[v]) u = par[i][u];
	if(u == v) return u;
	for(int i = 18; i > -1; i--){
		if(par[i][u] != par[i][v]) {
			u = par[i][u];
			v = par[i][v];
		}
	}
	return par[0][v];
}

int main(){
	cin >> n >> m >> q;
	for(int i = 1, x, y; i < n; i++){
		cin >> x >> y;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	for(int i = 1; i < m + 1; i++) cin >> a[i];
	dfs(1, 0);
	for(int i = 1; i < m + 1; i++) S[a[i]].insert(i);
	for(int i = 2; i < m + 1; i++) T[lca(a[i], a[i - 1])].insert(i);
	for(int i = 1; i < n + 1; i++) {
		S[i].insert(INT_MAX);
		T[i].insert(INT_MAX);
	}
	while(q--){
        int op, l, r, v; cin >> op;
		if(ty == 1){
			cin >> l >> v;
			S[a[l]].erase(l);
			if(l > 1) T[lca(a[l], a[l - 1])].erase(l);
			if(l < m) T[lca(a[l], a[l + 1])].erase(l + 1);
			a[l] = v;
			S[a[l]].insert(l);
			if(l > 1) T[lca(a[l], a[l-1])].insert(l);
			if(l < m) T[lca(a[l], a[l+1])].insert(l + 1);
		}else{
			cin >> l >> r >> v;
			int d = *S[v].lower_bound(l), e = *T[v].lower_bound(l+1);
			if(d <= r) cout << d << ' ' << d << '\n';
			else if(e <= r) cout << e - 1 << ' ' << e << '\n';
			else cout << "-1 -1\n";
		}
	}
}

Compilation message

treearray.cpp: In function 'void dfs(int, int)':
treearray.cpp:16:9: error: 'v' was not declared in this scope
   16 |  par[0][v] = p;
      |         ^
treearray.cpp:19:15: error: 'begin' was not declared in this scope
   19 |  for(auto v : u) if(v != p) dfs(v, u);
      |               ^
treearray.cpp:19:15: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from treearray.cpp:1:
/usr/include/c++/10/valarray:1224:5: note:   'std::begin'
 1224 |     begin(const valarray<_Tp>& __va)
      |     ^~~~~
In file included from /usr/include/c++/10/filesystem:46,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from treearray.cpp:1:
/usr/include/c++/10/bits/fs_dir.h:549:3: note:   'std::filesystem::__cxx11::begin'
  549 |   begin(recursive_directory_iterator __iter) noexcept
      |   ^~~~~
treearray.cpp:19:15: error: 'end' was not declared in this scope
   19 |  for(auto v : u) if(v != p) dfs(v, u);
      |               ^
treearray.cpp:19:15: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from treearray.cpp:1:
/usr/include/c++/10/valarray:1244:5: note:   'std::end'
 1244 |     end(const valarray<_Tp>& __va)
      |     ^~~
In file included from /usr/include/c++/10/filesystem:46,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from treearray.cpp:1:
/usr/include/c++/10/bits/fs_dir.h:554:3: note:   'std::filesystem::__cxx11::end'
  554 |   end(recursive_directory_iterator) noexcept
      |   ^~~
treearray.cpp: In function 'int main()':
treearray.cpp:56:6: error: 'ty' was not declared in this scope; did you mean 'tm'?
   56 |   if(ty == 1){
      |      ^~
      |      tm