?
№ | Отправитель | Задача | Язык | Вердикт | Время | Память | Отослано | Протест. | |
---|---|---|---|---|---|---|---|---|---|
171985514 |
Дорешивание: George1123 |
1495E - 33 | C++14 (GCC 6-32) | Полное решение | 561 мс | 117424 КБ | 2022-09-13 06:16:11 | 2022-09-13 06:16:11 |
#include <bits/stdc++.h> #define R(i, a, b) for (int i = (a); i < (b); ++i) #define L(i, a, b) for (int i = (b) - 1; i >= (a); --i) #define N(a) int((a).size()) #define V(a) (a).begin(), (a).end() #define B(a, n) (a), (a) + (n) #define spc << ' ' #define ntr << '\n' #define X(x) cerr << #x << " = " << (x) #define A(a) putA(cerr << #a << " = ", a) #define T() cerr << "TIME = " << double(clock() - T0) / CLOCKS_PER_SEC using namespace std; #define int long long using i64 = long long; clock_t T0 = clock(); template<class itp> ostream &putA(ostream &O, itp l, itp r) { for (itp x = l; x != r; ++x) O << *x spc; return O; } int nT, T; constexpr int xn = 5000007; int n, a[xn], t[xn], b[xn]; namespace generator { int m, seed, base; int rnd() { auto ret = seed; seed = (i64(seed) * base + 233) % 1000000007; return ret; } void work() { cin >> m; auto now = seed = base = 0; R(i, 0, m) { int p, k; cin >> p >> k >> seed >> base; R(j, now, p) { t[j] = rnd() % 2; a[j] = rnd() % k + 1; } now = p; } } }; void resolveT() { cin >> n; generator::work(); auto s = vector<i64>(2, 0); R(i, 0, n) s[t[i]] += a[i]; if (s[0] > s[1]) { swap(s[0], s[1]); R(i, 0, n) t[i] ^= 1; } // A(B(a, n)) ntr; // A(B(t, n)) ntr; R(i, 0, n) b[i] = 0; auto u = 0; if (t[0]) { a[0] -= 1; b[0] += 1; for (; u < n and t[u]; ++u); if (u >= n) return; } auto sum = i64(0); for (; s[0] or sum; ) { if (t[u]) { auto x = min<i64>(sum, a[u]); s[1] -= x; b[u] += x; a[u] -= x; sum -= x; } else { s[0] -= a[u]; b[u] += a[u]; sum += a[u]; a[u] = 0; } u = u == n - 1 ? 0 : u + 1; } // A(B(b, n)) ntr; } constexpr int mod = 1000000007; void solveT() { resolveT(); auto res = 1; R(i, 0, n) res = ((i64(i + 1) * (i + 1) ^ b[i]) + 1) % mod * res % mod; cout << res ntr; } signed main() { // freopen(".in", "r", stdin); cerr << fixed << setprecision(3); ios::sync_with_stdio(false); cin.tie(nullptr); // cin >> nT; nT = 1; for (; T < nT; ++T) solveT(); }
?
?
?
?