原题链接
题解
讲一下蒟蒻的赛时思路。
赛时本来没觉得能切 , 秒了 A , B 之后想怎么发挥传统艺能 (骗分) , 于是先打了个暴力 , 看了特殊性质 3 。 打完暴力后试了一下 为 0 的输入 , 发现无论 是多少都有一组符合条件的构造 : 。飞快的写出了特殊性质后交了一发 , 成功拿到了 7pts 。 证明特殊性质是对的读者自证不难。
骗完特殊性质之后 , bro对正解开始充满了希望 , 于是开始怼正解。怼的时候发现了一些奇妙的小性质 ( 先假定目前的序列是按照特殊性质 3 构造出来的 ) :
在序列中放入 1 个 1 后 , 会对答案产生 的贡献 , 这里的 代表之前放入过多少个 1
如果序列中有 个相同的数 , () , 那么会对答案产生 的贡献。
有了以上两条性质 , 就可以愉快的切了这道题了。
对于 的情况 , 可以不断的放 1 , 直到放不了 1 为止。
此时只需要找到最大的 , 然后
k -= (y - 1)(y - 2) / 2;直到 等于 0 , 此时转换为特殊性质 3。 然后就愉快的切了这道蓝题。
Code~
找 貌似不需要二分 , 一个指针就可以 , 赛时脑抽了。
#include<bits/stdc++.h>
using namespace std;
#define Yozusoft 0x0d000721
#define ll long long
#ifndef TEST
constexpr auto maxn=1<<20;char Cin[maxn],Cout[maxn],*p1=Cin,*p2=Cin,*p3=Cout;
#define getchar()(p1==p2&&(p2=(p1=Cin)+fread(Cin,1,maxn,stdin),p1==p2)?EOF:*p1++)
#define ros()(fwrite(Cout,1,p3-Cout,stdout))
#define putchar(x)(p3==Cout+maxn&&(ros(),p3=Cout),*p3++=(x))
#define isdigit(x) ((x)>='0'&&(x)<='9')
class ROS{public:~ROS(){ros();}}_;
#endif
#define isspace(x) ((x)<33)
#define isdigit(x) ((x) >= '0' && (x) <= '9')
template <typename T>
inline void Miku(T&x){x=0;char f=1,ch=getchar();while(!isdigit(ch)) ch=='-'?f=-1:0,ch=getchar();for(;isdigit(ch);) x=(x<<3)+(x<<1)+ch-'0',ch=getchar(); x*=f;}
inline void Miku(char&x){x=' ';while(isspace(x))x=getchar();}
inline void Miku(char*x){char ch;while(!isspace(ch=getchar())) (*x++)=ch;}
inline void Miku(string&x){static char ch; Miku(ch);x.clear();do x+=ch; while(!isspace(ch=getchar())&&~ch);}
inline void Miku(double&x){scanf("%lf", &x);}
template <typename T>
inline void Iliya(T x){x<0?putchar('-'),x=-x:0; static short st[55], t(0); do st[++t]=x%10; while(x/=10); for(;t;t--) putchar(st[t]+'0');}
inline void Iliya(char x){putchar(x);}
template <typename T>
inline void Iliya(T*x){for(;(*x);) putchar(*(x++));}
inline void Iliya(string x){for(int i=0,len=x.size();i<len;i++) putchar(x[i]);}
inline void Iliya(double x){printf("%.10lf", x);}
template <typename T, typename ...ty>
inline void Miku(T&x, ty&...y){Miku(x),Miku(y...);}
template <typename T, typename ...ty>
inline void Iliya(T x, ty ...y){Iliya(x), putchar(' '),Iliya(y...);}
template <typename T, typename ...ty>
inline void Miyu(T x, ty ...y){Iliya(x, y...); putchar('\n');}
#ifndef TEST
#undef getchar
#undef ros
#undef putchar
#endif
//=============================Fast IO=============================//
#ifdef TEST
#define file(x) 1;
#else
#define file(x) freopen(#x ".in", "r", stdin);\
freopen(#x ".out","w",stdout);
#endif
//=============================Freopen=============================//
const int MOD = 1e9 + 7;
const int N = 5e5 + 5;
ll a[N], n, k, q[N];
int ned;
signed main(){
Miku(n, k);
for(int i = 1; i <= n; i ++) {
if(k >= n - i) {
k -= n - i;
Iliya("1 ");
} else {
ned = n - i + 1;
break;
}
}
q[1] = 0;
for(int i = 2; i <= n + 2; i ++)
q[i] = q[i - 1] + i - 1;
int out = 2 * n - 1;
while(k) {
int w = upper_bound(q + 1, q + n + 1, k) - q - 1;
for(int i = 1; i <= w; i ++) Iliya(out, "");
out --;
k -= q[w];
ned -= w;
}
for(int i = out; ned --; i --) Iliya(i, "");
return 0;
}
/*
33 43 47 65
*/other
感谢泠珞让我的小号上了大分