【题解】【小铃的书】
题意
有
题解
\mathbf{Subtask I \ \ \ \ :n\le 10^5}
将所有书排序,然后看看哪本书出现的次数对
特别的,如果使用
\mathbf{Subtask II \ \ :n\le 10^6}
考虑将每个数转换成
如果某个编号出现了
如果某个编号多出现了一次,那么最后计数数组取模后的结果就是这个编号的
\mathbf{Subtask III :n\le 10^7}
duliu mrz!!!
原来没有这个
延续上一个
关于算法复杂度:
该题想了挺久怎么卡掉奇怪的算法的
使用排序算法,空间为
使用
使用
使用
使用
另外,
其他
其实原计划,空间限制为
赛后应该会提供一个空间限制为
参考代码
#include<bits/stdc++.h>
#define up(l,r,i) for(int i=l;i<=r;i++)
#define dn(l,r,i) for(int i=l;i>=r;i--)
using namespace std;
typedef long long LL;
const int INF =2147483647;
LL qread(){
LL w=1,c,ret;
while((c=getchar())> '9'||c< '0')
w=(c=='-'?-1:1); ret=c-'0';
while((c=getchar())>='0'&&c<='9')
ret=ret*10+c-'0';
return ret*w;
}
const int MAXN =64+3;
int cnt[MAXN]; LL n,k,t=1,ans;
int main(){
n=qread(),k=qread();
if(k==2){
up(1,n,i) ans^=qread(); printf("%lld\n",ans);
return 0;
}
up(1,n,i){
LL x=qread(),t=0; while(x){
cnt[t]+=x%k,x/=k,++t;
}
}
up(0,MAXN-1,i) ans+=(cnt[i]%k)*t,t*=k;
printf("%lld\n",ans);
return 0;
}
#include<cstdio>
typedef long long LL;
#define gc pa==pb&&(pb=(pa=buf)+fread(buf,1,200000,stdin),pa==pb)?EOF:*pa++
static char buf[200000],*pa(buf),*pb(buf);
inline LL readint() {
LL x=0;char c=gc;
while(c<'0'||c>'9')c=gc;
for(;c>='0'&&c<='9';c=gc)x=x*10+(c&15);
return x;
}
int _1[65538],_2[65538],_3[65538],_4[65538],n,k;
int main(){
n=readint(),k=readint();
while(n--){
LL x=readint();
++_1[x>>48],++_2[x>>32&65535],++_3[x>>16&65535],++_4[x&65535];
}
LL ans=0;
for(int i=0;i<65536;++i)if(_1[i]%k){
ans|=(LL)i<<48;break;
}
for(int i=0;i<65536;++i)if(_2[i]%k){
ans|=(LL)i<<32;break;
}
for(int i=0;i<65536;++i)if(_3[i]%k){
ans|=(LL)i<<16;break;
}
for(int i=0;i<65536;++i)if(_4[i]%k){
ans|=(LL)i;break;
}
printf("%lld\n",ans);
return 0;
}