我们直接模拟就可以了= =

now[x]表示x的倍数已经取到x * i了,于是每次读入x,直接向上枚举x个没取过的数即可。

 

 1 /**************************************************************
 2     Problem: 2793
 3     User: rausen
 4     Language: C++
 5     Result: Accepted
 6     Time:5296 ms
 7     Memory:14476 kb
 8 ****************************************************************/
 9  
10 #include <cstdio>
11 #include <algorithm>
12  
13 using namespace std;
14 typedef long long ll;
15 const int N = 1000005;
16  
17 int n, m, mx;
18 int now[N];
19 ll tot, ans[N], cnt;
20 bool f[N], vis[N];
21  
22 inline int read() {
23     int x = 0, sgn = 1;
24     char ch = getchar();
25     while (ch < '0' || '9' < ch) {
26         if (ch == '-') sgn = -1;
27         ch = getchar();
28     }
29     while ('0' <= ch && ch <= '9') {
30         x = x * 10 + ch - '0';
31         ch = getchar();
32     }
33     return sgn * x;
34 }
35  
36 int main() {
37     int i, x, t, C;
38     for (m = read(), i = 1; i <= m; ++i) {
39         x = read();
40         f[x] = 1, mx = max(mx, x);
41     }
42      
43     n = read();
44     while (n--) {
45         x = t = read();
46         for (i = now[x] + x, C = 0; i <= mx; i += x) {
47             if (!vis[i]) {
48                 ++cnt, --t, vis[i] = 1;
49                 if (f[i]) ans[++tot] = cnt;
50                 if (++C == x) break;
51             }
52             now[x] = i;
53         }
54         cnt += t;
55     }
56     printf("%lld\n", tot);
57     for (i = 1; i <= tot; ++i)
58         printf("%lld\n", ans[i]);
59 }
View Code

(p.s. 没有的搞懂,一开始各种WA,把ans数组改成long long就AC了?蒟蒻跪求大神求教)

posted on 2014-11-29 08:58  Xs酱~  阅读(269)  评论(0编辑  收藏  举报