Pagini recente » Cod sursa (job #2900990) | Cod sursa (job #2440336) | Cod sursa (job #1108233) | Cod sursa (job #1868992) | Cod sursa (job #2282254)
#include <fstream>
using namespace std;
ifstream fin("farfurii.in");
const int N=100000+5;
int n;
long long cnt,lft,x;
int vi;
int aib[N];
class OutParser {
private:
FILE *fout;
char *buff;
int sp;
void write_ch(char ch) {
if (sp == 70000) {
fwrite(buff, 1, 70000, fout);
sp = 0;
buff[sp++] = ch;
} else {
buff[sp++] = ch;
}
}
public:
OutParser(const char* name) {
fout = fopen(name, "w");
buff = new char[70000]();
sp = 0;
}
~OutParser() {
fwrite(buff, 1, sp, fout);
fclose(fout);
}
OutParser& operator << (int vu32) {
if (vu32 <= 9) {
write_ch(vu32 + '0');
} else {
(*this) << (vu32 / 10);
write_ch(vu32 % 10 + '0');
}
return *this;
}
OutParser& operator << (long long vu64) {
if (vu64 <= 9) {
write_ch(vu64 + '0');
} else {
(*this) << (vu64 / 10);
write_ch(vu64 % 10 + '0');
}
return *this;
}
OutParser& operator << (char ch) {
write_ch(ch);
return *this;
}
OutParser& operator << (const char *ch) {
while (*ch) {
write_ch(*ch);
++ch;
}
return *this;
}
};
int main()
{
OutParser fout("farfurii.out");
fin>>n>>cnt;
for(register int i=1;i<=n;i++)
{
lft=n-i;
x=lft*(lft-1)/2;
if(cnt<=x)
{
vi=0;
}
else
{
vi=cnt-x;
}
cnt-=vi;
vi++;
register int r=0,pas=(1<<16);
register int now=0;
while(pas)
{
if(r+pas<=n && r+pas+now+aib[r+pas]<vi)
{
r+=pas;
now+=aib[r];
}
pas>>=1;
}
r++;
for(register int j=r;j<=n;j+=j&(-j))
{
aib[j]--;
}
fout<<r<<" ";
}
return 0;
}