#include <bits/stdc++.h>
using namespace std;
#define FNAME "test"
typedef long long ll;
const ll M = 10007;
const int N = 1e5 + 5;
const int C = 21;
int n, c, q;
ll a[N], b[N];
struct Node {
ll chosen[C];
Node() {
memset(chosen, 0, sizeof(chosen));
}
Node(ll a, ll b) {
memset(chosen, 0, sizeof(chosen));
chosen[0] = b;
chosen[1] = a;
}
Node operator + (const Node& oth) {
Node nNode;
for (int i = 0; i <= c; i++) {
for (int j = 0; j <= c; j++) {
nNode.chosen[min(c, i + j)] = (nNode.chosen[min(c, i + j)] + chosen[i] * oth.chosen[j]) % M;
}
}
return nNode;
}
} ST[2 * N];
void Task() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(9);
if (fopen(FNAME".inp","r")) {
freopen(FNAME".inp","r",stdin);
freopen(FNAME".out","w",stdout);
}
}
void update(int pos, const Node& value) {
for (ST[pos += n] = value; pos >>= 1;) ST[pos] = ST[pos << 1] + ST[pos << 1 | 1];
}
ll query(int l, int r) {
Node res = ST[l + n];
for (int i = l + 1; i <= r; i++) res = res + ST[i + n];
return res.chosen[c];
}
void Solve() {
//Your Code
cin >> n >> c;
for (int i = 0; i < n; i++) cin >> a[i] >> b[i], update(i, Node(a[i], b[i]));
cin >> q;
while (q--) {
int pos;
ll vala, valb;
cin >> pos >> vala >> valb;
pos--;
a[pos] = vala, b[pos] = valb;
update(pos, Node(vala, valb));
cout << query(0, n - 1) << '\n';
}
}
int main() {
Task();
Solve();
cerr << "\nTime run: " << 1000*clock()/CLOCKS_PER_SEC << "ms";
return 37^37;
}
Compilation message
relativnost.cpp: In function 'void Task()':
relativnost.cpp:45:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | freopen(FNAME".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
relativnost.cpp:46:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
46 | freopen(FNAME".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
409 ms |
33368 KB |
Memory limit exceeded |
2 |
Runtime error |
648 ms |
33616 KB |
Memory limit exceeded |
3 |
Runtime error |
1193 ms |
33496 KB |
Memory limit exceeded |
4 |
Execution timed out |
4032 ms |
34640 KB |
Time limit exceeded |
5 |
Execution timed out |
4042 ms |
35684 KB |
Time limit exceeded |
6 |
Execution timed out |
4009 ms |
35828 KB |
Time limit exceeded |
7 |
Execution timed out |
4014 ms |
35092 KB |
Time limit exceeded |
8 |
Execution timed out |
4038 ms |
35856 KB |
Time limit exceeded |
9 |
Execution timed out |
4014 ms |
35152 KB |
Time limit exceeded |
10 |
Execution timed out |
4010 ms |
35508 KB |
Time limit exceeded |