Submission #100765

#TimeUsernameProblemLanguageResultExecution timeMemory
100765dalgerokRelativnost (COCI15_relativnost)C++17
140 / 140
2059 ms26872 KiB
#include<bits/stdc++.h> using namespace std; const int N = 1e5 + 5, M = 21, MOD = 1e4 + 7; int n, m, q, a[N], b[N], t[4 * N][M]; inline void upd(int v){ for(int i = 0; i <= m; i++){ t[v][i] = 0; } for(int i = 0; i <= m; i++){ for(int j = 0; j <= m; j++){ t[v][min(m, i + j)] += t[v + v][i] * t[v + v + 1][j] % MOD; } } for(int i = 0; i <= m; i++){ t[v][i] %= MOD; } } void build(int v, int l, int r){ if(l == r){ t[v][0] = b[l]; t[v][1] = a[l]; return; } int mid = (r + l) >> 1; build(v + v, l, mid); build(v + v + 1, mid + 1, r); upd(v); } void update(int v, int l, int r, int pos){ if(l == r){ t[v][0] = b[l]; t[v][1] = a[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); } upd(v); } 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][m] << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...