Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package LabaFirst;
- import java.util.Scanner;
- public class SumOnSection {
- public static void build (long a[], long tree[]) {
- tree[0] = a[0];
- for (int i = 1; i < a.length; i++) {
- tree[i] = tree[i-1] + a[i];
- }
- }
- public static void main (String args[]) {
- long answer = 0;
- Scanner in = new Scanner(System.in);
- int n = in.nextInt();
- long x = in.nextLong();
- long y = in.nextLong();
- long[]a = new long[n];
- a[0] = in.nextLong();
- for (int i = 1; i < n; i++) {
- a[i] = (long) ((x * a[i - 1] + y + Math.pow(2, 16)) % Math.pow(2, 16));
- }
- int m = in.nextInt();
- long z = in.nextLong();
- long t = in.nextLong();
- long[]b = new long[2 * m];
- b[0] = in.nextLong();
- for (int i = 1; i < b.length; i++) {
- b[i] = (long) ((z * b[i - 1] + t + Math.pow(2, 30)) % Math.pow(2, 30));
- }
- long[]c = new long[2 * m];
- for (int i = 0; i < c.length; i++) {
- c[i] = b[i] % n;
- }
- long tree[] = new long[n];
- build(a, tree);
- for (int i = 0; i < m; i++) {
- if (c[2*i] < c[2*i + 1]) {
- if (c[2*i] == 0) {
- answer = answer + tree[(int) c[2*i + 1]];
- } else {
- answer = answer + tree[(int) c[2*i + 1]] - tree[(int) (c[2*i] - 1)];
- }
- } else {
- if (c[2*i + 1] == 0) {
- answer = answer + tree[(int) c[2*i]];
- } else {
- answer = answer + tree[(int) c[2*i]] - tree[(int) (c[2*i + 1] - 1)];
- }
- }
- }
- in.close();
- System.out.println(answer);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement