# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
100762 | dalgerok | Relativnost (COCI15_relativnost) | C++17 | 42 ms | 33792 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;
const int N = 1e5 + 5, M = 25, MOD = 1e4 + 7;
int n, m, q, a[N], b[N];
struct item{
int dp[M];
item(){
memset(dp, 0, sizeof(dp));
}
};
item t[4 * N];
inline item mrg(item a, item b){
item c;
for(int i = 0; i <= m; i++){
for(int j = 0; j <= m; j++){
c.dp[min(m, i + j)] += 1LL * a.dp[i] * b.dp[j] % MOD;
}
}
for(int i = 0; i <= m; i++){
c.dp[i] %= MOD;
}
return c;
}
void build(int v, int l, int r){
if(l == r){
t[v].dp[0] = a[l];
t[v].dp[1] = b[l];
return;
}
int mid = (r + l) >> 1;
build(v + v, l, mid);
build(v + v + 1, mid + 1, r);
t[v] = mrg(t[v + v], t[v + v + 1]);
}
void update(int v, int l, int r, int pos){
if(l == r){
t[v].dp[0] = a[l];
t[v].dp[1] = b[l];
return;
}
int mid = (r + l) >> 1;
if(pos <= mid){
update(v + v, l, mid, pos);
}
else{
update(v + v + 1, mid + 1, r, pos);
}
t[v] = mrg(t[v + v], t[v + v + 1]);
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++){
cin >> a[i];
a[i] %= MOD;
}
for(int i = 1; i <= n; i++){
cin >> b[i];
b[i] %= MOD;
}
build(1, 1, n);
cin >> q;
while(q--){
int pos, x, y;
cin >> pos >> x >> y;
a[pos] = x;
b[pos] = y;
a[pos] %= MOD;
b[pos] %= MOD;
update(1, 1, n, pos);
cout << t[1].dp[m] << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |