#include #include #include #include using namespace std; typedef unsigned int UINT; typedef unsigned long long ULONGLONG; #define UINT_BIT (CHAR_BIT * sizeof(UINT)) #define UPDIV(x, n) (((x) + (n) - 1) / (n)) #define MAX_N 2000000 char result[MAX_N + 1]; int main() { #if 0 ifstream in("test_in/in1"); ofstream out("temp_1.txt"); #else #define in cin #define out cout #endif UINT N, S, X, Y, Z; in >> N >> S >> X >> Y >> Z; vector A, B; A.resize(UPDIV(N, UINT_BIT)); B.resize(UPDIV(N, UINT_BIT)); ULONGLONG a = S; for (UINT i = 0; i < N; i++) { A[i / UINT_BIT] |= (a & 1) << (i % UINT_BIT); a = (X * a + Y) % Z; } UINT Q; in >> Q; for (UINT q = 0; q < Q; q++) { UINT s, t, u, v; in >> s >> t >> u >> v; s--; t--; u--; v--; UINT t_idx = t / UINT_BIT; UINT t_off = t % UINT_BIT; UINT v_idx = v / UINT_BIT; UINT v_off = v % UINT_BIT; for (UINT i = s / UINT_BIT; i <= t_idx; i++) { B[i] = A[i]; } while (s <= t) { UINT s_idx = s / UINT_BIT; UINT s_off = s % UINT_BIT; UINT u_idx = u / UINT_BIT; UINT u_off = u % UINT_BIT; UINT w = B[s_idx]; UINT m = ~0U << s_off; if (t_idx == s_idx) { m &= ~0U >> (UINT_BIT - t_off - 1); } if (s_off > u_off) { w >>= s_off - u_off; m >>= s_off - u_off; A[u_idx] ^= w & m; u += UINT_BIT - s_off; s += UINT_BIT - s_off; } else if (u_off > s_off) { w <<= u_off - s_off; m <<= u_off - s_off; A[u_idx] ^= w & m; s += UINT_BIT - u_off; u += UINT_BIT - u_off; } else { A[u_idx] ^= w & m; s += UINT_BIT - u_off; u += UINT_BIT - u_off; } } } for (UINT i = 0; i < N; i++) { result[i] = "EO"[(A[i / UINT_BIT] >> (i % UINT_BIT)) & 1]; } result[N] = 0; out << result << endl; }