QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#314860 | #8174. Set Construction | ucup-team1447# | WA | 128ms | 8356kb | C++14 | 8.6kb | 2024-01-26 13:29:27 | 2024-01-26 13:29:27 |
Judging History
answer
// dottle bot
#ifndef ONLINE_JUDGE
#define DEBUG
#endif
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
#include <unordered_set>
#include <vector>
#include <bitset>
#include <map>
#include <assert.h>
#include <math.h>
#include <set>
#include <random>
std::mt19937_64 rnd(586666);
#define nln puts("")
#define od(x) printf("%d",x)
#define odb(x) printf("%d ",x)
#define odl(x) printf("%d\n",x)
#define odp(x,y) printf("%d %d\n",x,y)
#define ol(x) puts("")
#define old(x) printf("%lld",x)
#define oldb(x) printf("%lld ",x)
#define oldl(x) printf("%lld\n",x)
#define oldp(x,y) printf("%lld %lld\n",x,y)
#define rg(x) for(int i=1;i<=(x);i++){
#define rg_(i,x) for(int i=1;i<=(x);i++){
#define fe(u) for(int i=h[u];i;i=e[i].nxt){int v=e[i].v;
#define gr }
#define rrg(x) for(int i=0;i<(x);i++){
#define rdln(a) a[i]=read();
#define rdln0(a,x) rrg(x) rdln(a) gr
#define rdln1(a,x) rg(x) rdln(a) gr
#define int long long
const int mod=998244353;
#ifdef int
#define inf 0x3f3f3f3f3f3f3f3fll
#else
#define inf 0x3f3f3f3f
#endif
inline int min(int a,int b){return a>b?b:a;}
inline int max(int a,int b){return a<b?b:a;}
#define cmlSEGMIN
#define cmlSEGMAX
#define cmlSEGSUM
struct SegTreeAl{
#ifdef cmlSEGMIN
int minn[1000005<<2];
#endif
#ifdef cmlSEGMAX
int maxn[1000005<<2];
#endif
#ifdef cmlSEGSUM
int sum[1000005<<2];
#endif
int tag[1000005<<2];
#ifdef cmlSEGSUM
void pushdown(int o,int l,int r)
#else
void pushdown(int o)
#endif
{
int&t=tag[o];
#ifdef cmlSEGMIN
minn[o<<1]+=t;
minn[o<<1|1]+=t;
#endif
#ifdef cmlSEGMAX
maxn[o<<1]+=t;
maxn[o<<1|1]+=t;
#endif
#ifdef cmlSEGSUM
int m=l+r>>1;
sum[o<<1]+=t*(m-l+1);
sum[o<<1|1]+=t*(r-m);
#endif
tag[o<<1]+=t;
tag[o<<1|1]+=t;
t=0;
}
void add(int o,int l,int r,int L,int R,int v)
{
if(L<=l&&r<=R)
{
#ifdef cmlSEGMAX
maxn[o]+=v;
#endif
#ifdef cmlSEGMIN
minn[o]+=v;
#endif
#ifdef cmlSEGSUM
sum[o]+=v*(r-l+1);
#endif
tag[o]+=v;
return;
}
int m=l+r>>1;
#ifdef cmlSEGSUM
pushdown(o,l,r);
#else
pushdown(o);
#endif
if(L<=m)add(o<<1,l,m,L,R,v);
if(m<R)add(o<<1|1,m+1,r,L,R,v);
#ifdef cmlSEGMAX
maxn[o]=max(maxn[o<<1],maxn[o<<1|1]);
#endif
#ifdef cmlSEGMIN
minn[o]=min(minn[o<<1],minn[o<<1|1]);
#endif
#ifdef cmlSEGSUM
sum[o]=sum[o<<1]+sum[o<<1|1];
#endif
}
#ifdef cmlSEGMIN
int qmin(int o,int l,int r,int L,int R)
{
if(L<=l&&r<=R)
{
return minn[o];
}
int m=l+r>>1,res=inf;
#ifdef cmlSEGSUM
pushdown(o,l,r);
#else
pushdown(o);
#endif
if(L<=m)res=min(res,qmin(o<<1,l,m,L,R));
if(m<R)res=min(res,qmin(o<<1|1,m+1,r,L,R));
return res;
}
#endif
#ifdef cmlSEGMAX
int qmax(int o,int l,int r,int L,int R)
{
if(L<=l&&r<=R)
{
return maxn[o];
}
int m=l+r>>1,res=-inf;
#ifdef cmlSEGSUM
pushdown(o,l,r);
#else
pushdown(o);
#endif
if(L<=m)res=max(res,qmax(o<<1,l,m,L,R));
if(m<R)res=max(res,qmax(o<<1|1,m+1,r,L,R));
return res;
}
#endif
#ifdef cmlSEGSUM
int qsum(int o,int l,int r,int L,int R)
{
if(L<=l&&r<=R)
{
return sum[o];
}
int m=l+r>>1,res=0;
#ifdef cmlSEGSUM
pushdown(o,l,r);
#else
pushdown(o);
#endif
if(L<=m)res+=qsum(o<<1,l,m,L,R);
if(m<R)res+=qsum(o<<1|1,m+1,r,L,R);
return res;
}
#endif
};
#define newe(n) struct Edge{int v,w,nxt;}e[2*n+5];\
typedef int arr[n+5];\
arr h;\
int cnt=1;\
inline void addedge(int u,int v,int w){e[cnt]=(Edge){v,w,h[u]};h[u]=cnt++;}\
struct node{\
int u,d;\
bool operator<(const node&b)const{return d>b.d;}\
};\
void dij(int s,int *d,int N)\
{\
memset(d,0x3f,sizeof(int)*(N+3));\
d[s]=0;std::priority_queue<node>q;q.push((node){s,0});\
while(!q.empty())\
{\
int u=q.top().u,D=q.top().d;q.pop();if(D!=d[u])continue;\
for(int i=h[u];i;i=e[i].nxt){int v=e[i].v,w=e[i].w;\
if(d[u]+w<d[v])d[v]=d[u]+w,q.push((node){v,d[v]});\
}\
}\
}
#define mgs int fa[1<<22],sz[1<<22];\
inline int f(int x){return x==fa[x]?x:fa[x]=f(fa[x]);}\
inline int uf(int x,int y)\
{\
int fx=f(x),fy=f(y);\
if(fx==fy)return 0;\
if(sz[fx]>sz[fy])fx^=fy^=fx^=fy;\
fa[fx]=fy,sz[fy]+=sz[fx];\
return 1;\
}
inline int read()
{
int num=0,f=1;char c=getchar();
while(c<48||c>57){if(c=='-')f=-1;c=getchar();}
while(c>47&&c<58)num=num*10+(c^48),c=getchar();
return num*f;
}
inline int re1d()
{
char c=getchar();
while(c<48||c>49)c=getchar();
return c&1;
}
#ifdef cmlBIT
struct BIT{int a[1<<20|1],n;
void add(int x,int p){while(x<=n)a[x]+=p,x+=x&-x;}
int operator[](int x){int res=0;while(x)res+=a[x],x-=x&-x;return res;}
int operator()(int l,int r){return (*this)[r]-(*this)[l-1];}};
#endif
int rnv[1000005];
// #define COMB
#ifdef COMB
#ifndef int
#define int long long
#endif
int fac[1000005],inv[1000005];
#endif
void initprog()
{
#ifdef COMB
fac[0]=inv[0]=inv[1]=1;
rg(1000000)fac[i]=fac[i-1]*i%mod;gr
rg(1000000)if(i>1)inv[i]=inv[mod%i]*(mod-mod/i)%mod;gr
rg(1000000)rnv[i]=inv[i];gr
rg(1000000)inv[i]=inv[i]*inv[i-1]%mod;gr
#endif
}
#ifdef COMB
int C(int n,int m)
{
if(n==m||m==0)return 1;
if(n<m)return 0;
return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
#endif
inline int qp(int a,int b){int c=1;while(b){if(b&1)c=c*a%mod;a=a*a%mod;b>>=1;}return c;}
inline int mae(int &a,int b){a+=b;if(a>=mod)a-=mod;return a;}
inline int mde(int &a,int b){a+=mod-b;if(a>=mod)a-=mod;return a;}
inline int mle(int &a,int b){a=a*b%mod;return a;}
inline int mve(int &a,int b){a=a*qp(b,mod-2)%mod;return a;}
inline int mxe(int &a,int b){return a=a>b?a:b;}
inline int mne(int &a,int b){return a=a<b?a:b;}
inline int ae(int a,int b){int c=a+b;return c>=mod?c-mod:c;}
inline int de(int a,int b){return ae(a,mod-b);}
inline int me(int a,int b){return a*b%mod;}
inline int mive(int &a,int b){a=a*rnv[b]%mod;return a;}
inline int ive(int a,int b){return a*rnv[b]%mod;}
inline int ve(int a,int b){return a*qp(b,mod-2)%mod;}
#ifdef cmlST
struct STmin{
int a[21][1000005],n;
void init(int N,int *b)
{
n=N;
rg(n)a[0][i]=b[i];gr
rg(20)rg_(j,n-(1<<i)+1)a[i][j]=min(a[i-1][j],a[i-1][j+(1<<i-1)]);gr gr
}
int q(int l,int r)
{
int d=std::__lg(r-l+1);
return min(a[d][l],a[d][r-(1<<d)+1]);
}
};
struct STmax{
int a[21][1000005],n;
void init(int N,int *b)
{
n=N;
rg(n)a[0][i]=b[i];gr
rg(20)rg_(j,n-(1<<i)+1)a[i][j]=max(a[i-1][j],a[i-1][j+(1<<i-1)]);gr gr
}
int q(int l,int r)
{
int d=std::__lg(r-l+1);
return max(a[d][l],a[d][r-(1<<d)+1]);
}
};
#endif
#ifdef cmlSAM
struct SAM{
int ch[1000005][26],lnk[1000005],len[1000005],lst=1,cc=1;
int sz[1000005];
void insert(int c)
{
len[++cc]=len[lst]+1;sz[cc]=1;
int p=lst;lst=cc;
while(p&&ch[p][c]==0)ch[p][c]=cc,p=lnk[p];
if(p==0)lnk[cc]=1;
else
{
int x=ch[p][c];
if(len[p]+1==len[x])lnk[cc]=x;
else
{
int q=cc;++cc;
lnk[cc]=lnk[x];
lnk[x]=lnk[q]=cc;
len[cc]=len[p]+1;
memcpy(ch[cc],ch[x],sizeof(ch[cc]));
while(p&&ch[p][c]==x)ch[p][c]=cc,p=lnk[p];
}
}
}
newe(1000005);
long long ans;
void build()
{
rg(cc)addedge(lnk[i],i,0);gr
}
void dfs(int u)
{
fe(u)dfs(v),sz[u]+=sz[v];gr
if(sz[u]>1)ans=max(ans,1ll*sz[u]*len[u]);
}
}t;
#endif
std::unordered_set<int>s[77];
int n,m;
int sz[77];
int a[1234567];
int cc,z;
int tot=0;
void join(int x,int d,std::vector<int>&tmp)
{
if(s[d].count(x))return;
tmp.push_back(x);
s[d].insert(x);
// if(__builtin_popcountll(x)!=d)
// {
// printf("%lld %d\n",x,d);
// exit(0);
// }
for(int t:s[d])
if(__builtin_popcountll(t|x)==d+1)
join(t|x,d+1,tmp);
}
int vis[123456];
bool dfs(int u,int tag,int nw,int lst=0,int prev=0)
{
if(nw>n||u>n||z>m)return 0;
const int Z=60;
if(u>Z||nw>Z)return 0;
vis[z]=1;
if(z==m)
{
// puts("found");
int sum=0;
int res=(1ll<<n)-1;
rrg(n+1)for(int j:s[i])res&=~j;gr
rrg(n+1)for(int j:s[i])oldb(j?j|res:0);gr puts("");
// rrg(n+1)sum+=s[i].size();gr
// assert(sum==z);
return 1;
}
const int B=40;
if(s[u].size()>=1&&u<=B)
{
if(dfs(u+1,0,nw,prev,prev))return 1;
}
std::vector<int>tmp;
int v=(*s[u-1].begin())|(1ll<<nw);
// odb(lst),odp(v,u);
join(v,u,tmp);
z+=tmp.size();
if(dfs(u,1,nw+1,lst,v))return 1;
for(int t:tmp)s[__builtin_popcountll(t)].erase(t);
z-=tmp.size();
if(s[u].size()>=1&&u>B)
{
if(dfs(u+1,0,nw,prev,prev))return 1;
}
// if(tag&&u>B)
// {
// if(dfs(u+1,0,nw,prev,prev))return 1;
// }
return 0;
}
signed main()
{
initprog();
s[0].insert(0);
int T=read();rg(T)
n=read(),m=read();
rg(n)s[i].clear();gr
rg(n)sz[i]=0;gr sz[0]=1;
cc=0;z=1;
dfs(1,0,0);
// rg(1830)od(vis[i]);gr puts("");
// odl(tot);
gr
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 8096kb
input:
3 3 5 4 8 60 2
output:
0 1 5 3 7 0 2 1 6 3 14 7 15 0 1152921504606846975
result:
ok AC
Test #2:
score: 0
Accepted
time: 0ms
memory: 5716kb
input:
30 6 2 6 3 6 4 6 5 6 6 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 7 2 7 3 7 4 7 5 7 6 7 7 7 8 7 9 7 10 7 11
output:
0 63 0 61 63 0 57 59 63 0 49 51 55 63 0 33 35 39 47 63 0 1 3 7 15 31 63 0 1 3 7 15 47 31 63 0 1 3 7 23 15 55 31 63 0 1 3 11 7 27 15 59 31 63 0 1 3 7 39 23 15 47 55 31 63 0 1 3 11 7 43 27 15 47 59 31 63 0 1 5 3 13 7 45 29 15 47 61 31 63 0 1 3 19 11 7 51 23 27 15 59 55 31 63 0 1 5 3 21 13...
result:
ok AC
Test #3:
score: 0
Accepted
time: 2ms
memory: 5856kb
input:
30 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 7 26 7 27 7 28 8 2 8 3 8 4 8 5 8 6 8 7 8 8 8 9 8 10 8 11 8 12 8 13 8 14
output:
0 1 3 7 15 79 47 31 95 111 63 127 0 1 3 7 23 15 87 55 31 95 119 63 127 0 1 3 11 7 27 15 91 59 31 95 123 63 127 0 1 3 7 39 23 15 103 47 55 31 119 111 63 127 0 1 3 11 7 43 27 15 107 47 59 31 123 111 63 127 0 1 5 3 13 7 45 29 15 47 61 109 31 125 111 63 127 0 1 3 19 11 7 51 23 27 15 115 59 55 31 1...
result:
ok AC
Test #4:
score: 0
Accepted
time: 3ms
memory: 5768kb
input:
30 8 15 8 16 8 17 8 18 8 19 8 20 8 21 8 22 8 23 8 24 8 25 8 26 8 27 8 28 8 29 8 30 8 31 8 32 8 33 8 34 8 35 8 36 9 2 9 3 9 4 9 5 9 6 9 7 9 8 9 9
output:
0 1 3 7 23 15 55 31 183 119 63 191 247 127 255 0 1 3 7 15 79 47 31 207 95 111 63 239 223 127 255 0 1 3 7 23 15 87 55 31 215 95 119 63 247 223 127 255 0 1 3 11 7 27 15 91 59 31 95 123 219 63 251 223 127 255 0 1 3 7 39 23 15 103 47 55 31 231 119 111 63 239 247 127 255 0 1 3 7 15 143 79 47 31 159 ...
result:
ok AC
Test #5:
score: 0
Accepted
time: 3ms
memory: 5828kb
input:
30 9 10 9 11 9 12 9 13 9 14 9 15 9 16 9 17 9 18 9 19 9 20 9 21 9 22 9 23 9 24 9 25 9 26 9 27 9 28 9 29 9 30 9 31 9 32 9 33 9 34 9 35 9 36 9 37 9 38 9 39
output:
0 1 3 7 15 31 63 127 255 511 0 1 3 7 15 31 63 127 383 255 511 0 1 3 7 15 31 63 191 127 447 255 511 0 1 3 7 15 31 95 63 223 127 479 255 511 0 1 3 7 15 31 63 319 191 127 383 447 255 511 0 1 3 7 15 31 95 63 351 223 127 383 479 255 511 0 1 3 7 15 47 31 111 63 367 239 127 383 495 255 511 0 1 3 7 1...
result:
ok AC
Test #6:
score: 0
Accepted
time: 3ms
memory: 5856kb
input:
6 9 40 9 41 9 42 9 43 9 44 9 45
output:
0 1 3 11 7 43 27 15 299 171 107 47 59 31 315 363 427 303 187 175 235 123 111 63 319 379 491 431 443 191 239 367 251 127 383 495 507 447 255 511 0 1 5 3 13 7 45 29 15 301 173 109 47 61 31 317 303 365 429 189 175 125 111 237 63 367 381 319 493 431 445 191 239 253 127 383 495 509 447 255 511 0 1 3 19...
result:
ok AC
Test #7:
score: 0
Accepted
time: 128ms
memory: 5952kb
input:
30 60 1801 60 1802 60 1803 60 1804 60 1805 60 1806 60 1807 60 1808 60 1809 60 1810 60 1811 60 1812 60 1813 60 1814 60 1815 60 1816 60 1817 60 1818 60 1819 60 1820 60 1821 60 1822 60 1823 60 1824 60 1825 60 1826 60 1827 60 1828 60 1829 60 1830
output:
0 1134907106097364993 1134907106097364995 1134907106097364999 1134907106097365007 1134907106097365023 1134907106097365055 1134907106097365119 1134907106097365247 1134907106097365503 1134907106097366015 1134907106097367039 1134907106097369087 1134907106097373183 1134907106097381375 113490710609739775...
result:
ok AC
Test #8:
score: 0
Accepted
time: 127ms
memory: 8356kb
input:
30 59 1741 59 1742 59 1743 59 1744 59 1745 59 1746 59 1747 59 1748 59 1749 59 1750 59 1751 59 1752 59 1753 59 1754 59 1755 59 1756 59 1757 59 1758 59 1759 59 1760 59 1761 59 1762 59 1763 59 1764 59 1765 59 1766 59 1767 59 1768 59 1769 59 1770
output:
0 540431955284459521 540431955284459523 540431955284459527 540431955284459535 540431955284459551 540431955284459583 540431955284459647 540431955284459775 540431955284460031 540431955284460543 540431955284461567 540431955284463615 540431955284467711 540431955284475903 540431955284492287 5404319552845...
result:
ok AC
Test #9:
score: 0
Accepted
time: 119ms
memory: 5976kb
input:
30 58 1682 58 1683 58 1684 58 1685 58 1686 58 1687 58 1688 58 1689 58 1690 58 1691 58 1692 58 1693 58 1694 58 1695 58 1696 58 1697 58 1698 58 1699 58 1700 58 1701 58 1702 58 1703 58 1704 58 1705 58 1706 58 1707 58 1708 58 1709 58 1710 58 1711
output:
0 252201579132747777 252201579132747779 252201579132747783 252201579132747791 252201579132747807 252201579132747839 252201579132747903 252201579132748031 252201579132748287 252201579132748799 252201579132749823 252201579132751871 252201579132755967 252201579132764159 252201579132780543 2522015791328...
result:
ok AC
Test #10:
score: -100
Wrong Answer
time: 1ms
memory: 5764kb
input:
30 2 2 2 3 3 2 3 3 3 4 3 5 3 6 4 2 4 3 4 4 4 5 4 6 4 7 4 8 4 9 4 10 5 2 5 3 5 4 5 5 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15
output:
0 3 0 1 3 0 7 0 5 7 0 1 3 7 0 1 5 3 7 0 2 1 6 3 7 0 15 0 13 15 0 9 11 15 0 1 3 7 15 0 1 3 11 7 15 0 1 5 3 13 7 15 0 2 1 6 3 14 7 15 0 1 9 5 3 11 13 7 15 0 2 1 10 6 3 11 14 7 15 0 31 0 29 31 0 25 27 31 0 17 19 23 31 0 1 3 7 15 31 0 1 3 7 23 15 31 0 1 3 11 7 27 15 31 0 1 5 3 13 ...
result:
wrong output format Unexpected end of file - int64 expected