제출 #865154

#제출 시각아이디문제언어결과실행 시간메모리
865154vjudge1Birthday gift (IZhO18_treearray)C++17
12 / 100
1 ms604 KiB
/// tree bends in youth /// 24 .10.2023 /// success is doing same thing in every single day!!! #include <bits/stdc++.h> #define ll long long #define pb push_back #define all(x) x.begin(), x.end() #define F first #define S second using namespace std; const ll N =100+ 5; const ll NN =2e6 + 5; const ll INF = -1e1; const ll MOD = 1e9 + 7; const ll LG = 18; const ll k = 316; vector <int> g[101]; int tin[N],tout[N],a[N],cnt,used[N]; int p[N][16]; void dfs(int v){ cnt++; used[v] = 1; tin[v] = cnt; for(int to : g[v]){ if(used[to] == 0){ p[to][0] = v; dfs(to); } } tout[v] = cnt; } bool upper(int x,int y){ if(tin[x] <= tin[y] && tout[x] >= tout[y])return 1; else return 0; } int lca(int x,int y){ if(upper(x,y) == 1){ return x; } if(upper(y,x) == 1){ return y; } for(int j = 6;j >= 0;j--){ int h = p[x][j]; if(upper(h,y) == 0){ x = h; } } return p[x][0]; } void solve(){ int n,m,q; cin >> n >> m >> q; for(int i = 1;i < n;i++){ int u,v; cin >> u >> v; g[u].pb(v); g[v].pb(u); } p[1][0] = 1; dfs(1); for(int i = 1;i <= 6;i++){ for(int j = 1;j <= n;j++){ p[j][i] = p[p[j][i - 1]][i - 1]; } } for(int i = 1;i <= m;i++){ cin >> a[i]; } bool was = 1; while(q--){ int tp,l,r,x; cin >> tp >> l >> r; if(tp == 1){ a[l] = r; } else{ cin >> x; bool ok = 0; for(int j = l;j <= r;j++){ int lc = a[j]; if(lc == x){ cout << j << " " << j << '\n'; ok = 1; break; } int i = j + 1; while(i <= r){ int lcc= lca(lc,a[i]); if(lcc == x){ cout << j << ' ' << i << '\n'; ok = 1; break; } lc = lcc; i++; } if(ok)break; } if(!ok)cout << "-1 -1\n"; was = 0; } } } main (){ ios_base::sync_with_stdio(0); cin.tie(0); // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); ll abd= 1; // cin >> abd; for(ll i = 1;i <= abd;i++){ // cout << "Case " << i << ":\n"; solve(); } }

컴파일 시 표준 에러 (stderr) 메시지

treearray.cpp: In function 'void solve()':
treearray.cpp:71:10: warning: variable 'was' set but not used [-Wunused-but-set-variable]
   71 |     bool was = 1;
      |          ^~~
treearray.cpp: At global scope:
treearray.cpp:107:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  107 | main (){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...