Submission #1016012

#TimeUsernameProblemLanguageResultExecution timeMemory
1016012May27_thRelativnost (COCI15_relativnost)C++17
42 / 140
4046 ms47440 KiB
#include<bits/stdc++.h> using namespace std; #define i64 long long #define i128 __int128 #define mp make_pair #define pb push_back #define all(x) (x).begin(), (x).end() const int MOD = 10007; int C; struct Tree { struct Data { vector<int> f; Data () { f.resize(C + 1, 0); } }; int N; vector<Data> st; Tree (int _N) : N(_N), st(_N * 4 + 4) {} Data combine(Data L, Data R) { Data res; for (int i = 0; i <= C; i ++) { for (int j = 0; j <= C; j ++) { int &add = res.f[min(i + j, C)]; add = (add + L.f[i] * R.f[j] % MOD) % MOD; // cout << i << " " << j << " " << res.f[min(i + j, C)] << " " << L.f[i] << " " << R.f[j] << "\n"; } } return res; }; void update(int id, int l, int r, int p, pair<int, int> x) { if (p < l || p > r) return; if (l == r) { st[id].f[0] = x.second; st[id].f[1] = x.first; return; } int mid = (l + r)/2; update(id * 2, l, mid, p, x); update(id * 2 + 1, mid + 1, r, p, x); st[id] = combine(st[id * 2], st[id * 2 + 1]); } }; void Solve(void) { int N; cin >> N >> C; vector<pair<int, int>> p(N); for (int i = 0; i < N; i ++) cin >> p[i].first; for (int i = 0; i < N; i ++) cin >> p[i].second; Tree T(N); for (int i = 0; i < N; i ++) { T.update(1, 1, N, i + 1, p[i]); } // cout << T.st[1].f[C] << "\n"; int Q; cin >> Q; while (Q --) { int p, A, B; cin >> p >> A >> B; T.update(1, 1, N, p, mp(A, B)); cout << T.st[1].f[C] << "\n"; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(10); int Tests = 1; // cin >> Tests; while (Tests --) { Solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...