给一个长度为n的非负整数序列A1,A2,…,An。现有m个询问,每次询问给出l,r,p,k,问满足l<=i<=r且Ai mod p = k的值i的个数。
标签:des style blog http io color ar os sp
数据范围:
0<n,m<=10^5,任意1<=i<=n满足Ai<=10^4,0<p<=10^4,0<=k<p。
1 #include<cstdio> 2 3 #include<cstdlib> 4 5 #include<cmath> 6 7 #include<cstring> 8 9 #include<algorithm> 10 11 #include<iostream> 12 13 #include<vector> 14 15 #include<map> 16 17 #include<set> 18 19 #include<queue> 20 21 #include<string> 22 23 #define inf 1000000000 24 25 #define maxn 200000+5 26 27 #define maxm 500+100 28 29 #define eps 1e-10 30 31 #define ll long long 32 33 #define pa pair<int,int> 34 35 #define for0(i,n) for(int i=0;i<=(n);i++) 36 37 #define for1(i,n) for(int i=1;i<=(n);i++) 38 39 #define for2(i,x,y) for(int i=(x);i<=(y);i++) 40 41 #define for3(i,x,y) for(int i=(x);i>=(y);i--) 42 43 #define mod 1000000007 44 45 using namespace std; 46 47 inline int read() 48 49 { 50 51 int x=0,f=1;char ch=getchar(); 52 53 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} 54 55 while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();} 56 57 return x*f; 58 59 } 60 int n,m,tot,mx,ans[maxn][2],a[maxn],f[105][105],g[maxn]; 61 struct rec{int x,p,q,id,f;}b[maxn]; 62 inline void add(int x) 63 { 64 for1(i,100)f[i][x%i]++; 65 g[x]++; 66 } 67 inline bool cmp(rec a,rec b){return a.x<b.x;} 68 69 int main() 70 71 { 72 73 freopen("input.txt","r",stdin); 74 75 freopen("output.txt","w",stdout); 76 77 n=read();m=read(); 78 for1(i,n)a[i]=read(),mx=max(mx,a[i]); 79 for1(i,m) 80 { 81 int x=read(),y=read(),p=read(),q=read(); 82 b[++tot]=(rec){x-1,p,q,i,0}; 83 b[++tot]=(rec){y,p,q,i,1}; 84 } 85 sort(b+1,b+tot+1,cmp); 86 int now=0; 87 for1(i,tot) 88 { 89 while(now<b[i].x){now++;add(a[now]);} 90 int p=b[i].p,q=b[i].q; 91 if(p<=100)ans[b[i].id][b[i].f]=f[p][q]; 92 else for(int j=q;j<=mx;j+=p)ans[b[i].id][b[i].f]+=g[j]; 93 } 94 for1(i,m)printf("%d\n",ans[i][1]-ans[i][0]); 95 96 return 0; 97 98 }
标签:des style blog http io color ar os sp
原文地址:http://www.cnblogs.com/zyfzyf/p/4103123.html