Submission #541909

# Submission time Handle Problem Language Result Execution time Memory
541909 2022-03-24T19:24:56 Z Olympia Relativnost (COCI15_relativnost) C++17
0 / 140
4000 ms 48028 KB
#include <vector>
#include <algorithm>
#include <iostream>
#include <set>
#include <cmath>
#include <map>
#include <random>
#include <cassert>
#include <ctime>
#include <cstdlib>
#include <limits.h>
#include <queue>

using namespace std;
const int MOD = 10007;
class Node {
public:
    int64_t dp[22]; //how many ways such that exactly C people get a painting
    Node () {
        for (int i = 0; i < 22; i++) {
            dp[i] = 0;
        }
    }
};
Node merge (Node n1, Node n2) {
    Node ans;
    for (int i = 0; i < 22; i++) {
        for (int j = 0; j < 22; j++) {
            ans.dp[min(i + j, 21)] += n1.dp[i] * n2.dp[j];
            ans.dp[min(i + j, 21)] %= MOD;
        }
    }
    return ans;
}
Node get_node (pair<int,int> p) {
    Node ans;
    ans.dp[0] = p.second;
    ans.dp[1] = p.first;
    return ans;
}
template<class T>
class SegmentTree {
public:

    SegmentTree (int N) {
        N = (1 << ((int)floor(log2(N - 1)) + 1));
        this->N = N;
        val.assign(2 * N, ID);
    }

    void update (int x, T y) {
        x += N - 1;
        val[x] = y;
        while (x != 0) {
            x = (x - 1)/2;
            val[x] = merge(val[2 * x + 1], val[2 * x + 2]);
        }
    }

    T query (int ind, const int l, const int r, int tl, int tr) {
        if (tl >= l && tr <= r) {
            return val[ind];
        }
        if (tr < l || tl > r) {
            return ID;
        }
        return merge(query(2 * ind + 1, l, r, tl, (tl + tr)/2), query(2 * ind + 2, l, r, (tl + tr)/2 + 1, tr));
    }

    T query (int l, int r) {
        return query(0, l, r, 0, N - 1);
    }
private:
    vector<T> val;
    T ID;
    int N;
};
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, C;
    cin >> N >> C;
    SegmentTree<Node> st(N);
    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        st.update(i, get_node({x, y}));
    }
    int Q;
    cin >> Q;
    while (Q--) {
        int ind, x, y;
        cin >> ind >> x >> y;
        ind--;
        st.update(ind, get_node({x, y}));
        cout << st.query(0, N - 1).dp[C] << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 696 KB Output isn't correct
2 Incorrect 63 ms 712 KB Output isn't correct
3 Incorrect 58 ms 596 KB Output isn't correct
4 Execution timed out 4070 ms 25268 KB Time limit exceeded
5 Execution timed out 4029 ms 47896 KB Time limit exceeded
6 Execution timed out 4075 ms 48028 KB Time limit exceeded
7 Execution timed out 4050 ms 25232 KB Time limit exceeded
8 Execution timed out 4098 ms 47884 KB Time limit exceeded
9 Execution timed out 4096 ms 47752 KB Time limit exceeded
10 Execution timed out 4024 ms 47804 KB Time limit exceeded