# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
165281 | egekabas | Relativnost (COCI15_relativnost) | C++14 | 4086 ms | 53456 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>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<ll, ll> pii;
typedef pair<ld, ld> pld;
ll n, c, q, mod = 10007;
ll a[100009];
ll b[100009];
ll seg[400009][25];
void merge(ll cur, ll l, ll r){
for(ll i = 0; i < c; ++i){
seg[cur][i] = 0;
for(ll j = 0; j <= i; ++j){
seg[cur][i] += seg[l][j]*seg[r][i-j]%mod;
seg[cur][i] %= mod;
}
}
seg[cur][c] = 0;
for(ll i = 0; i <= c; ++i)
for(ll j = c-i; j <= c; ++j){
seg[cur][c] += seg[l][i]*seg[r][j]%mod;
seg[cur][c] %= mod;
}
}
void upd(ll v, ll tl, ll tr, ll idx){
if(idx < tl || idx > tr)
return;
if(idx == tl && idx == tr){
seg[v][0] = b[tl];
seg[v][1] = a[tl];
}
else{
ll tm = (tl+tr)/2;
upd(2*v, tl, tm, idx);
upd(2*v+1, tm+1, tr, idx);
merge(v, 2*v, 2*v+1);
}
}
void build(ll v, ll tl, ll tr){
if(tl > tr)
return;
if(tl == tr){
seg[v][0] = b[tl];
seg[v][1] = a[tl];
}
else{
ll tm = (tl+tr)/2;
build(2*v, tl, tm);
build(2*v+1, tm+1, tr);
merge(v, 2*v, 2*v+1);
}
}
int main() {
// freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
cin >> n >> c;
for(ll i = 0; i < n; ++i)
scanf("%lld", &a[i]);
for(ll i = 0; i < n; ++i)
scanf("%lld", &b[i]);
build(1, 0, n-1);
cin >> q;
while(q--){
ll t1, t2, t3;
scanf("%lld %lld %lld", &t1, &t2, &t3);
--t1;
a[t1] = t2;
b[t1] = t3;
upd(1, 0, n-1, t1);
printf("%lld\n", seg[1][c]);
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |