POJ 3484 二分前缀和

Data-mining huge data sets can be a painful and long lasting process if we are not aware of tiny patterns existing within those data sets.

One reputable company has recently discovered a tiny bug in their hardware video processing solution and they are trying to create software workaround. To achieve maximum performance they use their chips in pairs and all data objects in memory should have even number of references. Under certain circumstances this rule became violated and exactly one data object is referred by odd number of references. They are ready to launch product and this is the only showstopper they have. They need YOU to help them resolve this critical issue in most efficient way.

Can you help them?

Input

Input file consists from multiple data sets separated by one or more empty lines.

Each data set represents a sequence of 32-bit (positive) integers (references) which are stored in compressed way.

Each line of input set consists from three single space separated 32-bit (positive) integers X Y Z and they represent following sequence of references: X, X+Z, X+2*Z, X+3*Z, …, X+K*Z, …(while (X+K*Z)<=Y).

Your task is to data-mine input data and for each set determine weather data were corrupted, which reference is occurring odd number of times, and count that reference.

Output

For each input data set you should print to standard output new line of text with either “no corruption” (low case) or two integers separated by single space (first one is reference that occurs odd number of times and second one is count of that reference).

Sample Input

1 10 1
2 10 1

1 10 1
1 10 1

1 10 1
4 4 1
1 5 1
6 10 1

Sample Output

1 1
no corruption
4 3

题意:每次给出三个数x,y,z,用这三个数构成一个等差数列,x为首项,y是末项,z是公差,总共给出n组x,y,z( n待定),求这n组数列中出现次数为奇数的那个数以及该数出现的次数(保证最多有一个数出现的次数为奇数)

 

 

没有办法去暴力,所有的数值只知道是在int范围内,但是开到数组很大,并且还要是long long 的类型,否则会WA,还有就是如何输入的问题,用到了sscanf,把前提解决了,剩下的就是用二分枚举答案了;

在这里mid枚举的是出现奇数次的数字,然后根据等差数列的定理,可以算出大于首项x的mid的前面的数字有多少个。。。,有点绕,就是比如给1 10 1 ,mid=5,那么就需要算出mid(包括)前面有多少个数(因为题目中保证只有一个答案,所以不妨就用前缀和单调的方法来解决,那么假设x就是那个奇数个数的数,x之间的数应该都是出现了偶数次,依据这个不断压缩左端点,也就是最大值),如果将所有的n组数列求完之后小于mid的数有奇数个,那就继续压缩数据取值域,缩小右区间就好。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值