Submission #1032199

# Submission time Handle Problem Language Result Execution time Memory
1032199 2024-07-23T13:06:40 Z giorgitsibadze Relativnost (COCI15_relativnost) C++14
70 / 140
2462 ms 47184 KB
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define pb push_back
#define popb pop_back
#define pii pair<int, int>
#define pll pair<ll, ll>
using namespace std;

const int mod = 1e4 + 7;
const int inf = 1e15;

int n, c;
int a[100001], b[100001];
int t[400001][21];

void merge(int v) {
    for(int i = 0; i <= c; i++) t[v][i] = 0;
    for(int i = 0; i <= c; i++) {
        for(int j = 0; j <= c; j++) {
            (t[v][min(c, i + j)] += t[2 * v][i] * t[2 * v + 1][j]) %= mod;
        }
    }
}

void build(int v, int tl, int tr) {
    if(tl == tr) {
        (t[v][1] = a[tl]) %= mod;
        (t[v][0] = b[tl]) %= mod;
        return;
    }
    int tm = (tl + tr) / 2;
    build(2 * v, tl, tm);
    build(2 * v + 1, tm + 1, tr);
    merge(v);
}

void update(int v, int tl, int tr, int x) {
    if(tl == tr) {
        (t[v][1] = a[x]) %= mod;
        (t[v][0] = b[x]) %= mod;
        return;
    }
    int tm = (tl + tr) / 2;
    if(x <= tm) {
        update(2 * v, tl, tm, x);
    } else update(2 * v + 1, tm + 1, tr, x);
    merge(v);
}

void solve() {
    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 q;
    cin >> q;
    while(q--) {
        int p;
        cin >> p >> a[p] >> b[p];
        update(1, 1, n, p);
        cout << t[1][c] << '\n';
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    
    int t = 1;
    //cin >> t;
    while(t--) {
        solve();
        cout << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4696 KB Output is correct
2 Correct 9 ms 4748 KB Output is correct
3 Correct 18 ms 4700 KB Output is correct
4 Correct 299 ms 24912 KB Output is correct
5 Runtime error 977 ms 47184 KB Memory limit exceeded
6 Runtime error 1508 ms 47184 KB Memory limit exceeded
7 Correct 649 ms 25172 KB Output is correct
8 Runtime error 347 ms 46936 KB Memory limit exceeded
9 Runtime error 609 ms 47108 KB Memory limit exceeded
10 Runtime error 2462 ms 44116 KB Memory limit exceeded