#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 10;
const int mod = 10007;
int n, c, q, a[maxN], b[maxN], f[maxN * 2][22];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> c;
for (int i=0; i<n; ++i)
cin >> a[i];
for (int i=0; i<n; ++i)
cin >> b[i];
for (int i = 0; i < n; ++i)
{
f[i + n][1] = a[i] % mod;
f[i + n][0] = b[i] % mod;
}
for (int x=n-1; x>=1; --x)
{
for (int i = 0; i <= c; ++i)
f[x][i] = 0;
for (int i=0; i<=c; ++i)
for (int j=0; j<=c; ++j)
f[x][min(i + j, c)] += (f[x * 2][i] * f[x * 2 + 1][j]) % mod;
for (int i = 0; i <= c; ++i)
f[x][i] %= mod;
}
cin >> q;
while (q--)
{
int x;
cin >> x;
--x;
cin >> a[x] >> b[x];
x += n;
for (int i=0; i<c; ++i)
f[x][i] = 0;
f[x][1] = a[x - n] % mod;
f[x][0] = b[x - n] % mod;
for (x /= 2; x > 0; x /= 2)
{
for (int i = 0; i <= c; ++i)
f[x][i] = 0;
for (int i=0; i<=c; ++i)
for (int j=0; j<=c; ++j)
f[x][min(i + j, c)] += (f[x * 2][i] * f[x * 2 + 1][j]) % mod;
for (int i = 0; i <= c; ++i)
f[x][i] %= mod;
}
cout << f[1][c] << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
512 KB |
Output is correct |
2 |
Correct |
11 ms |
512 KB |
Output is correct |
3 |
Correct |
16 ms |
512 KB |
Output is correct |
4 |
Correct |
356 ms |
10100 KB |
Output is correct |
5 |
Correct |
1275 ms |
17016 KB |
Output is correct |
6 |
Correct |
1704 ms |
18172 KB |
Output is correct |
7 |
Correct |
715 ms |
12152 KB |
Output is correct |
8 |
Correct |
479 ms |
17892 KB |
Output is correct |
9 |
Correct |
797 ms |
15352 KB |
Output is correct |
10 |
Correct |
2618 ms |
14644 KB |
Output is correct |