제출 #963416

#제출 시각아이디문제언어결과실행 시간메모리
963416pccBall Machine (BOI13_ballmachine)C++17
16.11 / 100
127 ms45328 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll,ll> #define pii pair<int,int> #define fs first #define sc second #define tlll tuple<ll,ll,ll> const int mxn = 1e5+10; vector<int> tree[mxn]; vector<int> eul; int par[mxn][20],dep[mxn]; int N,Q; int rt; int dp[mxn]; int dfn[mxn]; set<int> st; void dfs(int now){ for(int i = 1;i<20;i++)par[now][i] = par[par[now][i-1]][i-1]; sort(tree[now].begin(),tree[now].end()); for(auto nxt:tree[now]){ dep[nxt] = dep[now]+1; par[nxt][0] = now; dfs(nxt); } dfn[now] = eul.size(); eul.push_back(now); return; } int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>N>>Q; for(int i = 1;i<=N;i++){ int p; cin>>p; par[i][0] = p; tree[p].push_back(i); if(!p)rt = i; } par[rt][0] = rt; dfs(rt); for(int i = 0;i<N;i++)st.insert(i); int C = 0; while(Q--){ int t,k; cin>>t>>k; int lst = 0; assert(C == N-st.size()); if(t == 1){ C += k; while(k--){ lst = *st.begin(); st.erase(st.begin()); dp[eul[lst]] = true; } cout<<eul[lst]<<'\n'; } else{ C--; lst = k; for(int i = 19;i>=0;i--){ if(dp[par[lst][i]])lst = par[lst][i]; } dp[lst] = false; st.insert(dfn[lst]); cout<<dep[k]-dep[lst]<<'\n'; } } return 0; }

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

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from ballmachine.cpp:1:
ballmachine.cpp: In function 'int main()':
ballmachine.cpp:52:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |   assert(C == N-st.size());
      |          ~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...