# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
251678 | VEGAnn | Relativnost (COCI15_relativnost) | C++14 | 2865 ms | 12920 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;
typedef long long ll;
const int N = 100100;
const int C = 22;
const int md = 10007;
int n, c, a[N], b[N];
short st[4 * N][C];
int mult(int x, int y) { return (x * y) % md; }
void SUM(short &x, short y){
x += y;
if (x >= md)
x -= md;
}
void clear(int v){
for (int i = 0; i <= c; i++)
st[v][i] = 0;
}
void combine(int v, int l, int r){
clear(v);
for (int i = 0; i <= c; i++)
for (int j = 0; j <= c; j++)
SUM(st[v][min(i + j, c)], mult(st[l][i], st[r][j]));
}
void build(int v, int l, int r){
if (l == r){
clear(v);
st[v][0] = b[l] % md;
st[v][1] = a[l] % md;
return;
}
int md = (l + r) >> 1;
build(v + v, l, md);
build(v + v + 1, md + 1, r);
combine(v, v + v, v + v + 1);
}
void update(int v, int l, int r, int ps){
if (l == r){
clear(v);
st[v][0] = b[l] % md;
st[v][1] = a[l] % md;
return;
}
int md = (l + r) >> 1;
if (ps <= md)
update(v + v, l, md, ps);
else update(v + v + 1, md + 1, r, ps);
combine(v, v + v, v + v + 1);
}
int main() {
#ifdef _LOCAL
freopen("in.txt","r",stdin); // freopen("output.txt","w",stdout);
#else
// freopen("mining.in","r",stdin); freopen("mining.out","w",stdout);
ios_base::sync_with_stdio(0); cin.tie(0);
#endif
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);
int qq; cin >> qq;
for (; qq; qq--){
int ps, an, bn; cin >> ps >> an >> bn;
a[ps] = an;
b[ps] = bn;
update(1, 1, n, ps);
cout << st[1][c] << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |