Exercises
The feeling is not to do the problem ah ...
See the puzzle to find violence can be too embarrassing ... Record how many x multiples were last taken.
Complexity: N/1+N/2+......+N/N=NLNN
Code:
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>Ten#include <queue> One#include <string> A #defineINF 1000000000 - #defineMAXN 1000000+5 - #defineMAXM 1000000+5 the #defineEPS 1e-10 - #definell Long Long - #definePA pair<int,int> - #defineFor0 (i,n) for (int i=0;i<= (n); i++) + #defineFor1 (i,n) for (int i=1;i<= (n); i++) - #defineFor2 (i,x,y) for (int i= (x); i<= (y); i++) + #defineFor3 (i,x,y) for (int i= (x); i>= (y); i--) A #defineFor4 (i,x) for (int i=head[x],y=e[i].go;i;i=e[i].next,y=e[i].go) at #defineMoD 1000000007 - using namespacestd; -InlineintRead () - { - intx=0, f=1;CharCh=GetChar (); - while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} in while(ch>='0'&&ch<='9') {x=Ten*x+ch-'0'; ch=GetChar ();} - returnx*F; to } + BOOLA[MAXN]; - intN,MX,NOW[MAXN]; the ll CNT,ANS[MAXN]; * BOOLV[MAXN]; $ intMain ()Panax Notoginseng { -Freopen ("Input.txt","R", stdin); theFreopen ("output.txt","W", stdout); +N=read ();intx; A while(n--) A[x=read ()]=1, mx=Max (mx,x); then=read (); + while(n--) - { $X=read ();inty=x; $ for(inti=now[x]+x,j=0; i<=mx&&j<x;i+=x) - { - if(!V[i]) the { -cnt++;y--;j++;Wuyiv[i]=1; the if(A[i]) ans[++ans[0]]=CNT; - } Wunow[x]=i; - } Aboutcnt+=y; $ } -printf"%lld\n", ans[0]); -For1 (i,ans[0]) printf ("%lld\n", Ans[i]); - return 0; A}View Code
BZOJ2793: [Poi2012]vouchers