# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
919733 | TIN | Relativnost (COCI15_relativnost) | C++17 | 4042 ms | 35856 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |