제출 #501507

#제출 시각아이디문제언어결과실행 시간메모리
501507tmn2005Birthday gift (IZhO18_treearray)C++17
100 / 100
1373 ms212392 KiB
#include<bits/stdc++.h> using namespace std; #define ar array #define fr first #define sc second #define vec vector #define ret return #define ins insert #define mk make_pair #define pb push_back #define pf push_front #define pob pop_back #define pof pop_front #define int long long #define pii pair<int,int> #define all(s) s.begin(), s.end() #define allr(s) s.rbegin(), s.rend() #define NeedForSpeed ios::sync_with_stdio(0),cin.tie(0); #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> const int N=1e6+12,INF=1e9,mod = 1e9+7; bool iswowel(char n){ n = toupper(n); if(n == 'A' || n == 'O' || n == 'U' || n == 'E' || n == 'I') return true; else return false;} int n,m,k,x,y,l,ll,r,o,ans,res,timer,ok,mx,mn = INF; int a[N], tin[N], tout[N]; vec<int>g[N]; int up[N][30]; set<int>s[N], ss[N]; void dfs(int v, int pred){ tin[v] = ++timer; up[v][0] = pred; for(int i=1; i<=22; i++) up[v][i] = up[up[v][i-1]][i-1]; for(int to : g[v]){ if(to != pred){ dfs(to, v); } } tout[v] = ++timer; } bool upper(int a, int b){ ret tin[a] <= tin[b] && tout[b] <= tout[a]; } int lca(int a, int b){ if(upper(a, b))ret a; if(upper(b, a))ret b; for(int i=22; i>=0; i--){ if(!upper(up[a][i], b)) a = up[a][i]; } ret up[a][0]; } map<int, int>mp; main(){ NeedForSpeed cin>>m>>n>>o; m--; while(m--){ cin>>x>>y; g[x].pb(y); g[y].pb(x); } dfs(1,1); for(int i=1; i<=n; i++){ cin>>a[i]; ss[a[i]].ins(i); } for(int i=1; i<=n; i++) s[lca(a[i], a[i+1])].ins(i); while(o--){ cin>>ok; if(ok == 1){ cin>>l>>r; ss[a[l]].erase(l); s[lca(a[l], a[l+1])].erase(l); s[lca(a[l-1], a[l])].erase(l-1); a[l] = r; ss[a[l]].ins(l); if(l < n)s[lca(a[l], a[l+1])].ins(l); if(1 < l)s[lca(a[l-1], a[l])].ins(l-1); } else{ ans = -1, res = -1; cin>>l>>r>>x; auto it = ss[x].lower_bound(l); if(it != ss[x].end() && *it <= r)ans = *it, res = *it; it = s[x].lower_bound(l); if(it != s[x].end() && *it < r)ans = *it, res = *it+1; cout<<ans<<" "<<res<<endl; } } return 0; }

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

treearray.cpp:63:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   63 | 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...