Submission #283241

#TimeUsernameProblemLanguageResultExecution timeMemory
283241AKaan37Ball Machine (BOI13_ballmachine)C++17
20.95 / 100
1099 ms29560 KiB
//Bismillahirrahmanirrahim //█▀█─█──█──█▀█─█─█ //█▄█─█──█──█▄█─█▄█ //█─█─█▄─█▄─█─█─█─█ #pragma GCC optimize ("O3") #pragma GCC target ("sse4") #pragma GCC optimize ("unroll-loops") #pragma GCC target ("avx2") #include <bits/stdc++.h> using namespace std; typedef long long lo; typedef pair< lo,lo > PII; #define fi first #define se second #define mp make_pair #define endl "\n" #define int long long #define pb push_back #define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define FOR for(int i=1;i<=n;i++) #define mid ((start+end)/2) #define ort ((bas+son)/2) const lo inf = 1000000000000000000; const lo KOK = 100000; const lo LOG = 30; const lo li = 500005; const lo mod = 1000000007; int n,m,b[li],a[li],k,flag,t,vis[li],root,par[li][LOG],last,mini[li]; int cev; multiset<PII> st; string s; vector<int> v; inline void build_lca(){ for(int i=1;i<=17;i++){ for(int j=1;j<=n;j++)par[j][i]=par[par[j][i-1]][i-1]; } } int32_t main(void){ scanf("%lld %lld",&n,&t); FOR{ int x; scanf("%lld",&x); if(x==0){ root=x; } else{ vis[x]++; par[i][0]=x; } } FOR{ if(vis[i]==0)st.insert({i,i}); mini[i]=i; } build_lca(); vis[0]=1000000; while(t--){ int type; scanf("%lld",&type); if(type==1){ scanf("%lld",&k); while(k){ k--; auto it=st.begin(); PII p=*it; last=p.se; //~ cout<<p.fi<<endl; //~ if(last==212)cout<<k<<"**\n"; //~ cout<<last<<endl; vis[par[p.se][0]]--; mini[par[p.se][0]]=min(mini[par[p.se][0]],p.fi); if(vis[par[p.se][0]]==0){st.insert({min(mini[par[p.se][0]],p.fi),par[p.se][0]});} st.erase(it); } printf("%lld\n",last); continue; } int x; scanf("%lld",&x); //~ int y=x; cev=0; for(int i=17;i>=0;i--){ if(vis[par[x][i]] || st.find({mini[par[x][i]],par[x][i]})!=st.end())continue; x=par[x][i]; cev+=(1<<i); } if(st.find({mini[par[x][0]],par[x][0]})!=st.end()){st.erase(st.find({mini[par[x][0]],par[x][0]}));} vis[par[x][0]]++; st.insert({mini[x],x}); printf("%lld\n",cev); } return 0; }

Compilation message (stderr)

ballmachine.cpp: In function 'int32_t main()':
ballmachine.cpp:48:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   48 |  scanf("%lld %lld",&n,&t);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~
ballmachine.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   51 |   scanf("%lld",&x);
      |   ~~~~~^~~~~~~~~~~
ballmachine.cpp:68:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   68 |   scanf("%lld",&type);
      |   ~~~~~^~~~~~~~~~~~~~
ballmachine.cpp:70:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   70 |    scanf("%lld",&k);
      |    ~~~~~^~~~~~~~~~~
ballmachine.cpp:88:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   88 |   scanf("%lld",&x);
      |   ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...