码迷,mamicode.com
首页 > 其他好文 > 详细

BZOJ2506 calc

时间:2014-11-17 00:13:58      阅读:285      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   color   ar   os   sp   for   

Orz hzwer巨巨

竟然要分块。。。本来以为离线就好了。。。

 

bubuko.com,布布扣
 1 /**************************************************************
 2     Problem: 2506
 3     User: rausen
 4     Language: C++
 5     Result: Accepted
 6     Time:920 ms
 7     Memory:6320 kb
 8 ****************************************************************/
 9  
10 #include <cstdio>
11 #include <algorithm>
12  
13 using namespace std;
14 const int N = 100005;
15 const int M = 105;
16  
17 struct data {
18     int x, p, k, w, f;
19     data() {}
20     data(int _x, int _p, int _k, int _w, int _f) : x(_x), p(_p), k(_k), w(_w), f(_f) {}
21 }q[N << 1];
22 inline bool operator < (const data &a, const data &b) {
23     return a.x < b.x;
24 }
25  
26 int n, m, tot, Max;
27 int a[N], f1[M][M], f2[N];
28 int ans[2][N];
29  
30 inline int read() {
31     int x = 0;
32     char ch = getchar();
33     while (ch < 0 || 9 < ch)
34         ch = getchar();
35     while (0 <= ch && ch <= 9) {
36         x = x * 10 + ch - 0;
37         ch = getchar();
38     }
39     return x;
40 }
41  
42 void add(int x) {
43     for (int i = 1; i <= 100; ++i)
44         ++f1[i][x % i];
45     ++f2[x];
46 }
47  
48 int main() {
49     int i, j;
50     int l, r, p, k;
51     n = read(), m = read();
52     for (i = 1; i <= n; ++i)
53         a[i] = read(), Max = max(Max, a[i]);
54     for (i = 1; i <= m; ++i) {
55         l = read(), r = read(), p = read(), k = read();
56         q[++tot] = data(l - 1, p, k, i, 0);
57         q[++tot] = data(r, p, k, i, 1);
58     }
59     sort(q + 1, q + tot + 1);
60     int now = 0;
61     for (i = 1; i <= tot; ++i) {
62         while (now < q[i].x)
63             ++now, add(a[now]);
64         p = q[i].p, k = q[i].k;
65         if (p <= 100)
66             ans[q[i].f][q[i].w] = f1[p][k];
67         else
68             for (j = k; j <= Max; j += p)
69                 ans[q[i].f][q[i].w] += f2[j];
70     }
71     for (i = 1; i <= m; ++i)
72         printf("%d\n", ans[1][i] - ans[0][i]);
73 }
View Code

 

BZOJ2506 calc

标签:style   blog   http   io   color   ar   os   sp   for   

原文地址:http://www.cnblogs.com/rausen/p/4102636.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!