BZOJ2793: [Poi2012]Vouchers
题解:
感觉是不可做题啊。。。
看题解发现暴力就可以过囧。。。记录一下x倍数上次取到多少即可。
复杂度:n/1+n/2+……+n/n=nlnn
代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<cstdio> 2 #include<cstdlib> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<iostream> 7 #include<vector> 8 #include<map> 9 #include<set> 10 #include<queue> 11 #include<string> 12 #define inf 1000000000 13 #define maxn 1000000+5 14 #define maxm 1000000+5 15 #define eps 1e-10 16 #define ll long long 17 #define pa pair<int,int> 18 #define for0(i,n) for(int i=0;i<=(n);i++) 19 #define for1(i,n) for(int i=1;i<=(n);i++) 20 #define for2(i,x,y) for(int i=(x);i<=(y);i++) 21 #define for3(i,x,y) for(int i=(x);i>=(y);i--) 22 #define for4(i,x) for(int i=head[x],y=e[i].go;i;i=e[i].next,y=e[i].go) 23 #define mod 1000000007 24 using namespace std; 25 inline int read() 26 { 27 int x=0,f=1;char ch=getchar(); 28 while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} 29 while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();} 30 return x*f; 31 } 32 bool a[maxn]; 33 int n,mx,now[maxn]; 34 ll cnt,ans[maxn]; 35 bool v[maxn]; 36 int main() 37 { 38 freopen("input.txt","r",stdin); 39 freopen("output.txt","w",stdout); 40 n=read();int x; 41 while(n--)a[x=read()]=1,mx=max(mx,x); 42 n=read(); 43 while(n--) 44 { 45 x=read();int y=x; 46 for(int i=now[x]+x,j=0;i<=mx&&j<x;i+=x) 47 { 48 if(!v[i]) 49 { 50 cnt++;y--;j++; 51 v[i]=1; 52 if(a[i])ans[++ans[0]]=cnt; 53 } 54 now[x]=i; 55 } 56 cnt+=y; 57 } 58 printf("%lld\n",ans[0]); 59 for1(i,ans[0])printf("%lld\n",ans[i]); 60 return 0; 61 }