Submission #100762

#TimeUsernameProblemLanguageResultExecution timeMemory
100762dalgerokRelativnost (COCI15_relativnost)C++17
0 / 140
42 ms33792 KiB
#include<bits/stdc++.h> using namespace std; const int N = 1e5 + 5, M = 25, MOD = 1e4 + 7; int n, m, q, a[N], b[N]; struct item{ int dp[M]; item(){ memset(dp, 0, sizeof(dp)); } }; item t[4 * N]; inline item mrg(item a, item b){ item c; for(int i = 0; i <= m; i++){ for(int j = 0; j <= m; j++){ c.dp[min(m, i + j)] += 1LL * a.dp[i] * b.dp[j] % MOD; } } for(int i = 0; i <= m; i++){ c.dp[i] %= MOD; } return c; } void build(int v, int l, int r){ if(l == r){ t[v].dp[0] = a[l]; t[v].dp[1] = b[l]; return; } int mid = (r + l) >> 1; build(v + v, l, mid); build(v + v + 1, mid + 1, r); t[v] = mrg(t[v + v], t[v + v + 1]); } void update(int v, int l, int r, int pos){ if(l == r){ t[v].dp[0] = a[l]; t[v].dp[1] = b[l]; return; } int mid = (r + l) >> 1; if(pos <= mid){ update(v + v, l, mid, pos); } else{ update(v + v + 1, mid + 1, r, pos); } t[v] = mrg(t[v + v], t[v + v + 1]); } int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n >> m; for(int i = 1; i <= n; i++){ cin >> a[i]; a[i] %= MOD; } for(int i = 1; i <= n; i++){ cin >> b[i]; b[i] %= MOD; } build(1, 1, n); cin >> q; while(q--){ int pos, x, y; cin >> pos >> x >> y; a[pos] = x; b[pos] = y; a[pos] %= MOD; b[pos] %= MOD; update(1, 1, n, pos); cout << t[1].dp[m] << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...