답안 #251678

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
251678 2020-07-22T07:13:51 Z VEGAnn Relativnost (COCI15_relativnost) C++14
140 / 140
2865 ms 12920 KB
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 512 KB Output is correct
2 Correct 10 ms 384 KB Output is correct
3 Correct 31 ms 384 KB Output is correct
4 Correct 385 ms 6776 KB Output is correct
5 Correct 1222 ms 12792 KB Output is correct
6 Correct 1831 ms 12920 KB Output is correct
7 Correct 795 ms 6904 KB Output is correct
8 Correct 422 ms 12664 KB Output is correct
9 Correct 778 ms 12664 KB Output is correct
10 Correct 2865 ms 12864 KB Output is correct