Submission #251688

# Submission time Handle Problem Language Result Execution time Memory
251688 2020-07-22T07:35:01 Z Vimmer Relativnost (COCI15_relativnost) C++14
0 / 140
46 ms 65540 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;

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

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

ll binpow(ll a, ll b)
{
    if (b == 0) return 1ll;

    ll s = binpow(a, b / 2);

    s = mlt(s, s);

    if (b % 2) s = mlt(s, a);

    return s;
}

ll fact[N], t[N * 4][21], n, c, a[N], b[N];

ll kol(ll k, ll n) {if (k > n) return 0; return mlt(fact[n], binpow(fact[k] * fact[n - k], M - 2));}

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);

    fact[0] = 1;

    for (int i = 1; i < N; i++) fact[i] = mlt(fact[i - 1], i);

    cin >> n >> c;

    for (int i = 0; i < N * 4; i++) t[i][0] = 1;

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

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

    bld(1, 0, n - 1);

    int q;

    cin >> q;

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

        cin >> x >> l >> r;

        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 Runtime error 33 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 29 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Runtime error 34 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 33 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 33 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 32 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 46 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 34 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 34 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 33 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)