結果

問題 No.1030 だんしんぐぱーりない
ユーザー HIR180HIR180
提出日時 2020-04-17 21:49:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 230 ms / 2,000 ms
コード長 3,431 bytes
コンパイル時間 5,536 ms
コンパイル使用メモリ 231,016 KB
実行使用メモリ 45,548 KB
最終ジャッジ日時 2023-07-27 00:06:43
合計ジャッジ時間 11,403 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
39,076 KB
testcase_01 AC 16 ms
38,976 KB
testcase_02 AC 15 ms
38,932 KB
testcase_03 AC 16 ms
38,968 KB
testcase_04 AC 16 ms
38,936 KB
testcase_05 AC 161 ms
44,320 KB
testcase_06 AC 133 ms
43,244 KB
testcase_07 AC 90 ms
40,876 KB
testcase_08 AC 98 ms
41,196 KB
testcase_09 AC 133 ms
44,384 KB
testcase_10 AC 64 ms
39,924 KB
testcase_11 AC 136 ms
41,860 KB
testcase_12 AC 133 ms
43,372 KB
testcase_13 AC 120 ms
43,088 KB
testcase_14 AC 163 ms
43,252 KB
testcase_15 AC 82 ms
39,984 KB
testcase_16 AC 129 ms
42,280 KB
testcase_17 AC 135 ms
44,364 KB
testcase_18 AC 165 ms
43,500 KB
testcase_19 AC 93 ms
40,364 KB
testcase_20 AC 107 ms
41,600 KB
testcase_21 AC 115 ms
42,916 KB
testcase_22 AC 108 ms
41,684 KB
testcase_23 AC 126 ms
41,508 KB
testcase_24 AC 107 ms
40,520 KB
testcase_25 AC 122 ms
41,524 KB
testcase_26 AC 83 ms
39,572 KB
testcase_27 AC 94 ms
39,796 KB
testcase_28 AC 161 ms
42,776 KB
testcase_29 AC 109 ms
43,360 KB
testcase_30 AC 100 ms
41,772 KB
testcase_31 AC 109 ms
41,384 KB
testcase_32 AC 142 ms
43,228 KB
testcase_33 AC 148 ms
43,916 KB
testcase_34 AC 71 ms
40,004 KB
testcase_35 AC 224 ms
45,548 KB
testcase_36 AC 230 ms
45,464 KB
testcase_37 AC 216 ms
45,464 KB
testcase_38 AC 218 ms
45,536 KB
testcase_39 AC 213 ms
45,480 KB
testcase_40 AC 15 ms
39,004 KB
testcase_41 AC 16 ms
39,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//Let's join Kaede Takagaki Fan Club !!
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
template<class T>
void dmp(T a){
	rep(i,a.size()) cout << a[i] << " ";
	cout << endl;
}
template<class T>
bool chmax(T&a, T b){
	if(a < b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a, T b){
	if(a > b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const int mod = 1000000007;
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}

#define SZ 100005
int n, k, q;
int mx[100005];
P ar[SZ*2]={};
int pos[SZ]={},id=0,up[SZ],dep[SZ];
P mn[20][SZ*2]={};
int sz[SZ*2]={};
vector<int>edge[SZ];
struct LCA{
	//SZは元の木の頂点数より大
	//外部でedge[]に隣接状況を持って置く必要あり
	
	void dfs(int v,int u,int d){
		pos[v] = id; up[v] = u; dep[v] = d;
		ar[id++] = mp(d,v);
		for(int i=0;i<edge[v].size();i++){
			if(edge[v][i] == u) continue;
			dfs(edge[v][i],v,d+1);
			ar[id++] = mp(d,v);
		}
	}
	void prepare(){
		dfs(1,-1,0);
		for(int i=0;i<id;i++) mn[0][i] = ar[i];
		for(int j=0;j<19;j++){
			for(int i=0;i<id;i++){
				if(i+(1<<j) >= id) mn[j+1][i] = mn[j][i];
				else mn[j+1][i] = min(mn[j][i], mn[j][i+(1<<j)]);
			}
		}
		for(int i=1;i<SZ*2;i++){
			for(int j=0;j<20;j++){
				if((1<<j) <= i && i <= (2<<j)){
					sz[i] = j;
					break;
				}
			}
		}
	}
	int get(int a,int b){
		if(a == 0) return b;
		if(b == 0) return a;
		
		int len = max(pos[a],pos[b]) - min(pos[a],pos[b]) + 1;
		int ty = sz[len];
		P p = min(mn[ty][min(pos[a],pos[b])], mn[ty][max(pos[a],pos[b])-(1<<ty)+1]);
		return p.second;
	}
}kaede;

struct RMQ{
	#define s (1<<18)
	int seg[s];
	void update(int k,int a){
		k+=s/2-1; seg[k]=a;
		while(k>0){
			k=(k-1)/2;
			seg[k]=kaede.get(seg[k*2+1],seg[k*2+2]);
		}
	}
	int query(int a,int b,int k,int l,int r){
		if(r<a || b<l) return 0;
		if(a<=l && r<=b) return seg[k];
		else{
			int vl=query(a,b,k*2+1,l,(l+r)/2);
			int vr=query(a,b,k*2+2,(l+r)/2+1,r);
			return kaede.get(vl,vr);
		}
	}
}rmq;
int aa[100005];

void dfs2(int v,int u,int m){
	chmax(mx[v], m);
	for(auto to:edge[v]){
		if(to == u) continue;
		dfs2(to, v, mx[v]);
	}
}
int main(){
	scanf("%d%d%d",&n,&k,&q);
	repn(i, n){
		scanf("%d", &mx[i]);
	}
	rep(i, k){
		scanf("%d", &aa[i]);
	}
	rep(i, n-1){
		int a, b; scanf("%d%d", &a, &b);
		edge[a].pb(b);
		edge[b].pb(a);
	}
	kaede.prepare();
	dfs2(1, -1, 0);
	rep(i, k) rmq.update(i, aa[i]);
	
	
	rep(i, q){
		int ty; scanf("%d", &ty);
		if(ty == 1){
			int a, b; scanf("%d%d", &a, &b); a--;
			rmq.update(a, b);
		}
		else{
			int a, b; scanf("%d%d", &a, &b);
			int c = rmq.query(a-1, b-1, 0, 0, s/2-1);
			printf("%d\n", mx[c]);
		}
	}
}
0