結果

問題 No.1030 だんしんぐぱーりない
ユーザー HIR180
提出日時 2020-04-17 21:49:32
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 334 ms / 2,000 ms
コード長 3,431 bytes
コンパイル時間 3,673 ms
コンパイル使用メモリ 226,620 KB
最終ジャッジ日時 2025-01-09 19:54:51
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 40
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:141:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  141 |         scanf("%d%d%d",&n,&k,&q);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~
main.cpp:143:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  143 |                 scanf("%d", &mx[i]);
      |                 ~~~~~^~~~~~~~~~~~~~
main.cpp:146:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  146 |                 scanf("%d", &aa[i]);
      |                 ~~~~~^~~~~~~~~~~~~~
main.cpp:149:32: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  149 |                 int a, b; scanf("%d%d", &a, &b);
      |                           ~~~~~^~~~~~~~~~~~~~~~
main.cpp:159:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  159 |                 int ty; scanf("%d", &ty);
      |                         ~~~~~^~~~~~~~~~~
main.cpp:161:40: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  161 |                         int a, b; scanf("%d%d", &a, &b); a--;
      |                                   ~~~~~^~~~~~~~~~~~~~~~
main.cpp:165:40: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  165 |                         int a, b; scanf("%d%d", &a, &b);
      |                                   ~~~~~^~~~~~~~~~~~~~~~

ソースコード

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]);
}
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0