# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
697278 | kusssso | Relativnost (COCI15_relativnost) | C++17 | 960 ms | 65536 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
const int N = 1e5 + 5;
const int mod = 10007;
int n, c;
int q;
int a[N];
int b[N];
struct Node {
ll tot;
vi dp;
}
st[4 * N];
void update (int p, ll va, ll vb, int x = 1, int L = 1, int R = n) {
if (L > p || R < p) return;
if (L == R && R == p) {
st[x].tot = (va + vb) % mod;
st[x].dp[0] = vb;
st[x].dp[1] = va;
return;
}
int mid = (L + R) / 2;
update(p, va, vb, x * 2, L, mid);
update(p, va, vb, x * 2 + 1, mid + 1, R);
st[x].tot = st[x * 2].tot * st[x * 2 + 1].tot % mod;
for (int k = 0; k < c; k++) {
st[x].dp[k] = 0;
for (int i = 0; i <= k; i++) {
st[x].dp[k] = (st[x].dp[k] + st[x * 2].dp[i] * st[x * 2 + 1].dp[k - i] % mod) % mod;
}
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> c;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
for (int i = 0; i < 4 * N; i++) st[i].dp.resize(c, 0);
for (int i = 1; i <= n; i++) update(i, a[i], b[i]);
cin >> q;
while (q--) {
int i, na, nb;
cin >> i >> na >> nb;
a[i] = na;
b[i] = nb;
update(i, na, nb);
ll total = st[1].tot;
ll bad = 0;
// cout << '#' << st[1].dp[0] << '\n';
for (int k = 0; k < c; k++) bad = (bad + st[1].dp[k]) % mod;
cout << (total + mod - bad) % mod << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |