#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';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
512 KB |
Output is correct |
2 |
Correct |
13 ms |
512 KB |
Output is correct |
3 |
Correct |
28 ms |
512 KB |
Output is correct |
4 |
Correct |
444 ms |
12024 KB |
Output is correct |
5 |
Correct |
1518 ms |
23320 KB |
Output is correct |
6 |
Correct |
2293 ms |
23092 KB |
Output is correct |
7 |
Correct |
1000 ms |
12024 KB |
Output is correct |
8 |
Correct |
515 ms |
22776 KB |
Output is correct |
9 |
Correct |
951 ms |
22908 KB |
Output is correct |
10 |
Correct |
3652 ms |
23032 KB |
Output is correct |