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的数有奇数个,那就继续压缩数据取值域,缩小右区间就好。

猜你喜欢

转载自blog.csdn.net/c___c18/article/details/83747016