# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1016007 | May27_th | Relativnost (COCI15_relativnost) | C++17 | 4059 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;
#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<i64> f;
Data () {
f.resize(C + 2, 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 ++) {
i64 &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<int> a(N + 2), b(N + 2);
for (int i = 1; i <= N; i ++) cin >> a[i];
for (int i = 1; i <= N; i ++) cin >> b[i];
Tree T(N);
for (int i = 1; i <= N; i ++) {
T.update(1, 1, N, i, mp(a[i], b[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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |