Submission #484011

#TimeUsernameProblemLanguageResultExecution timeMemory
484011uroskBirthday gift (IZhO18_treearray)C++14
100 / 100
974 ms104732 KiB
//https://oj.uz/problem/view/IZhO18_treearray // __builtin_popcount(x) broj bitova // __builtin_popcountll(x) long long #include "bits/stdc++.h" #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> #define ld double #define ll long long #define ull unsigned long long #define llinf 100000000000000000LL // 10^17 #define iinf 2000000000 // 2*10^9 #define pb push_back #define popb pop_back #define fi first #define sc second #define endl '\n' #define pii pair<int,int> #define pll pair<ll,ll> #define pld pair<ld,ld> #define sz(a) int(a.size()) #define all(a) a.begin(),a.end() #define rall(a) a.begin(),a.end(),greater<int>() #define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());} #define pi 3.14159265358979323846 #define here cerr<<"---------------------------\n" #define ceri(a,l,r) {for(ll i = l;i<=r;i++) cerr<<a[i]<< " ";cerr<<endl;} #define yes cout<<"YES"<<endl #define no cout<<"NO"<<endl using namespace std; using namespace __gnu_pbds; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; void setIO(string inoutname) { freopen((inoutname+".in").c_str(),"r",stdin); freopen((inoutname+".out").c_str(),"w",stdout); } #define mod 1 ll gcd(ll a, ll b) { if(b==0) return a; if(a==0) return b; if(a>=b) return gcd(a%b,b); return gcd(a,b%a); } ll lcm(ll a,ll b){ return (a/gcd(a,b))*b; } ll add(ll a,ll b){ a+=b; a+=mod; if(a>=mod) a%=mod; return a; } ll mul(ll a,ll b){return(a*b)%mod;} #define maxn 200005 #define lg 25 ll n,m,q; vector<ll> g[maxn]; set<ll> v[maxn]; set<ll> w[maxn]; ll a[maxn]; ll b[maxn]; ll in[maxn]; ll out[maxn]; ll st[maxn][lg]; ll ti = 1; void dfs(ll u,ll par){ st[u][0] = par; in[u] = ti; ti++; for(ll s : g[u]){ if(s==par) continue; dfs(s,u); } out[u] = ti; ti++; } bool in_t(ll v,ll u){return in[u]<=in[v]&&out[u]>=out[v];} void init(){ for(ll j = 1;j<lg;j++){ for(ll i = 1;i<=n;i++) st[i][j] = st[st[i][j-1]][j-1]; } } ll lca(ll u,ll v){ if(in_t(v,u)) return u; if(in_t(u,v)) return v; for(ll j = lg-1;j>=0;j--){ if(!in_t(v,st[u][j])) u = st[u][j]; } return st[u][0]; } void tc(){ ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0); cin >> n >> m >> q; for(ll i = 1;i<=n-1;i++){ ll x,y; cin >> x >> y; g[x].pb(y); g[y].pb(x); } for(ll i = 1;i<=m;i++) cin >> a[i]; dfs(1,1); init(); for(ll i = 1;i<=m-1;i++){ w[a[i]].insert(i); b[i] = lca(a[i],a[i+1]); v[b[i]].insert(i); } w[a[m]].insert(m); while(q--){ ll tip; cin >> tip; if(tip==1){ ll i,x; cin >> i >> x; w[a[i]].erase(w[a[i]].find(i)); a[i] = x; w[a[i]].insert(i); if(i>1){ v[b[i-1]].erase(v[b[i-1]].find(i-1)); b[i-1] = lca(a[i-1],a[i]); v[b[i-1]].insert(i-1); } if(i<m){ v[b[i]].erase(v[b[i]].find(i)); b[i] = lca(a[i],a[i+1]); v[b[i]].insert(i); } }else{ ll l,r,x; cin >> l >> r >> x; auto it = v[x].lower_bound(l); if(it!=v[x].end()&&*it<r){ cout<<*it<< " "<<*it+1<<endl; }else if(!w[x].empty()){ auto j = w[x].lower_bound(l); if(j!=w[x].end()&&*j<=r) cout<<*j<< " "<<*j<<endl; else cout<<-1<< " "<<-1<<endl; }else cout<<-1<< " "<<-1<<endl; } } } int main(){ ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0); //setIO("lol"); int t; t = 1; while(t--){ tc(); } return 0; } /* 5 4 4 1 2 3 1 3 4 5 3 4 5 2 3 2 1 3 1 1 3 5 2 3 4 5 2 1 3 1 */

Compilation message (stderr)

treearray.cpp: In function 'void setIO(std::string)':
treearray.cpp:36:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |  freopen((inoutname+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
treearray.cpp:37:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |      freopen((inoutname+".out").c_str(),"w",stdout);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...