#include <bits/stdc++.h>
using namespace std;
#define FNAME "test"
const int M = 10007;
const int N = 1e5 + 5;
int n, c, q;
int pos, vala, valb;
int a[N], b[N];
struct Node {
int chosen[21];
Node() {
memset(chosen, 0, sizeof(chosen));
}
Node operator + (const Node& oth) {
Node nNode;
for (int i = 0; i <= c; i++) {
for (int j = 0; j <= c; j++) {
nNode.chosen[min(c, i + j)] = (nNode.chosen[min(c, i + j)] + chosen[i] * oth.chosen[j]) % M;
}
}
return nNode;
}
} ST[3 * N];
Node merge(const Node& Node1, const Node& Node2) {
Node nNode;
for (int i = 0; i <= c; i++) {
for (int j = 0; j <= c; j++) {
nNode.chosen[min(c, i + j)] = (nNode.chosen[min(c, i + j)] + Node1.chosen[i] * Node2.chosen[j]) % M;
}
}
return nNode;
}
void Task() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(9);
if (fopen(FNAME".inp","r")) {
freopen(FNAME".inp","r",stdin);
freopen(FNAME".out","w",stdout);
}
}
void build(int id, int l, int r) {
if (l == r) {
ST[id].chosen[0] = b[l] % M;
ST[id].chosen[1] = a[r] % M;
return;
}
int m = (l + r) / 2;
build(id * 2, l, m);
build(id * 2 + 1, m + 1, r);
ST[id] = ST[id * 2] + ST[id * 2 + 1];
}
void update(int id, int l, int r, int pos, int vala, int valb) {
if (pos < l || r < pos) return;
if (l == r) {
a[pos] = vala; ST[id].chosen[1] = a[pos] % M;
b[pos] = valb; ST[id].chosen[0] = b[pos] % M;
return;
}
int m = (l + r) / 2;
update(id * 2, l, m, pos, vala, valb);
update(id * 2 + 1, m + 1, r, pos, vala, valb);
ST[id] = ST[id * 2] + ST[id * 2 + 1];
}
void Solve() {
//Your Code
cin >> n >> c;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
build(1, 1, n);
cin >> q;
while (q--) {
cin >> pos >> vala >> valb;
update(1, 1, n, pos, vala, valb);
cout << ST[1].chosen[c] << '\n';
}
}
signed main() {
Task();
Solve();
cerr << "\nTime run: " << 1000*clock()/CLOCKS_PER_SEC << "ms";
return 37^37;
}
Compilation message
relativnost.cpp: In function 'void Task()':
relativnost.cpp:47:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | freopen(FNAME".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
relativnost.cpp:48:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | freopen(FNAME".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
25176 KB |
Output is correct |
2 |
Correct |
15 ms |
25176 KB |
Output is correct |
3 |
Correct |
25 ms |
25176 KB |
Output is correct |
4 |
Correct |
310 ms |
26052 KB |
Output is correct |
5 |
Correct |
1041 ms |
26392 KB |
Output is correct |
6 |
Correct |
1587 ms |
26340 KB |
Output is correct |
7 |
Correct |
680 ms |
26156 KB |
Output is correct |
8 |
Correct |
364 ms |
26068 KB |
Output is correct |
9 |
Correct |
650 ms |
26448 KB |
Output is correct |
10 |
Correct |
2498 ms |
26256 KB |
Output is correct |