답안 #375913

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
375913 2021-03-10T09:07:48 Z SavicS Pictionary (COCI18_pictionary) C++14
컴파일 오류
0 ms 0 KB
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define fb(i,b,a) for(int i=b;i>=a;i--)

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 100005;
const int inf = 1e9 + 5;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// os.order_of_key(k) the number of elements in the os less than k
// *os.find_by_order(k)  print the k-th smallest number in os(0-based)

int n, m, q;

vector<pii> g[maxn];

int sz[maxn];
int par[maxn];
int findpar(int x){
	if(x == par[x])return x;
	return par[x] = findpar(par[x]);
}
void unite(int x, int y){
	int a = findpar(x);
	int b = findpar(y);
	if(sz[a] > sz[b])swap(a, b);
	par[b] = a;
	sz[a] += sz[b];
}
void init(){
	ff(i,1,n){
		par[i] = i;
		sz[i] = 1;
	}
}

int d[maxn];
int deda[maxn][20];
int mx[maxn][20];
void dfs(int v, int p, int pw){
	deda[v][0] = p;
	mx[v][0] = pw;
	ff(i,1,19){
		deda[v][i] = deda[deda[v][i - 1]][i - 1];
		mx[v][i] = max(mx[v][i - 1], mx[deda[v][i - 1]][i - 1]);
	}
	for(auto c : g[v]){
		int u = c.fi;
		int w = c.se;
		if(u != p){
			d[u] = d[v] + 1;
			dfs(u, v, w);
		}
	}
}

int lca(int x, int y){
	if(d[x] < d[y])swap(x, y);
	fb(i,19,0){
		if((d[x] - d[y]) & (1 << i))x = deda[x][i];
	}
	fb(i,19,0){
		if(deda[x][i] != deda[y][i]){
			x = deda[x][i];
			y = deda[y][i];
		}
	}
	return (x == y ? x : sdeda[x][0]);
}

int calc(int x, int y){
	int najv = 0;
	fb(i,19,0){
		if(y & (1 << i)){
			najv = max(najv, mx[x][i]);
			x = deda[x][i];
		}
	}
	return najv;
}

int main()
{
   	ios::sync_with_stdio(false);
   	cout.tie(nullptr);
  	cin.tie(nullptr);
	cin >> n >> m >> q;
	init();
	fb(i,m,1){
		for(int j=2*i;j<=n;j+=i){
			if(findpar(i) == findpar(j))continue;
			unite(i, j);
			g[i].pb({j, m - i + 1});
			g[j].pb({i, m - i + 1});
		}
	}
	dfs(1, 0, 0);
	while(q--){
		int a, b;
		cin >> a >> b;
		int lc = lca(a, b);
		int ans = max(calc(a, d[a] - d[lc]), calc(b, d[b] - d[lc]));
		cout << ans << endl;
	}	
   	return 0;
}
/**



// probati bojenje sahovski ili slicno

**/


Compilation message

pictionary.cpp: In function 'int lca(int, int)':
pictionary.cpp:82:23: error: 'sdeda' was not declared in this scope; did you mean 'deda'?
   82 |  return (x == y ? x : sdeda[x][0]);
      |                       ^~~~~
      |                       deda