#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int N = 1e5 + 7, mod = 10007;
struct node{
int ret[21];
} it[4 * N];
int n, c, q, a, b, x;
int pa[N], pb[N];
int read(){
char p;
while((p = getchar())){
if(p < '0' || p > '9') continue;
break;
}
int ret = p - '0';
while((p = getchar())){
if(p >= '0' && p <= '9'){
ret *= 10;
ret += p - '0';
}
else break;
}
return ret;
}
int dg[10];
void print(int x){
int cur = 0;
if(x == 0) putchar('0');
while(x > 0){
cur++;
dg[cur] = x % 10;
x /= 10;
}
for(int i = cur; i >= 1; i--){
char p = '0' + dg[i];
putchar(p);
}
putchar('\n');
}
void add(int &a, int b){
a += b;
a %= mod;
}
node merge(node a, node b){
node res;
for(int i = 0; i <= c; i++) res.ret[i] = 0;
for(int i = 0; i <= c; i++){
for(int j = 0; j <= c; j++){
add(res.ret[min(c, i + j)], a.ret[i] * b.ret[j]);
}
}
return res;
}
void init(int k, int l, int r){
if(l == r){
it[k].ret[0] = pb[l];
it[k].ret[1] = pa[l];
return;
}
int mid = (l + r) >> 1;
init(k << 1, l, mid);
init(k << 1 | 1, mid + 1, r);
it[k] = merge(it[k << 1], it[k << 1 | 1]);
}
void update(int k, int l, int r, int pos, int a, int b){
if(l > pos || r < pos) return;
if(l == r){
it[k].ret[0] = b;
it[k].ret[1] = a;
return;
}
int mid = (l + r) >> 1;
update(k << 1, l, mid, pos, a, b);
update(k << 1 | 1, mid + 1, r, pos, a, b);
it[k] = merge(it[k << 1], it[k << 1 | 1]);
}
int main(){
n = read(), c = read();
for(int i = 1; i <= n; i++) pa[i] = read(), pa[i] %= mod;
for(int i = 1; i <= n; i++) pb[i] = read(), pb[i] %= mod;
init(1, 1, n);
q = read();
while(q --){
x = read(), a = read(), b = read();
a %= mod, b %= mod;
update(1, 1, n, x, a, b);
print(it[1].ret[c]);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
512 KB |
Output is correct |
2 |
Correct |
14 ms |
632 KB |
Output is correct |
3 |
Correct |
24 ms |
512 KB |
Output is correct |
4 |
Correct |
438 ms |
11984 KB |
Output is correct |
5 |
Correct |
1464 ms |
23036 KB |
Output is correct |
6 |
Correct |
2267 ms |
23136 KB |
Output is correct |
7 |
Correct |
943 ms |
12128 KB |
Output is correct |
8 |
Correct |
498 ms |
22776 KB |
Output is correct |
9 |
Correct |
935 ms |
23096 KB |
Output is correct |
10 |
Correct |
3236 ms |
23164 KB |
Output is correct |