이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>
//#define int long long
#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".ans","w",stdout)
#define pb push_back
#define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
using namespace std;
#define getchar_unlocked getchar
inline int scan()
{
char c = getchar_unlocked();
int x = 0;
while(c<'0'||c>'9')
{
c=getchar_unlocked();
}
while(c>='0'&&c<='9')
{
x=(x<<1)+(x<<3)+c-'0';
c=getchar_unlocked();
}
return x;
}
void phongbeo();
const int inf=1e9;
const int mod2=1e9+9;
const int mod1=998244353;
struct icd
{
long double a;
int b;
};
struct ib
{
int a;
int b;
};
struct ic
{
int a,b,c;
};
struct id
{
int a,b,c,d;
};
struct ie
{
int a,b,c,d,e;
};
ll n,m,s1,s2,s3,s4,sf,k,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,s33,dem3,dem4,l,r,mid;
int i,s10,s12;
int kk;
int el=29;
vector<int> construct_permutation(long long k)
{
set<int> s;
vector<int> v;
vector<int> v2;
vector<int> v3;
dem=0;
bool de=0;
/// xoay chieu 2 con 2^(i-2)*5=2^(i-1)+2^(i-2)
/// xoay chieu 2 con xong roi lay toan bo 2^i+2^(i-1) :)
/// 2^(x-1)+2^(x-2)
for(int i=59; i>=0; --i)
{
if(bit(k,i))
{
v.pb(i);
if(dem==0) dem=i;
else dem++;
}
}
if(dem>=90)
{
v.clear();
dem=0;
s5=1;
s4=(1ll<<s5)+1;
s2=k%s4;
if(k<s4){
return {-1};
}
k=k/s4;
s9=0;
for(int i=60-s5-1; i>=0; --i)
{
if(bit(k,i))
{
v.pb(i+s5+1);
if(dem==0)dem=i+s5+1,s9=10;
else dem++;
}
}
for(int i=s5; i>=0; --i)
if(bit(s4,i))
{
v.pb(i);
dem++;
}
for(int i=0; i<=dem; i++)
s.insert(i);
reverse(v.begin(),v.end());
for(int i=0; i<v.size(); i++)
{
if(i+1==v.size())
{
for (auto it = s.begin(); it != s.end(); ++it)
v3.pb(*it);
reverse(v3.begin(),v3.end());
for(auto x:v3)
v2.pb(x);
}
else
{
auto x=s.begin();
for(int j=1; j<=v[i]; j++)
x++;
v2.pb(*x);
s.erase(x);
}
}
reverse(v2.begin(),v2.end());
for(int i=s5; i>=1; --i)
swap(v2[i],v2[i-1]);
return v2;
}
dem--;
for(int i=0; i<=dem; i++)
s.insert(i);
reverse(v.begin(),v.end());
for(int i=0; i<v.size(); i++)
{
if(i+1==v.size())
{
for (auto it = s.begin(); it != s.end(); ++it)
v3.pb(*it);
reverse(v3.begin(),v3.end());
for(auto x:v3)
v2.pb(x);
}
else
{
auto x=s.begin();
for(int j=1; j<=v[i]; j++)
x++;
v2.pb(*x);
s.erase(x);
}
}
reverse(v2.begin(),v2.end());
return v2;
}
/*main()
{
freopen ("test.inp", "r", stdin);
freopen ("test.ans", "w", stdout);
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int q;
cin >> q;
while ( q-- ) {
ll k;
cin >> k;
vector <int> kk = construct_permutation(k);
cout<<kk.size()<<"\n";
for(auto x:kk)
cout<<x<<" ";
}
}*/
컴파일 시 표준 에러 (stderr) 메시지
perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:120:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
120 | for(int i=0; i<v.size(); i++)
| ~^~~~~~~~~
perm.cpp:122:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
122 | if(i+1==v.size())
| ~~~^~~~~~~~~~
perm.cpp:152:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
152 | for(int i=0; i<v.size(); i++)
| ~^~~~~~~~~
perm.cpp:154:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
154 | if(i+1==v.size())
| ~~~^~~~~~~~~~
perm.cpp:74:10: warning: unused variable 'de' [-Wunused-variable]
74 | bool de=0;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |