Submission #644974

# Submission time Handle Problem Language Result Execution time Memory
644974 2022-09-25T17:16:21 Z BackNoob Relativnost (COCI15_relativnost) C++14
98 / 140
3129 ms 34712 KB
#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;
        t.resize(n * 4 + 7);
    }

    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
1 Correct 9 ms 596 KB Output is correct
2 Correct 12 ms 596 KB Output is correct
3 Correct 24 ms 468 KB Output is correct
4 Correct 393 ms 21004 KB Output is correct
5 Runtime error 1343 ms 33292 KB Memory limit exceeded
6 Runtime error 1990 ms 34712 KB Memory limit exceeded
7 Correct 867 ms 24648 KB Output is correct
8 Runtime error 462 ms 34024 KB Memory limit exceeded
9 Correct 820 ms 29624 KB Output is correct
10 Correct 3129 ms 28100 KB Output is correct