Submission #1209465

#TimeUsernameProblemLanguageResultExecution timeMemory
1209465hainam2k9동기화 (JOI13_synchronization)C++20
0 / 100
169 ms23404 KiB
#include <bits/stdc++.h> #define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0) #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout) #define ll long long #define ull unsigned long long #define i128 __int128 #define db long double #define sz(a) ((int)(a).size()) #define pb emplace_back #define pf emplace_front #define pob pop_back #define pof pop_front #define lb lower_bound #define ub upper_bound #define fi first #define se second #define ins emplace #define mp make_pair using namespace std; const int MOD = 1e9+7, MAXN = 1e5+5; const string NAME = ""; int n,m,q,rs[MAXN],cnt[MAXN]; int depth[MAXN],par[MAXN][20]; int Start[MAXN],End[MAXN],bit[MAXN],id=0; bool type[MAXN],vis[MAXN]; pair<int,int> p[MAXN]; vector<int> adj[MAXN]; void dfs(int u){ Start[u]=++id; for(int& v : adj[u]) if(v!=par[u][0]){ depth[v]=depth[u]+1, par[v][0]=u; for(int i = 1; i<=16; ++i) par[v][i]=par[par[v][i-1]][i-1]; dfs(v); } End[u]=id; } void update(int pos, int val){ while(pos<=n) bit[pos]+=val, pos+=pos&-pos; } int getsum(int pos){ int rs=0; while(pos>0) rs+=bit[pos], pos-=pos&-pos; return rs; } int main() { tt; if(fopen((NAME + ".INP").c_str(), "r")) fo; cin >> n >> m >> q; for(int i = 1; i<n; ++i) cin >> p[i].fi >> p[i].se, adj[p[i].fi].pb(p[i].se), adj[p[i].se].pb(p[i].fi); dfs(1); for(int i = 1; i<n; ++i) if(depth[p[i].fi]<depth[p[i].se]) swap(p[i].fi,p[i].se); while(m--){ int x; cin >> x; x=p[x].fi, type[x]^=1; if(type[x]){ update(Start[x],1), update(End[x]+1,-1); int maxpar=x,sum=getsum(Start[x]); for(int i = 16; i>=0; --i) if(par[maxpar][i]!=0&&depth[x]-depth[par[maxpar][i]]==sum-getsum(Start[par[maxpar][i]])) maxpar=par[maxpar][i]; if(!vis[x]) ++rs[maxpar], ++cnt[maxpar], vis[x]=1; rs[maxpar]+=cnt[x], cnt[x]=0; }else{ int maxpar=x,sum=getsum(Start[x]); for(int i = 16; i>=0; --i) if(par[maxpar][i]!=0&&depth[x]-depth[par[maxpar][i]]==sum-getsum(Start[par[maxpar][i]])) maxpar=par[maxpar][i]; rs[x]=rs[maxpar]; update(Start[x],-1), update(End[x]+1,1); } } while(q--){ int x; cin >> x; int maxpar=x,sum=getsum(Start[x]); for(int i = 16; i>=0; --i) if(par[maxpar][i]!=0&&depth[x]-depth[par[maxpar][i]]==sum-getsum(Start[par[maxpar][i]])) maxpar=par[maxpar][i]; cout << rs[maxpar]+1 << "\n"; } }

Compilation message (stderr)

synchronization.cpp: In function 'int main()':
synchronization.cpp:3:19: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
synchronization.cpp:50:45: note: in expansion of macro 'fo'
   50 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
synchronization.cpp:3:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |                                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
synchronization.cpp:50:45: note: in expansion of macro 'fo'
   50 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...