# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
98745 | HellAngel | Relativnost (COCI15_relativnost) | C++14 | 2618 ms | 18172 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;
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";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |