Submission #251695

# Submission time Handle Problem Language Result Execution time Memory
251695 2020-07-22T07:39:01 Z Vimmer Relativnost (COCI15_relativnost) C++14
140 / 140
3864 ms 12504 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")

#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define pf push_front
#define N 100010
#define M ll(10007)
#define inf 1e9 + 1e9

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef short int si;
typedef array <int, 3> a3;
typedef array <int, 4> a4;
typedef pair <int, int> pt;
//typedef tree <int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int sm(int x, int y) {return (x + y) % M;}

int mlt(int x, int y) {return (x * y) % M;}

int n, c, a[N], b[N];

si t[N * 4][21];
void make(int v, int vl, int vr)
{
    memset(t[v], 0, sizeof(t[v]));

    for (int i = 0; i <= c; i++)
        for (int j = 0; j <= c; j++)
        {
            int nw = min(int(c), i + j);

            t[v][nw] = sm(t[v][nw], mlt(t[vl][i], t[vr][j]));
        }
}

void bld(int v, int tl, int tr)
{
    if (tl == tr)
    {
        t[v][0] = b[tl];

        t[v][1] = a[tl];

        return;
    }

    int md = (tl + tr) >> 1;

    bld(v + v, tl, md);

    bld(v + v + 1, md + 1, tr);

    make(v, v + v, v + v + 1);
}

void upd(int v, int tl, int tr, int pos)
{
    if (tl == tr)
    {
        t[v][0] = b[tl];

        t[v][1] = a[tl];

        return;
    }

    int md = (tl + tr) >> 1;

    if (pos <= md) upd(v + v, tl, md, pos); else upd(v + v + 1, md + 1, tr, pos);

    make(v, v + v, v + v + 1);
}
int main()
{
    //freopen("mining.in", "r", stdin); freopen("mining.out", "w", stdout);

    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> c;

    for (int i = 0; i < n; i++) {cin >> a[i]; a[i] %= M;}

    for (int i = 0; i < n; i++) {cin >> b[i]; b[i] %= M;}

    bld(1, 0, n - 1);

    int q;

    cin >> q;

    for (; q > 0; q--)
    {
        int x, l, r;

        cin >> x >> l >> r;

        l %= M; r %= M;

        x--;

        b[x] = r; a[x] = l;

        upd(1, 0, n - 1, x);

        cout << t[1][c] << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 384 KB Output is correct
2 Correct 14 ms 512 KB Output is correct
3 Correct 30 ms 512 KB Output is correct
4 Correct 455 ms 6452 KB Output is correct
5 Correct 1579 ms 12504 KB Output is correct
6 Correct 2474 ms 12352 KB Output is correct
7 Correct 1076 ms 6564 KB Output is correct
8 Correct 513 ms 11896 KB Output is correct
9 Correct 990 ms 12288 KB Output is correct
10 Correct 3864 ms 12408 KB Output is correct