Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef unsigned long long ull;
- #define all(x) x.begin(), x.end()
- #define rall(x) x.rbegin(), x.rend()
- ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }
- ll fac(ll a) { return (a ? a * fac(a - 1) : 1); }
- int n, p, q, m;
- unsigned int SA, SB, SC;
- vector<unsigned int> v, maxx;
- unsigned int res = 0;
- unsigned int rng61() {
- SA ^= SA << 16;
- SA ^= SA >> 5;
- SA ^= SA << 1;
- unsigned int t = SA;
- SA = SB;
- SB = SC;
- SC ^= t ^ SA;
- return SC;
- }
- void gen() {
- cin >> n >> p >> q >> m >> SA >> SB >> SC;
- v.clear();
- maxx.clear();
- maxx.reserve(n);
- v.reserve(n);
- res = 0;
- for (int i = 1; i <= n; i++) {
- if (rng61() % (p + q) < p) {
- unsigned int t = rng61() % m + 1;
- v.push_back(t);
- if (maxx.size() == 0) maxx.push_back(t);
- else maxx.push_back(max<unsigned int>(t, maxx.back()));
- }
- else if(v.size() > 0) {
- maxx.pop_back();
- v.pop_back();
- }
- unsigned int t;
- if (maxx.size() > 0)
- t = maxx.back();
- else t = 0;
- res ^= i * t;
- }
- }
- signed main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int cur_q = 1, max_q;
- cin >> max_q;
- while (cur_q <= max_q) {
- gen();
- cout << "Case #" << cur_q << ": " << res << "\n";
- ++cur_q;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement