#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 time |
Memory |
Grader output |
1 |
Correct |
12 ms |
600 KB |
Output is correct |
2 |
Correct |
18 ms |
604 KB |
Output is correct |
3 |
Correct |
38 ms |
796 KB |
Output is correct |
4 |
Incorrect |
707 ms |
15956 KB |
Output isn't correct |
5 |
Incorrect |
2667 ms |
30900 KB |
Output isn't correct |
6 |
Execution timed out |
4046 ms |
47440 KB |
Time limit exceeded |
7 |
Incorrect |
1667 ms |
22948 KB |
Output isn't correct |
8 |
Incorrect |
1048 ms |
26704 KB |
Output isn't correct |
9 |
Incorrect |
1540 ms |
22120 KB |
Output isn't correct |
10 |
Execution timed out |
4042 ms |
34132 KB |
Time limit exceeded |