Submission #230579

# Submission time Handle Problem Language Result Execution time Memory
230579 2020-05-10T13:16:23 Z ParsaAlizadeh Relativnost (COCI15_relativnost) C++17
140 / 140
3781 ms 24252 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long int   ll;
typedef pair<ll, ll>    pll;
typedef pair<int, int>  pii;

#define all(x)          x.begin(), x.end()
#define kill(x)         return cout << x << endl, 0
#define X               first
#define Y               second
#define sep             ' '
#define endl            '\n'

template<class T = ll>
T nxt() {T x; cin >> x; return x;}

ll pw(ll a, ll b, ll mod) {
    if (!b)    return 1;
    if (b & 1) return a * pw(a * a % mod, b / 2, mod) % mod;
    return pw(a * a % mod, b / 2, mod) % mod;
}

const int N    = 1e5 + 10;
const int K    = 22;
const int MOD  = 10007;

int n, q, A[N], B[N], k, seg[N << 2][K];

void Merge(int id) {
    for (int i = 0; i <= k; i++) {
        seg[id][i] = 0;
    }
    for (int i = 0; i <= k; i++) {
        for (int j = 0; j <= k; j++) {
            seg[id][min(k, i + j)] += seg[2 * id][i] * seg[2 * id + 1][j] % MOD;
            seg[id][min(k, i + j)] %= MOD;
        }
    }
}

void Build(int id, int l, int r) {
    if (r - l == 1) {
        seg[id][0] = B[l];
        seg[id][1] = A[l];
        return;
    }
    int mid = (l + r) >> 1;
    Build(2 * id, l, mid);
    Build(2 * id + 1, mid, r);
    Merge(id);
}

void Update(int id, int l, int r, int ind) {
    if (ind < l || r <= ind)
        return;
    if (r - l == 1) {
        seg[id][0] = B[l];
        seg[id][1] = A[l];
        return;
    }
    int mid = (l + r) >> 1;
    if (ind < mid)
        Update(2 * id, l, mid, ind);
    else
        Update(2 * id + 1, mid, r, ind);
    Merge(id);
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> A[i]; A[i] %= MOD;
    }
    for (int i = 0; i < n; i++) {
        cin >> B[i]; B[i] %= MOD;
    }
    Build(1, 0, n);
    cin >> q;
    while (q--) {
        int ind, a, b;
        cin >> ind >> a >> b; ind--;
        A[ind] = a % MOD;
        B[ind] = b % MOD;
        Update(1, 0, n, ind);
        cout << seg[1][k] << endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 512 KB Output is correct
2 Correct 17 ms 512 KB Output is correct
3 Correct 32 ms 512 KB Output is correct
4 Correct 471 ms 12432 KB Output is correct
5 Correct 1552 ms 24056 KB Output is correct
6 Correct 2392 ms 24252 KB Output is correct
7 Correct 1004 ms 12664 KB Output is correct
8 Correct 554 ms 23736 KB Output is correct
9 Correct 961 ms 24056 KB Output is correct
10 Correct 3781 ms 24204 KB Output is correct