#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 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;
update(1, 1, n, i, pa[i], pb[i]);
}
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]);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
512 KB |
Output is correct |
2 |
Correct |
18 ms |
512 KB |
Output is correct |
3 |
Correct |
34 ms |
636 KB |
Output is correct |
4 |
Correct |
763 ms |
11896 KB |
Output is correct |
5 |
Correct |
2658 ms |
23288 KB |
Output is correct |
6 |
Execution timed out |
4050 ms |
23076 KB |
Time limit exceeded |
7 |
Correct |
1597 ms |
12028 KB |
Output is correct |
8 |
Correct |
1099 ms |
22916 KB |
Output is correct |
9 |
Correct |
1474 ms |
23148 KB |
Output is correct |
10 |
Execution timed out |
4075 ms |
22928 KB |
Time limit exceeded |