# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
644975 | BackNoob | Relativnost (COCI15_relativnost) | C++14 | 3036 ms | 23124 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 ll long long
#define fi first
#define se second
#define endl '\n'
#define MASK(i) (1LL << (i))
#define ull unsigned long long
#define ld long double
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define BIT(x , i) ((x >> (i)) & 1)
#define TASK "task"
#define sz(s) (int) (s).size()
using namespace std;
const int mxN = 1e5 + 227;
const int inf = 1e9 + 277;
const int mod = 10007;
const ll infll = 1e18 + 7;
const int base = 307;
const int LOG = 20;
template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
if (a < b) {a = b; return true;} return false;
}
int n;
int k;
int q;
pair<int, int> a[mxN];
void add(int &a, int b)
{
a += b;
if(a >= mod)
a -= mod;
}
struct IT{
struct Node{
int f[21];
Node() {
for(int i = 0; i < 21; i++) f[i] = 0;
}
};
int n;
vector<Node> t;
IT(){}
IT(int _n) {
n = _n;
int offset;
for(offset = 1; offset < n; offset *= 2);
t.resize(offset * 2);
}
Node BASE;
void merge_node(Node &res, Node &a, Node &b)
{
for(int i = 0; i <= k; i++) res.f[i] = 0;
for(int i = 0; i <= k; i++) {
for(int j = 0; j <= k; j++) {
add(res.f[min(k, i + j)], 1LL * a.f[i] * b.f[j] % mod);
}
}
}
void build(int v, int tl, int tr)
{
if(tl == tr) {
t[v].f[1] = a[tl].fi;
t[v].f[0] = a[tl].se;
}
else {
int tm = (tl + tr) / 2;
build(v * 2, tl, tm);
build(v * 2 + 1, tm + 1, tr);
merge_node(t[v], t[v * 2], t[v * 2 + 1]);
}
}
void update(int v, int tl, int tr, int pos, pair<int, int> val)
{
if(tl == tr) {
t[v].f[1] = val.fi;
t[v].f[0] = val.se;
}
else {
int tm = (tl + tr) / 2;
if(pos <= tm) update(v * 2, tl, tm, pos, val);
else update(v * 2 + 1, tm + 1, tr, pos, val);
merge_node(t[v], t[v * 2], t[v * 2 + 1]);
}
}
void update(int pos, pair<int, int> val)
{
update(1, 1, n, pos, val);
}
} seg;
void solve()
{
cin >> n >> k;
for(int i = 1; i <= n; i++) cin >> a[i].fi;
for(int i = 1; i <= n; i++) cin >> a[i].se;
seg = IT(n);
seg.build(1, 1, n);
cin >> q;
while(q--) {
int idx, x, y;
cin >> idx >> x >> y;
a[idx] = {x, y};
seg.update(idx, a[idx]);
cout << seg.t[1].f[k] << endl;
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int tc = 1;
//cin >> tc;
while(tc--) {
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |