제출 #443899

#제출 시각아이디문제언어결과실행 시간메모리
443899NintsiChkhaidzeBirthday gift (IZhO18_treearray)C++14
0 / 100
35 ms48232 KiB
#include <iostream> #include <set> #include <vector> #define pb push_back using namespace std; const int N = 200005; int a[N],dp[N],d[20][N],n; vector <int> v[N]; set <int> A[N],B[N]; void dfs(int x,int par){ dp[x] = dp[par] + 1; d[0][x] = par; for (int i = 0; i < v[x].size(); i++) if (v[x][i] != par) dfs(v[x][i],x); } int lca(int x,int y){ if (dp[x] > dp[y]) swap(x,y); for (int i = 18; i >= 0; i--) if (dp[d[i][y]] >= dp[x]) y = d[i][y]; if (x == y) return x; for (int i = 18; i >= 0; i--) if (d[i][x] != d[i][y]) x = d[i][x],y = d[i][y]; return d[0][x]; } void upd(int ind,bool val){ int y = 0,x = 0; if (ind) x = a[ind]; if (ind && ind < n) y = lca(a[ind],a[ind + 1]); if (!val){ if (ind) A[x].erase(A[x].find(ind)); if (ind && ind < n) B[y].erase(B[y].find(ind)); } else{ if (ind) A[x].insert(ind); if (ind && ind < n) B[y].insert(ind); } } int main (){ ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL); int m,q; cin>>n>>m>>q; for (int i = 1; i < n; i++){ int a,b; cin>>a>>b; v[a].pb(b),v[b].pb(a); } for (int i = 1; i <= m; i++) cin>>a[i]; dfs(1,1); for (int j = 1; j <= 18; j++) for (int i = 1; i <= n; i++) d[j][i] = d[j - 1][d[j - 1][i]]; for (int i = 1; i <= n; i++) upd(i,1); while(q--){ int tp; cin>>tp; if (tp == 1){ int pos,val; cin>>pos>>val; upd(pos - 1, 0); upd(pos, 0); a[pos] = val; upd(pos - 1, 1),upd(pos, 1); } else{ int l,r,val; cin>>l>>r>>val; int x = -1,y = -1; set <int> :: iterator it; if (A[val].size()){ it = A[val].lower_bound(l); if (it != A[val].end()) x = *it; } if (B[val].size()){ it = B[val].lower_bound(l); if (it != B[val].end()) y = *it; } if (y >= l && y < r) cout<<y<<" "<<y + 1<<"\n"; else if (x >= l && x <= r) cout<<x<<" "<<x<<"\n"; else cout<<-1<<" "<<-1<<"\n"; } } }

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

treearray.cpp: In function 'void dfs(int, int)':
treearray.cpp:13:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for (int i = 0; i < v[x].size(); i++)
      |                     ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...