Submission #31687

#TimeUsernameProblemLanguageResultExecution timeMemory
31687buichitrung2001Relativnost (COCI15_relativnost)C++14
0 / 140
0 ms1840 KiB
#include <iostream> #include <cstdio> using namespace std; typedef long long ll; const int oo = 1e9 + 1; const int mod = 1e4 + 7; const int maxn = 1e5 + 5; int n, a, b, C, i, id, leaf[maxn], Q, u[maxn], t[maxn]; struct Node { int f[21]; }; Node St[4 * maxn]; void Build (int id, int l, int r) { if (i < l || i > r) return; if (l == r) { leaf[i] = id; St[id].f[0] = b % mod; St[id].f[1] = a % mod; return; } int mid = (l + r) / 2; Build (id * 2, l, mid); Build (id * 2 + 1, mid + 1, r); } void Merge (int id) { for (int j = 0; j <= C; ++j) St[id].f[j] = 0; for (int j = 0; j <= C; ++j) for (int l = 0; l <= C; ++l) St[id].f[min(C, l + j)] = (St[id].f[min(C, l + j)] + St[id * 2].f[j] * St[id * 2 + 1].f[l] % mod) % mod; } void Init() { cin >> n >> C; for (i = 1; i <= n; ++i) cin >> u[i]; for (i = 1; i <= n; ++i) cin >> t[i]; for (i = 1; i <= n; ++i) { a = u[i]; b = t[i]; Build (1, 1, n); } for (i = 4 * n - 1; i >= 1; --i) if (St[i].f[0] == 0) Merge(i); } void Solve() { cin >> Q; for (i = 1; i <= Q; ++i) { cin >> id >> a >> b; St[leaf[id]].f[0] = b % mod; St[leaf[id]].f[1] = a % mod; int u = leaf[id]; while (true) { u = u / 2; if (u == 0) break; Merge (u); } cout << St[1].f[C] << '\n'; } } int main() { ios_base :: sync_with_stdio(false); cin.tie(NULL); //freopen("RELATIVNOST.inp", "r", stdin); //freopen("RELATIVNOST.out", "w", stdout); Init(); Solve(); } //Date 30 Month 8 Year 2017
#Verdict Execution timeMemoryGrader output
Fetching results...