版本比较
[爆标]CF2106G2
正文
增加 21 行删除 21 行
93 行未改动9495969798989910010110213 行未改动1161171181191201201211221231241251261271281281291301311324 行未改动1371381391401411411421431441453 行未改动1491501511521531531541551561576 行未改动1641651661671681681691701711721731741741751761771789 行未改动1881891901911921921931941951961971981992002002012022032042052062072072082092102112112122132142152162172182182192202212225 行未改动22822923023123223223323423423523623723818 行未改动25725825926026126126226326426517 行未改动28328428528628728728828929029129229329429529529629729729829930030112 行未改动31431531631731831831932032132232332432532632632732832933023 行未改动35435535635735835835936036136245 行未改动93 行未改动操作 $5'$:可以以 $\frac{n}{\log_2 n±\Theta(1)}+O(\log n)$ 个查询内计算所有 $f$。
先找到根,接下来如果当前深度最深的树超过 $L$,则按这个根询问一发链下去,直到所有树深度都不超过 $L$。
现在森林共有 $n$ 个节点,深度均小于 $L$。 现在森林共有 $n$ 个节点,深度均小于 $L$。将深度为 $d$ 的节点集合记为 $S_d$,则需的询问次数为:
$$Q=\sum_{d=1}^L \lceil \frac{|S_d|}{L} \rceil=\frac{n}{L} + O(L)$$
13 行未改动#include "bits/stdc++.h"using namespace std;#pragma GCC optimize("Ofast","inline","-ffast-math")#pragma GCC target("avx,sse2,sse3,sse4,mmx")
vector<int> Q[1001];int n,L,root,val[1001],father[1001],pre[1001];
namespace findroot { bool proot[1001]; int weight[1001];
void dfs1(int x,int fa,int& sum,int &res) { int val=0; weight[x]=1; for(int i:Q[x])4 行未改动 } val=max(val,sum-weight[x]); if(val<=sum/2) res=x; }
int gravity() { int sum=0,res=0; for(int i=1;i<=n;++i) sum+=proot[i]; for(int i=1;i<=n;++i)3 行未改动 } if(sum==1) return -res; return res; }
bool checkroot(vector<int> candidate,int x) { int res1,res2; cout << "? 1 " << candidate.size() << ' '; assert(candidate.size()<=n);6 行未改动 cout << endl; cin >> res2; return abs(res1-res2)/2==candidate.size(); }
int weightsum(int sz,int p) { if(p<=0||sz==0) return false; int bs=sz/p,lc=sz%p,sc=p-lc; return lc*(lc-1)/2*(bs+1)+(lc*2+sc-1)*sc/2*(bs); }
int fa(int x) { vector<int> candidate; for(int i:Q[x]) if(proot[i])9 行未改动 int res1,res2; cout << "? 1 " << weightsum(candidate.size(),p) << ' '; for(int i=0;i<p;++i) for(int j:group[i]) for(int k=0;k<i;++k) for(int k=0;k<i;++k) cout << j << ' '; cout << endl; cin >> res1; cout << "? 2 " << x << endl; cout << "? 1 " << weightsum(candidate.size(),p) << ' '; for(int i=0;i<p;++i) for(int j:group[i]) for(int k=0;k<i;++k) for(int k=0;k<i;++k) cout << j << ' '; cout << endl; cin >> res2; candidate=group[abs(weightsum(candidate.size(),p)-abs(res1-res2)/2)]; break; }
} return candidate[0]; }
void dfs2(int x,int fa) { proot[x]=false; for(int i:Q[x]) if(i!=fa) dfs2(i,x); }
int root() { for(int i=1;i<=n;++i) proot[i]=true; while(true) { int g=gravity();5 行未改动 }};
namespace valquery {
int depth[1001];
vector<int> chain(vector<int> node,int inital) { assert(node.size()<=L); int val=0; vector<int> res;18 行未改动 } } return res; }
vector<int> separate(vector<int> node,vector<int> inital) { assert(node.size()<=L); int val=0; vector<int> res;17 行未改动 } } return res; }
void dfs1(int x,int fa) { for(int i:Q[x]) if(i!=fa) { dfs1(i,x); depth[x]=max(depth[x],depth[i]+1); } if(val[x]!=0) depth[x]=0; else depth[x]=max(depth[x],1); else depth[x]=max(depth[x],1); }
vector<int> findchain() { dfs1(root,0); int maxdepth=0,maxidx=0; for(int i=1;i<=n;++i)12 行未改动 } } return res; }
void dfs2(int x,int fa,int dep) { if(val[x]) dep=0; depth[x]=dep; for(int i:Q[x]) if(i!=fa) dfs2(i,x,dep+1); }
void getval() { while(true) { vector<int> t=findchain(); if(t.empty()) break;23 行未改动 } } } }
};
void dfs(int x,int fa) { father[x]=fa;45 行未改动