#pragma GCC optimize ("O3")
#include "dzilib.h"
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, b, e) for(int i = (b); i < (e); i++)
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
auto &operator<<(auto &o, pair<auto, auto> p) {
return o << "(" << p.st << ", " << p.nd << ")"; }
auto operator<<(auto &o, auto x)->decltype(end(x), o) {
o << "{"; int i=0; for(auto e: x) o << ", " + 2*!i++ << e;
return o << "}"; }
#ifdef LOCAL
#define deb(x...) cerr << "[" #x "]: ", [](auto...$) { \
((cerr << $ << "; "),...) << endl; }(x)
#else
#define deb(...)
#endif
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const int SHIFT = 13;
ll los(ll a, ll b) {
return rng() % (b - a + 1) + a;
}
ll losnp(ll a, ll b) {
ll res = 0;
while(res % 2 == 0) res = los(a, b);
return res;
}
ll lim;
ll ask(ll x) {
return Ask(x + SHIFT);
}
int dajbit(ll suffix, int kty) {
ll k = 1ll << (kty + 1);
ll doklej = k - suffix;
while(1) {
ll alpha = k * los(3, lim / k);
ll alpha2 = k * los(3, lim / k);
ll d1 = ask(alpha + doklej);
if(d1 == 2 * (kty + 1)) return 1;
if(d1 % (kty + 1)) return 0;
ll d2 = ask(k / 2 + alpha2 + doklej);
if(d2 == 2 * (kty + 1)) return 0;
if(d2 % (kty + 1)) return 1;
}
}
const int BRUT_B = 23;
const int BB = (1 << BRUT_B) * 3;
int divs[BB + 5];
void prep() {
FOR(i, 1, BB) for(int j = i; j < BB; j += i) divs[j]++;
}
ll brut(ll suff, int k) {
ll doklej = (1ll << k) - suff;
ll slim = 1 << BRUT_B;
vi cands;
while(sz(cands) != 1) {
ll pot_k = (1ll << k) / 2;
ll alpha = losnp(0, slim);
ll d = ask(alpha * pot_k + doklej);
if(sz(cands) == 0) {
FOR(cand, 1, slim) if(ll(k) * divs[cand * 2 + alpha] == d) cands.pb(cand);
}
else {
vi ncands;
for(int &cand: cands) if(ll(k) * divs[cand * 2 + alpha] == d) ncands.pb(cand);
cands = ncands;
}
// deb(sz(cands));
}
return (ll(cands[0]) << k) - doklej;
}
void solve() {
prep();
int t = GetT();
int q = GetQ();
lim = GetC() / 1000; // adapt
ll n = GetN() + SHIFT;
int bity = 1;
while(1ll << bity <= n) bity++;
int zgaduj_bity = max(1, bity - BRUT_B);
FOR(test, 0, t) {
ll suff = 0;
FOR(i, 0, zgaduj_bity) {
int bit = dajbit(suff, i);
suff ^= ll(bit) << i;
}
suff = brut(suff, zgaduj_bity);
Answer(suff - SHIFT);
}
}
int main() {
// cin.tie(0)->sync_with_stdio(0);
int tt = 1;
// cin >> tt;
FOR(te, 0, tt) solve();
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | #pragma GCC optimize ("O3") #include "dzilib.h" #include <bits/stdc++.h> using namespace std; #define FOR(i, b, e) for(int i = (b); i < (e); i++) #define sz(x) int(x.size()) #define all(x) x.begin(), x.end() #define pb push_back #define mp make_pair #define st first #define nd second using ll = long long; using vi = vector<int>; using pii = pair<int, int>; auto &operator<<(auto &o, pair<auto, auto> p) { return o << "(" << p.st << ", " << p.nd << ")"; } auto operator<<(auto &o, auto x)->decltype(end(x), o) { o << "{"; int i=0; for(auto e: x) o << ", " + 2*!i++ << e; return o << "}"; } #ifdef LOCAL #define deb(x...) cerr << "[" #x "]: ", [](auto...$) { \ ((cerr << $ << "; "),...) << endl; }(x) #else #define deb(...) #endif mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const int SHIFT = 13; ll los(ll a, ll b) { return rng() % (b - a + 1) + a; } ll losnp(ll a, ll b) { ll res = 0; while(res % 2 == 0) res = los(a, b); return res; } ll lim; ll ask(ll x) { return Ask(x + SHIFT); } int dajbit(ll suffix, int kty) { ll k = 1ll << (kty + 1); ll doklej = k - suffix; while(1) { ll alpha = k * los(3, lim / k); ll alpha2 = k * los(3, lim / k); ll d1 = ask(alpha + doklej); if(d1 == 2 * (kty + 1)) return 1; if(d1 % (kty + 1)) return 0; ll d2 = ask(k / 2 + alpha2 + doklej); if(d2 == 2 * (kty + 1)) return 0; if(d2 % (kty + 1)) return 1; } } const int BRUT_B = 23; const int BB = (1 << BRUT_B) * 3; int divs[BB + 5]; void prep() { FOR(i, 1, BB) for(int j = i; j < BB; j += i) divs[j]++; } ll brut(ll suff, int k) { ll doklej = (1ll << k) - suff; ll slim = 1 << BRUT_B; vi cands; while(sz(cands) != 1) { ll pot_k = (1ll << k) / 2; ll alpha = losnp(0, slim); ll d = ask(alpha * pot_k + doklej); if(sz(cands) == 0) { FOR(cand, 1, slim) if(ll(k) * divs[cand * 2 + alpha] == d) cands.pb(cand); } else { vi ncands; for(int &cand: cands) if(ll(k) * divs[cand * 2 + alpha] == d) ncands.pb(cand); cands = ncands; } // deb(sz(cands)); } return (ll(cands[0]) << k) - doklej; } void solve() { prep(); int t = GetT(); int q = GetQ(); lim = GetC() / 1000; // adapt ll n = GetN() + SHIFT; int bity = 1; while(1ll << bity <= n) bity++; int zgaduj_bity = max(1, bity - BRUT_B); FOR(test, 0, t) { ll suff = 0; FOR(i, 0, zgaduj_bity) { int bit = dajbit(suff, i); suff ^= ll(bit) << i; } suff = brut(suff, zgaduj_bity); Answer(suff - SHIFT); } } int main() { // cin.tie(0)->sync_with_stdio(0); int tt = 1; // cin >> tt; FOR(te, 0, tt) solve(); return 0; } |
English