-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChefAndQueries.java
More file actions
58 lines (48 loc) · 1.37 KB
/
ChefAndQueries.java
File metadata and controls
58 lines (48 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package problems.codechef;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* Created by Arpit on 20-Dec-15.
*/
public class ChefAndQueries {
void solve(){
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String[]sp= new String[0];
try {
sp = br.readLine().split("\\s");
} catch (IOException e) {
e.printStackTrace();
}
int q=Integer.parseInt(sp[0]);
long s=Integer.parseInt(sp[1]);
long a=Integer.parseInt(sp[2]);
long b=Integer.parseInt(sp[3]);
long sum=0;
long set[]=new long[1<<25];
for (int i = 1 ; i <=q ; i++) {
int temp= (int) (s>>>1);
long x=set[temp>>>6];
long y=(1L<<(temp%64));
if (temp!=0)
if ((s&1)==1){
if ((x&y)==0){
set[temp>>>6]^=y;
sum+=temp;
}
}
else {
if (((x&y)<0||((x&y)>0))){
set[temp>>>6]^=y;
sum-=temp;
}
}
s = ((s*a+b)&((1L<<32)-1));
}
System.out.println(sum);
}
public static void main(String[] args) throws IOException {
ChefAndQueries c=new ChefAndQueries();
c.solve();
}
}