132 lines
2.2 KiB
Java
132 lines
2.2 KiB
Java
import java.math.BigInteger;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
import java.util.Random;
|
|
|
|
public class Main {
|
|
|
|
public static void main(String[] args) {
|
|
new Main().run();
|
|
}
|
|
|
|
int myId = message.MyNodeId();
|
|
int nodeCount = message.NumberOfNodes();
|
|
long aLength = todd_and_steven.GetToddLength();
|
|
long bLength = todd_and_steven.GetStevenLength();
|
|
long itemCount = (long) 5.05e9;
|
|
long perNode = itemCount / nodeCount + 1;
|
|
|
|
long iL = Math.min(myId * perNode, itemCount);
|
|
long iR = Math.min((myId + 1) * perNode, itemCount);
|
|
|
|
void run() {
|
|
client();
|
|
|
|
if (myId == 0) {
|
|
server();
|
|
}
|
|
}
|
|
|
|
long mul(long a, long b) {
|
|
return (a * b) % MOD;
|
|
}
|
|
|
|
long add(long a, long b) {
|
|
return (a + b) % MOD;
|
|
}
|
|
|
|
long MOD = 1000000007L;
|
|
long BIG = 1000000000000L;
|
|
|
|
long get(int type, long i) {
|
|
if (type == 0) {
|
|
if (i >= aLength) {
|
|
return BIG;
|
|
}
|
|
return todd_and_steven.GetToddValue(i);
|
|
}
|
|
if (type == 1) {
|
|
if (i >= bLength) {
|
|
return BIG;
|
|
}
|
|
return todd_and_steven.GetStevenValue(i);
|
|
}
|
|
throw new IllegalArgumentException();
|
|
}
|
|
|
|
long binSearch(int type, long minVal) {
|
|
long l = 0;
|
|
long r = BIG;
|
|
|
|
while (r - l > 1) {
|
|
long m = (l + r) / 2;
|
|
|
|
long x = get(type, m);
|
|
|
|
if (x < minVal) {
|
|
l = m;
|
|
} else {
|
|
r = m;
|
|
}
|
|
}
|
|
|
|
if (get(type, l) < minVal) {
|
|
l++;
|
|
}
|
|
|
|
return l;
|
|
}
|
|
|
|
void client() {
|
|
long minVal = iL;
|
|
long maxVal = iR;
|
|
|
|
long ai = binSearch(0, minVal);
|
|
long bi = binSearch(1, minVal);
|
|
|
|
long nextA = get(0, ai);
|
|
long nextB = get(1, bi);
|
|
|
|
long pos = ai + bi;
|
|
long res = 0;
|
|
|
|
while (true) {
|
|
long x = Math.min(nextA, nextB);
|
|
|
|
if (x >= maxVal) {
|
|
break;
|
|
}
|
|
|
|
res = add(res, x ^ pos);
|
|
pos++;
|
|
|
|
if (x == nextA) {
|
|
ai++;
|
|
nextA = get(0, ai);
|
|
}
|
|
|
|
if (x == nextB) {
|
|
bi++;
|
|
nextB = get(1, bi);
|
|
}
|
|
}
|
|
|
|
message.PutLL(0, res);
|
|
message.Send(0);
|
|
}
|
|
|
|
|
|
void server() {
|
|
long res = 0;
|
|
for (int i = 0; i < nodeCount; i++) {
|
|
message.Receive(i);
|
|
long x = message.GetLL(i);
|
|
|
|
res = add(res, x);
|
|
}
|
|
|
|
System.out.println(res);
|
|
}
|
|
}
|