Submission #283131

#TimeUsernameProblemLanguageResultExecution timeMemory
283131AKaan37Ball Machine (BOI13_ballmachine)C++17
4.29 / 100
1100 ms15736 KiB
//Bismillahirrahmanirrahim //█▀█─█──█──█▀█─█─█ //█▄█─█──█──█▄█─█▄█ //█─█─█▄─█▄─█─█─█─█ #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 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; int cev; set<int> st; string s; vector<int> v; inline void build_lca(){ for(int i=1;i<=27;i++){ for(int j=1;j<=n;j++)par[j][i]=par[par[j][i-1]][i-1]; } } int main(void){ scanf("%d %d",&n,&t); FOR{ int x; scanf("%d",&x); if(x==0){ root=x; } else{ vis[x]++; par[i][0]=x; } } FOR{ if(vis[i]==0)st.insert(i); } build_lca(); vis[0]=1000000; while(t--){ int type; scanf("%d",&type); if(type==1){ scanf("%d",&k); while(k){ k--; auto it=st.begin(); last=*it; //~ cout<<last<<endl; vis[par[*it][0]]--; if(vis[par[*it][0]]==0)st.insert(par[*it][0]); st.erase(it); } printf("%d\n",last); continue; } int x; scanf("%d",&x); int y=x; cev=0; for(int i=27;i>=0;i--){ if(vis[par[x][i]])continue; x=par[x][i]; cev+=(1<<i); } //~ vis[x]=1; if(st.find(x)!=st.end())st.erase(x); else vis[par[x][0]]++; //~ st.insert(x); vis[x]++; for(int i=27;i>=0;i--){ if(vis[par[y][i]] || par[y][i]==x)continue; y=par[y][i]; //~ cev+=(1<<i); } st.insert(y); vis[y]=0; printf("%d\n",cev); } return 0; }

Compilation message (stderr)

ballmachine.cpp: In function 'int main()':
ballmachine.cpp:42:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   42 |  scanf("%d %d",&n,&t);
      |  ~~~~~^~~~~~~~~~~~~~~
ballmachine.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   45 |   scanf("%d",&x);
      |   ~~~~~^~~~~~~~~
ballmachine.cpp:61:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   61 |   scanf("%d",&type);
      |   ~~~~~^~~~~~~~~~~~
ballmachine.cpp:63:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   63 |    scanf("%d",&k);
      |    ~~~~~^~~~~~~~~
ballmachine.cpp:77:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   77 |   scanf("%d",&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...