Submission #230579

#TimeUsernameProblemLanguageResultExecution timeMemory
230579ParsaAlizadehRelativnost (COCI15_relativnost)C++17
140 / 140
3781 ms24252 KiB
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; #define all(x) x.begin(), x.end() #define kill(x) return cout << x << endl, 0 #define X first #define Y second #define sep ' ' #define endl '\n' template<class T = ll> T nxt() {T x; cin >> x; return x;} ll pw(ll a, ll b, ll mod) { if (!b) return 1; if (b & 1) return a * pw(a * a % mod, b / 2, mod) % mod; return pw(a * a % mod, b / 2, mod) % mod; } const int N = 1e5 + 10; const int K = 22; const int MOD = 10007; int n, q, A[N], B[N], k, seg[N << 2][K]; void Merge(int id) { for (int i = 0; i <= k; i++) { seg[id][i] = 0; } for (int i = 0; i <= k; i++) { for (int j = 0; j <= k; j++) { seg[id][min(k, i + j)] += seg[2 * id][i] * seg[2 * id + 1][j] % MOD; seg[id][min(k, i + j)] %= MOD; } } } void Build(int id, int l, int r) { if (r - l == 1) { seg[id][0] = B[l]; seg[id][1] = A[l]; return; } int mid = (l + r) >> 1; Build(2 * id, l, mid); Build(2 * id + 1, mid, r); Merge(id); } void Update(int id, int l, int r, int ind) { if (ind < l || r <= ind) return; if (r - l == 1) { seg[id][0] = B[l]; seg[id][1] = A[l]; return; } int mid = (l + r) >> 1; if (ind < mid) Update(2 * id, l, mid, ind); else Update(2 * id + 1, mid, r, ind); Merge(id); } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> n >> k; for (int i = 0; i < n; i++) { cin >> A[i]; A[i] %= MOD; } for (int i = 0; i < n; i++) { cin >> B[i]; B[i] %= MOD; } Build(1, 0, n); cin >> q; while (q--) { int ind, a, b; cin >> ind >> a >> b; ind--; A[ind] = a % MOD; B[ind] = b % MOD; Update(1, 0, n, ind); cout << seg[1][k] << endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...