Submission #710355

#TimeUsernameProblemLanguageResultExecution timeMemory
710355vjudge1Carnival (CEOI14_carnival)C++17
100 / 100
26 ms23884 KiB
/* #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimize("unroll-loops") */ #include<bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() #define len(x) ll(x.size()) #define eb emplace_back #define PI 3.14159265359 #define fi first #define se second #define mp make_pair #define pb push_back #define MIN(v) *min_element(all(v)) #define MAX(v) *max_element(all(v)) #define BIT(x,i) (1&((x)>>(i))) #define MASK(x) (1LL<<(x)) #define task "tnc" typedef long long ll; const ll INF=1e18; const int maxn=1e6+5; const int mod=1e9+7; const int mo=998244353; using pi=pair<ll,ll>; using vi=vector<ll>; using pii=pair<pair<ll,ll>,ll>; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int pa[maxn]; int n; vector<int>sz[maxn]; vector<int>q; int ask(vector<int>s){ cout<<s.size()<<" "; for(int i=0;i<s.size();i++){ cout<<s[i]<<" "; } cout<<endl; int d; cin>>d; return d; } int find(int u,vector<int>d,int l,int r){ vector<int>z=d; z.pb(u); int s=ask(z); if(r-l+1==d.size() && s==(int)(d.size())+1){ return -1; } else{ if(l==r){ return l; } int mid=(l+r)/2; vector<int>k1; for(int i=l;i<=mid;i++){ k1.pb(d[i]); } k1.pb(u); if(ask(k1)==mid-l+1){ return find(u,d,l,mid); } else{ return find(u,d,mid+1,r); } } } int fin(int a){ if(a==pa[a])return a; return pa[a]=fin(pa[a]); } vector<int>divide(int l,int r){ //cout<<l<<" "<<r<<"\n"; vector<int>s; if(l==r){ s.pb(l); return s; } int mid=(l+r)/2; vector<int>k1=divide(l,mid); vector<int>k2=divide(mid+1,r); for(auto u:k1){ if((int)(k2.size())==0){ break; } int z=find(u,k2,0,(int)(k2.size())-1); if(z!=-1){ pa[k2[z]]=u; k2.erase(k2.begin()+z); } } for(auto v:k2){ k1.pb(v); } return k1; } signed main() { cin.tie(0),cout.tie(0)->sync_with_stdio(0); //freopen(task".inp" , "r" , stdin); //freopen(task".out" , "w" , stdout); cin>>n; for(int i=1;i<=n;i++){ pa[i]=i; sz[i].pb(i); } divide(1,n); vector<int>dinh; for(int i=1;i<=n;i++){ if(fin(i)==i){ dinh.pb(i); } } cout<<"0"<<" "; for(int i=1;i<=n;i++){ int d=lower_bound(dinh.begin(),dinh.end(),pa[i])-dinh.begin()+1; cout<<d<<" "; } cout<<endl; return 0; }

Compilation message (stderr)

carnival.cpp: In function 'int ask(std::vector<int>)':
carnival.cpp:36:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |  for(int i=0;i<s.size();i++){
      |              ~^~~~~~~~~
carnival.cpp: In function 'int find(int, std::vector<int>, int, int)':
carnival.cpp:48:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |  if(r-l+1==d.size() && s==(int)(d.size())+1){
      |     ~~~~~^~~~~~~~~~
#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...