#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[21]; //how many ways such that exactly C people get a painting
Node () {
for (int i = 0; i < 21; i++) {
dp[i] = 0;
}
}
};
Node merge (Node n1, Node n2) {
Node ans;
for (int i = 0; i < 21; i++) {
for (int j = 0; j < 21; j++) {
ans.dp[min(i + j, 20)] += n1.dp[i] * n2.dp[j];
ans.dp[min(i + j, 20)] %= MOD;
//cout << ans.dp[min(i + j)]
}
}
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, Node());
}
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]);
}
}
vector<T> val;
private:
int N;
};
int main() {
//freopen("balancing.in", "r", stdin);
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}));
int64_t ans = 0;
for (int i = C; i <= 20; i++) {
ans += st.val[0].dp[i];
}
cout << ans % MOD << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
37 ms |
596 KB |
Output isn't correct |
2 |
Incorrect |
42 ms |
596 KB |
Output isn't correct |
3 |
Incorrect |
35 ms |
596 KB |
Output isn't correct |
4 |
Incorrect |
3324 ms |
22420 KB |
Output isn't correct |
5 |
Execution timed out |
4054 ms |
44396 KB |
Time limit exceeded |
6 |
Execution timed out |
4030 ms |
44200 KB |
Time limit exceeded |
7 |
Incorrect |
3525 ms |
22788 KB |
Output isn't correct |
8 |
Execution timed out |
4035 ms |
44340 KB |
Time limit exceeded |
9 |
Execution timed out |
4056 ms |
44576 KB |
Time limit exceeded |
10 |
Execution timed out |
4046 ms |
44696 KB |
Time limit exceeded |