# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
93613 | BartolM | Relativnost (COCI15_relativnost) | C++17 | 3402 ms | 13152 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 <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
const int INF=0x3f3f3f3f;
const int N=1e5+5;
const int K=25;
const int MOD=10007;
int n, k, off=1, q;
int tour[K][3*N], A[N], B[N];
int add(int x, int y) {
return (x+y)%MOD;
}
int mul(int x, int y) {
return (x*y)%MOD;
}
void mrg(int l, int r, int pos) {
for (int i=0; i<k; ++i) {
tour[i][pos]=0;
for (int j=0; j<=i; ++j) {
tour[i][pos]=add(mul(tour[j][l], tour[i-j][r]), tour[i][pos]);
}
}
tour[k][pos]=0;
for (int i=0; i<=k; ++i) {
for (int j=k-i; j<=k; ++j) {
tour[k][pos]=add(tour[k][pos], mul(tour[i][l], tour[j][r]));
}
}
}
void update(int pos, int a, int b) {
pos+=off;
tour[0][pos]=b;
tour[1][pos]=a;
while (1) {
pos/=2;
if (!pos) break;
mrg(pos*2, pos*2+1, pos);
}
}
void load() {
scanf("%d %d", &n, &k);
while (off<n) off*=2;
for (int i=0; i<n; ++i) {
scanf("%d", A+i);
A[i]%=MOD;
tour[1][i+off]=A[i];
}
for (int i=0; i<n; ++i) {
scanf("%d", B+i);
B[i]%=MOD;
tour[0][i+off]=B[i];
}
for(int i=n; i<off; ++i) tour[0][i+off] = 1;
scanf("%d", &q);
}
void solve() {
for (int i=off-1; i>0; --i) mrg(i*2, i*2+1, i);
//printf("%d\n", tour[k][1]);
for (int i=0; i<q; ++i) {
int p, a, b;
scanf("%d %d %d", &p, &a, &b); --p;
update(p, a%MOD, b%MOD);
printf("%d\n", tour[k][1]);
}
}
int main() {
load();
solve();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |