-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC.cpp
78 lines (73 loc) · 1.83 KB
/
C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <bits/stdc++.h>
#define fi first
#define se second
#define db double
#define U unsigned
#define P std::pair<int,int>
#define LL long long
#define pb push_back
#define MP std::make_pair
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const int MAXN = 1e5 + 5;
int n;LL s;
int d[MAXN];
inline bool chk(int x){
FOR(i,1,n) d[i] = 1;
LL r = 1ll*n*(n+1)/2-s;
if(r < 0) return 0;
if(r == 0) return 1;
int now = 2,lst = n;
while(1){
while(1ll*d[now-1]*x == d[now]) ++now;
while(!d[lst]) --lst;
if(lst <= now) return 0;
if(r > lst-now){
d[lst]--;d[now]++;
r -= (lst-now);
continue;
}
else{
while(r < lst-now) ++now;
d[now]++;d[lst]--;
r = 0;
return 1;
}
}
return 0;
}
std::vector<P> G[MAXN];
int fa[MAXN],dep[MAXN];
int main(){
scanf("%d%lld",&n,&s);
int l = 1,r = n-1,ans = -1;
while(l <= r){
int mid = (l + r) >> 1;
if(chk(mid)) ans = mid,r = mid-1;
else l = mid+1;
}
if(ans == -1){
puts("No");return 0;
}
puts("Yes");chk(ans);
G[1].pb(MP(1,ans));int t = 1;
FOR(i,2,n){
FOR(j,1,d[i]){
assert(!G[i-1].empty());++t;
printf("%d ",fa[t]=G[i-1].back().fi);
G[i-1].back().se--;
if(!G[i-1].back().se) G[i-1].pop_back();
G[i].pb(MP(t,ans));
}
}
puts("");
// dep[1] = 1;
// FOR(i,2,n) dep[i] = dep[fa[i]]+1;
// int tt = 0;FOR(i,1,n) tt += i*d[i];
// DEBUG(tt);
//puts("");
return 0;
}