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

20140711 set

时间:2014-07-12 13:54:36      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   数据   os   

题目大意

维护一个可重集,支持:

插入一个正整数

询问一个正整数k,集合中有多少个数是k的倍数

数据范围是40000,时限0.5s

暴力肯定不行,想起这道题叫set,今天中午刚刚看了STL set用法,于是用了一个set来做,想着是logn的复杂度,其实还是n,总的就是n^2..............................................

后面才知道应该将插入的数分解因数,读入一个查询值直接输出即可,O(n*n^0.5)

bubuko.com,布布扣
 1 #include<cstdio>
 2 #include<string.h>
 3 using namespace std;
 4 
 5 int a[40000];
 6 
 7 int n;
 8 
 9 int main()
10 {
11     freopen("set.in","r",stdin);
12     freopen("set.out","w",stdout);
13     int x,y;
14     scanf("%d",&n);
15     int ans=0;
16     memset(a,0,sizeof(a));
17     while (n--)
18     {
19         scanf("%d%d",&x,&y);
20         if (x==1)
21          {
22         for (int i=1;i*i<=y;i++)
23          {
24             if(y%i==0)
25              {
26                 a[i]++;
27                 a[y/i]++;        
28             }
29             if (y==i*i) a[i]--;    
30             }
31         }
32     else
33          {
34              ans=ans xor a[y];            
35         }
36     }
37     printf("%d",ans);
38     return 0;
39 }
View Code

 

20140711 set,布布扣,bubuko.com

20140711 set

标签:style   blog   http   color   数据   os   

原文地址:http://www.cnblogs.com/woshizyj/p/3838132.html

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