QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#22434 | #2351. Lost in Transfer | 1145141919810# | 0 | 4ms | 7460kb | C++20 | 5.7kb | 2022-03-09 18:14:37 | 2023-01-17 09:35:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef double db;
//#define int long long
#define fi first
#define se second
#define mk make_pair
#define pb emplace_back
#define poly vector<int>
#define Bt(a) bitset<a>
#define bc __builtin_popcount
#define pc putchar
#define ci const int&
const int mod = 998244353;
const db eps = 1e-10;
inline int Max(ci x, ci y) {
return x > y ? x : y;
}
inline int Min(ci x, ci y) {
return x < y ? x : y;
}
inline db Max(db x, db y) {
return x - y > eps ? x : y;
}
inline db Min(db x, db y) {
return x - y < eps ? x : y;
}
inline int Add(ci x, ci y, ci M = mod) {
return (x + y) % M;
}
inline int Mul(ci x, ci y, ci M = mod) {
return 1ll * x * y % M;
}
inline int Dec(ci x, ci y, ci M = mod) {
return (x - y + M) % M;
}
typedef pair<int, int> pii;
inline int Abs(int x) {
return x < 0 ? -x : x;
}
//char buf[1<<21],*p1=buf,*p2=buf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char Obuf[105000],*O=Obuf;//Siz shoule be the size of Out File
int pst[30],ptop;
inline void Fprint() {
fwrite(Obuf,1,O-Obuf,stdout);
}
inline void Fwrite(int x) {
if(x==0) {
*O++='0';
if(O-Obuf>100000)Fprint(),O=Obuf;
return;
}
if(x<0)*O++='-',x=-x;
ptop=0;
while(x)pst[++ptop]=x%10,x/=10;
while(ptop)*O++=pst[ptop--]+'0';
if(O-Obuf>100000)Fprint(),O=Obuf;
}
inline int read() {
int s = 0, w = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') w = -1;
ch = getchar();
}
while (isdigit(ch)) {
s = s * 10 + ch - '0';
ch = getchar();
}
return s * w;
}
inline void write(int x) {
if (x < 0)putchar('-'), x = -x;
if (x > 9)write(x / 10);
pc(x % 10 + '0');
}
inline int qpow(int x, int y) {
int res = 1;
while (y) {
if (y & 1)res = Mul(res, x);
x = Mul(x, x);
y >>= 1;
}
return res;
}
inline void cadd(int &x, int y) {
x += y;
}
inline void cmul(int &x, int y) {
x *= y;
}
inline void cmax(int &x, int y) {
x = Max(x, y);
}
inline void cmin(int &x, int y) {
x = Min(x, y);
}
const int N = 3e5 + 10;
namespace Refined_heart {
namespace Cantor {
const int N=10;
int fac[N],c[N],n,m;
void init() {
fac[0]=1;
for(int i=1; i<N; ++i)fac[i]=fac[i-1]*i;
}
void setn(int _n) {
n=_n;
m=1;
while(m<=n)m<<=1;
for(int i=0; i<m; ++i)c[i]=0;
}
int lowbit(int x) {
return x&-x;
}
void add(int u,int x) {
while(u<m) {
c[u]+=x;
u+=lowbit(u);
}
}
int rnk(int u) {
int ret=0;
while(u) {
ret+=c[u];
u-=lowbit(u);
}
return ret;
}
int kth(int k) {
int ret=0;
for(int i=m>>1; i; i>>=1) {
if(c[ret+i]<k) {
ret+=i;
k-=c[ret];
}
}
return ret+1;
}
int encode(int* a,int _n) {
setn(_n);
int ret=0;
for(int i=n-1; i>=0; --i) {
ret+=rnk(a[i])*fac[n-1-i];
add(a[i],1);
}
return ret;
}
vector<int> decode(int x,int _n) {
setn(_n);
vector<int> ret;
for(int i=1; i<=n; ++i)add(i,1);
for(int i=n-1; i>=0; --i) {
int t=kth(x/fac[i]+1);
ret.push_back(t);
add(t,-1);
x%=fac[i];
}
return ret;
}
}
char st[100];
int a[N],b[N],c[N],d[N];
const int B = 6;
int tg[N];
void workit(int s,int t,int vl){
poly A=Cantor::decode(vl,6);
// puts("???");
int pos=0;
for(int i=s;i<=t;++i){
// tg[i]=A[pos++];
b[A[pos++]]=a[i];
}
for(int i=s;i<=t;++i){
a[i]=b[i-s+1];
}
// sort(a+s,a+s+t,cmp);
}
void transmit(){
int v=0;
int n=read();
for(int i=1;i<=n;++i)a[i]=read();
sort(a+1,a+n+1);
for(int i=1;i<=n;++i)v^=a[i];
// cout<<v<<"\n";
// puts("!!!");
for(int i=1;i<=n;i+=6){
if(i+6-1>n){
random_shuffle(a+i,a+n+1);
break;
}
workit(i,i+5,v);
}
// puts(">>>");
for(int i=1;i<=n;++i)cout<<a[i]<<" ";
cout<<"\n";
}
int vis[1000];
int getval(int l,int r){
int cnt=0;
for(int i=l;i<=r;++i)c[++cnt]=a[i];
sort(c+1,c+cnt+1);
for(int i=1;i<=cnt;++i)b[c[i]]=i;
for(int i=l;i<=r;++i){
d[i-l]=b[a[i]];
}
return Cantor::encode(d,6);
}
bool checkit(int n){
int pre=0;
for(int i=1;i<=n;i+=6){
int r=i+5;
if(r>n)break;
int vl=getval(i,i+5);
if(!pre)pre=vl;
else if(pre!=vl)return false;
}
for(int i=n-(n%6);i;i-=6){
int l=i-5;
if(l<1)break;
int vl=getval(l,i);
if(pre!=vl)return false;
}
return true;
}
void recover(){
int n=read();
// cout<<n<<"-----------------\n";
for(int i=1;i<=n;++i)a[i]=read();
int kk=checkit(n);
if(kk){
sort(a+1,a+n+1);
for(int i=1;i<=n;++i)cout<<a[i]<<" ";
cout<<"\n";
return;
}
// puts(">>");
poly app;
int pre=0;
for(int i=1;i<=n;i+=6){
int r=i+5;
if(r>n)break;
// cout<<i<<" "<<"\n";
int vl=getval(i,i+5);
vis[vl]++;
// cout<<vl<<"\n";
if(vis[vl]==1)app.pb(vl);
if(!pre)pre=vl;
else if(vl!=pre)break;
}
// puts(" ");
pre=0;
for(int i=n-(n+1)%6;i>=1;i-=6){
int l=i-5;
if(l<1)break;
int vl=getval(l,i);
// cout<<vl<<"\n";
vis[vl]++;
if(vis[vl]==1)app.pb(vl);
if(!pre)pre=vl;
else if(pre!=vl)break;
}
int vv=0,ct=0;
for(auto v:app){
if(vis[v]>ct){
vv=v;
ct=vis[v];
}
}
// cout<<vv<<"\n";
int rr=0;
for(int i=1;i<=n;++i)rr^=a[i];
if(vv!=rr){
a[++n]=vv^rr;
}
sort(a+1,a+n+1);
for(int i=1;i<=n;++i)cout<<a[i]<<" ";
cout<<"\n";
}
void solve() {
cin>>st;
int fg=0;
if(st[0]=='t'){
fg=1;
}
int T=read();
for(int i=1;i<=T;++i){
Cantor::init();
if(fg){
transmit();
}
else{
recover();
}
for(int k=1;k<=1000;++k){
a[k]=b[k]=c[k]=vis[k]=d[k]=0;
}
}
}
}
signed main() {
Refined_heart::solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 7460kb
input:
transmit 2 20 97 388 459 467 32 99 98 296 403 325 330 271 87 333 378 267 405 58 426 374 20 125 481 451 150 495 136 444 192 118 26 68 281 120 61 494 339 86 292 100 32
output:
58 32 97 87 99 98 271 267 325 296 333 330 378 374 403 388 426 405 459 467 26 100 32 68 86 61 118 192 120 136 150 125 281 481 292 444 451 339 495 494
input:
recover 2 19 58 32 97 87 99 98 271 267 325 296 333 330 378 374 403 388 426 405 459 19 26 100 32 68 61 118 192 120 136 150 125 281 481 292 444 451 339 495 494
output:
32 58 87 97 98 99 267 271 296 325 330 333 374 378 388 403 405 426 459 24 26 32 61 68 100 118 120 125 136 150 192 281 292 339 444 451 481 494 495
result:
wrong answer incorrect answer. (test case 1)