B. Fibonaccharsis
问你多少个满足 fi=fi−1+fi−2,i>2 的数列满足 fk=n
考虑最简单的斐波那契,并且多一项前导0, k 最多不会超过40。
于是直接暴力即可。
| 12
 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
 
 | #include<bits/stdc++.h>
 using namespace std;
 
 const int maxn=550;
 
 int n,T,k,ans;
 
 void check(int a,int b)
 {
 int lk=0;
 if(a>b) return ;
 for(int i=1;i<=k-3;i++)
 {
 lk=b-a;
 b=a;
 a=lk;
 if(a>b||a<0) return ;
 }
 ans++;
 }
 
 int main()
 {
 ios::sync_with_stdio(false);
 cin>>T;
 while(T--)
 {
 ans=0;
 cin>>n>>k;
 for(int i=n/2;i<=n;i++)
 {
 check(n-i,i);
 }
 cout<<ans<<"\n";
 }
 return 0;
 }
 
 | 
C. Ina of the Mountain
给你一个从 1 到正无穷的数列,然后给你一个序列 a ,每次删除数列的 ai 项,重复 k 次,询问最后第一项是多少。
从后到前推即可,有正着的做法,据说是考虑第一个和第二个的关系,但是没去了解过。
| 12
 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
 
 | #include<bits/stdc++.h>#define int long long
 
 using namespace std;
 
 const int maxn=200200;
 
 int n,T,k,ans;
 int a[maxn],b[maxn];
 
 int fink(int x)
 {
 if(x>(a[n]-n)) return x+n;
 else
 {
 int looker=lower_bound(b+1,b+n+1,x)-b;
 return x+looker-1;
 }
 }
 
 signed main()
 {
 ios::sync_with_stdio(false);
 cin>>T;
 while(T--)
 {
 ans=0;
 cin>>n>>k;
 for(int i=1;i<=n;i++)
 {
 cin>>a[i];
 b[i]=a[i]-i;
 }
 int lk=1;
 for(int i=1;i<=k;i++)
 {
 lk=fink(lk);
 }
 cout<<lk<<'\n';
 }
 return 0;
 }
 
 | 
D. Imbalanced Arrays
给你一个序列 a ,你需要构造一个序列 b  ,满足 ai=(bi+bj>0),并且不会有任何 bi+bj=0
直接考虑贪心加进去即可。
| 12
 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
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 
 | #include<bits/stdc++.h>#define int long long
 
 using namespace std;
 
 const int maxn=200200;
 
 int n,T,k,a[maxn],ans[maxn],fs;
 
 struct mmm{
 int x,bh;
 bool operator <(const mmm b)
 {
 return x<b.x;
 }
 }b[maxn];
 
 struct tree_array{
 
 int c[maxn];
 #define lowbit(x) (x&(-x))
 
 void init()
 {
 for(int i=1;i<=n*2+1;i++) c[i]=0;
 }
 
 void add(int x)
 {
 while(x<=n*2+1)
 {
 c[x]++;
 x+=lowbit(x);
 }
 }
 
 int ask(int x)
 {
 int ans=0;
 while(x)
 {
 ans+=c[x];
 x-=lowbit(x);
 }
 return ans;
 }
 
 }c;
 
 void br(int x)
 {
 int t=b[x].bh;
 ans[t]=fs;
 c.add(fs+n+1);
 fs--;
 }
 
 void bl(int x)
 {
 int t=b[x].bh;
 ans[t]=-fs;
 c.add(-fs+n+1);
 fs--;
 }
 
 signed main()
 {
 ios::sync_with_stdio(false);
 cin>>T;
 while(T--)
 {
 cin>>n;
 fs=n;
 c.init();
 for(int i=1;i<=n;i++)
 {
 cin>>a[i];
 b[i].bh=i;
 b[i].x=a[i];
 }
 sort(b+1,b+n+1);
 int looker=0;
 int st=0;
 if(b[1].x==0) st=0;
 else st=1;
 if(n==1)
 {
 cout<<"YES\n";
 if(a[1]==0) cout<<"-1\n";
 else cout<<"1\n";
 continue;
 }
 for(int l=1,r=n;l<r;)
 {
 if(st==1)
 {
 br(r);
 while(r-1>=l&&b[r].x==b[r-1].x) br(--r);
 if(l==r) continue;
 else
 {
 bl(l);
 while(l+1<=r&&b[l].x==b[l+1].x) bl(++l);
 }
 r--,l++;
 if(l==r) br(r--);
 }
 else
 {
 bl(l);
 while(l+1<=r&&b[l].x==b[l+1].x) bl(++l);
 if(l==r) continue;
 else
 {
 br(r);
 while(r-1>=l&&b[r].x==b[r-1].x) br(--r);
 }
 r--,l++;
 if(l==r) bl(l++);
 }
 }
 int bj=0;
 for(int i=1;i<=n;i++)
 {
 int vvv=c.ask(2*n+1)-c.ask(-ans[i]+n+1);
 if(vvv!=a[i])
 bj=1;
 }
 if(bj)
 {
 cout<<"NO\n";
 }
 else
 {
 cout<<"YES\n";
 for(int i=1;i<=n;i++)
 {
 cout<<ans[i]<<" ";
 }
 cout<<'\n';
 }
 }
 return 0;
 }
 
 |