Submission #865188

#TimeUsernameProblemLanguageResultExecution timeMemory
865188vjudge1Birthday gift (IZhO18_treearray)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout) #define optimus_prime ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define fxd(x) fixed << setprecision(x) #define all(a) (a.begin() , a.end()) #define popcount(x) __builtin_popcount(x) #define lwb lower_bound #define upb upper_bound #define dl double long #define ll long long #define pb push_back #define sz() size() #define F first #define S second using namespace std; const ll N = 1e5+9; const ll inf=1e9+9; const ll mod=1e9+7; const ll P = 37; const ll L = 30; ll n , m , q , a[N] , tin[N] , tout[N] , timer , h[N] , up[N][L]; vector <int> g[N]; calc(ll cur , ll p , ll len=1){ h[cur]=len; tin[cur]=++timer; up[cur][0]=p; for (int i = 1 ; i <= L ; i++)up[cur][i]=up[up[cur][i-1]][i-1]; for (auto to : g[cur]){ if (to!=p)calc(to , cur , len+1); } tout[cur]=timer; } bool upper(ll a , ll b){ if (tin[a]<=tin[b]&&tout[b]<=tout[a])return 1; return 0; } ll lca(ll a , ll b){ if (upper(a , b))return a; if (upper(b , a))return b; for (int i = L ; i >= 0 ; i--){ if (!upper(up[a][i] , b))a=up[a][i]; } return up[a][0]; } void solve(){ cin >> n >> m >> q; for (int i = 1 ; i < n ; i++){ ll u , v; cin >> u >> v; g[u].pb(v); g[v].pb(u); } for (int i = 1 ; i <= m ; i++)cin >> a[i]; calc(1 , 1); while (q--){ ll tp; cin >> tp; if (tp==1){ ll pos , v; cin >> pos >> v; a[pos]=v; } else { ll l , r , v , ok=0; cin >> l >> r >> v; for (int i = l ; i <= r ; i++){ if (a[i]==v){ cout << i << " " << i << "\n"; ok=1; break; } } if (ok)continue; while (h[a[l]]<=h[v])l++; while (h[a[r]]<=h[v])r--; for (int x = l ; x <= r ; x++){ if (ok)break; for (int y = x ; y <= r ; y++){ ll niga=a[x]; for (int i = x ; i <= y ; i++){ niga=lca(a[i] , niga); if (h[niga]<h[v])break; } if (niga==v){ cout << x << " " << y << "\n"; ok=1; break; } } if (ok)break; } if (!ok)cout << "-1 -1\n"; } } } signed main() { optimus_prime; ll t=1; while (t--)solve(); return 0; }

Compilation message (stderr)

treearray.cpp:28:1: error: ISO C++ forbids declaration of 'calc' with no type [-fpermissive]
   28 | calc(ll cur , ll p , ll len=1){
      | ^~~~
treearray.cpp: In function 'int calc(long long int, long long int, long long int)':
treearray.cpp:37:1: warning: no return statement in function returning non-void [-Wreturn-type]
   37 | }
      | ^