Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #define MAXN 16777216
  2. #include <iostream>
  3. #include <fstream>
  4. #include <cmath>
  5. #include <string>
  6. #include <cstdio>
  7.  
  8.  
  9.  
  10. using namespace std;
  11. unsigned int  add, l, r;
  12. unsigned int nextRand();
  13. unsigned int cur = 0;
  14.  
  15.  
  16. unsigned int m, q, c, b;
  17. long long a[MAXN + 1];
  18.  
  19. unsigned int lal = 0;
  20. int main(){
  21.     ifstream cin("input.txt");
  22.     ofstream cout("output.txt");   
  23.     cin >> m >> q >> c >> b;   
  24.     memset(a, 0, sizeof(a));
  25.  
  26.     for (int i = 0; i < m; i++){
  27.         add = nextRand();
  28.         l = nextRand();
  29.         r = nextRand();
  30.         if (l > r) swap(l, r);
  31.         a[l] += add;
  32.         a[r + 1] -= add;
  33.         }
  34.     for (int i = 1; i < MAXN; i++)
  35.         a[i] += a[i - 1];
  36.    
  37.     for (int i = 0; i < q; i++){
  38.         l = nextRand();
  39.         r = nextRand();
  40.         if (l > r) swap(l, r);
  41.             if (l == 0)
  42.         lal += a[r];
  43.             else lal += a[r] - a[l - 1];
  44.     }
  45.  
  46.     cout << lal;
  47. return 0;
  48. }
  49.  
  50. unsigned int nextRand() {
  51.  cur = cur * c + b;
  52.  return cur >> 8;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement