Submission #251689

#TimeUsernameProblemLanguageResultExecution timeMemory
251689VimmerRelativnost (COCI15_relativnost)C++14
140 / 140
3652 ms23320 KiB
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> // //#pragma GCC optimize("unroll-loops") //#pragma GCC optimize("-O3") //#pragma GCC optimize("Ofast") //#pragma GCC optimize("fast-math") //#pragma GCC optimize("no-stack-protector") #define F first #define S second #define sz(x) int(x.size()) #define pb push_back #define pf push_front #define N 100010 #define M ll(10007) #define inf 1e9 + 1e9 using namespace std; //using namespace __gnu_pbds; typedef long double ld; typedef long long ll; typedef unsigned long long ull; typedef short int si; typedef array <int, 3> a3; typedef array <int, 4> a4; typedef pair <int, int> pt; //typedef tree <int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; int sm(int x, int y) {return (x + y) % M;} int mlt(int x, int y) {return (x * y) % M;} int t[N * 4][21], n, c, a[N], b[N]; void make(int v, int vl, int vr) { memset(t[v], 0, sizeof(t[v])); for (int i = 0; i <= c; i++) for (int j = 0; j <= c; j++) { int nw = min(int(c), i + j); t[v][nw] = sm(t[v][nw], mlt(t[vl][i], t[vr][j])); } } void bld(int v, int tl, int tr) { if (tl == tr) { t[v][0] = b[tl]; t[v][1] = a[tl]; return; } int md = (tl + tr) >> 1; bld(v + v, tl, md); bld(v + v + 1, md + 1, tr); make(v, v + v, v + v + 1); } void upd(int v, int tl, int tr, int pos) { if (tl == tr) { t[v][0] = b[tl]; t[v][1] = a[tl]; return; } int md = (tl + tr) >> 1; if (pos <= md) upd(v + v, tl, md, pos); else upd(v + v + 1, md + 1, tr, pos); make(v, v + v, v + v + 1); } int main() { //freopen("mining.in", "r", stdin); freopen("mining.out", "w", stdout); ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> c; for (int i = 0; i < n; i++) {cin >> a[i]; a[i] %= M;} for (int i = 0; i < n; i++) {cin >> b[i]; b[i] %= M;} bld(1, 0, n - 1); int q; cin >> q; for (; q > 0; q--) { int x, l, r; cin >> x >> l >> r; l %= M; r %= M; x--; b[x] = r; a[x] = l; upd(1, 0, n - 1, x); cout << t[1][c] << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...