Advertisement
Guest User

Reincarnation Generator

a guest
Mar 12th, 2022
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. //assume that rnd.next(a, b) returns a random number in the range [a, b]
  2. //assume that shuffle() shuffles the array uniformly and randomly
  3. //the generated data is written to stdout
  4.  
  5. #include "testlib.h"
  6. #include <algorithm>
  7. #include <iostream>
  8. #include <cstdio>
  9. #include <vector>
  10. #include <cmath>
  11. #include <numeric>
  12. #include <functional>
  13. using namespace std;
  14.  
  15. #define all(x) x.begin(), x.end()
  16.  
  17. int main(int argc, char* argv[]) {
  18.   registerGen(argc,argv,1);
  19.     int n = atoi(argv[1]); //number of elements in array
  20.     int q = atoi(argv[2]); //number of queries
  21.     int rollback_count = atoi(argv[3]); //total amount of rollbacks
  22.     int d = atoi(argv[4]); //maximum value of d
  23.     int ai = atoi(argv[5]); //maximum value of an element in the array
  24.    
  25.     printf("%d %d\n", n, q);
  26.    
  27.     vector<int> does_rollback(q), perm(q);
  28.     iota(all(perm), 0);
  29.     shuffle(all(perm));
  30.     for(int i = 0; i<rollback_count; i++){
  31.         does_rollback[perm[i]] = 1;
  32.     }
  33.     for(int t = 1; t<=q; t++){
  34.         int op = (does_rollback[t-1]) ? 2 : 1;
  35.         int dd = rnd.next(1, d);
  36.         if(op == 1){
  37.             int l = rnd.next(1, n), r = rnd.next(1, n);
  38.             if(l > r) swap(l, r);
  39.             int x = rnd.next(1, ai);
  40.             printf("%d %d %d %d %d\n", op, dd, l, r, x);
  41.         }else{
  42.             int k = rnd.next(0, t-1);
  43.             printf("%d %d %d\n", op, dd, k);
  44.         }
  45.     }
  46.  
  47.  
  48.  
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement