#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cstring>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template<typename T, typename V>
void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template<typename T>
void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto &i: x) cerr << (f++ ? "," : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template<typename T, typename... V>
void _print(T t, V... v) {
__print(t);
if (sizeof...(v)) cerr << ", ";
_print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair <int, int>
#define ull unsigned long long
#define int long long
// #define int unsigned long long
const ll mod = 10007;
const ll weirdMod = 998244353;
const int maxN = 1e5 + 25;
int n, c, q, a[maxN], b[maxN], t[4 * maxN][21];
void build(int v, int tl, int tr) {
if (tl == tr) {
t[v][0] = b[tl] % mod;
t[v][1] = a[tl] % mod;
return;
} int tm = (tl + tr) / 2;
build(2 * v, tl, tm);
build(2 * v + 1, tm + 1, tr);
for (int i = 0; i <= c; i++)
for (int j = 0; j <= c; j++)
(t[v][min(c, i + j)] += t[2 * v][i] * t[2 * v + 1][j] % mod) %= mod;
}
void update(int v, int tl, int tr, int pos) {
if (tl == tr) {
t[v][0] = b[tl] % mod;
t[v][1] = a[tl] % mod;
return;
} int tm = (tl + tr) / 2;
if (pos <= tm) update(2 * v, tl, tm, pos);
else update(2 * v + 1, tm + 1, tr, pos);
for (int i = 0; i <= c; i++)
t[v][i] = 0;
for (int i = 0; i <= c; i++)
for (int j = 0; j <= c; j++)
(t[v][min(c, i + j)] += t[2 * v][i] * t[2 * v + 1][j] % mod) %= mod;
}
void solve() {
cin >> n >> c;
int cnt = 0;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
cin >> b[i];
build(1, 1, n);
cin >> q;
while (q--) {
int x;
cin >> x;
cin >> a[x] >> b[x];
update(1, 1, n, x);
cout << t[1][c] << '\n';
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
cout << '\n';
}
return 0;
}
Compilation message
relativnost.cpp: In function 'void solve()':
relativnost.cpp:114:9: warning: unused variable 'cnt' [-Wunused-variable]
114 | int cnt = 0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4700 KB |
Output is correct |
2 |
Correct |
10 ms |
4748 KB |
Output is correct |
3 |
Correct |
20 ms |
4700 KB |
Output is correct |
4 |
Correct |
320 ms |
26048 KB |
Output is correct |
5 |
Runtime error |
1163 ms |
47188 KB |
Memory limit exceeded |
6 |
Runtime error |
1810 ms |
47444 KB |
Memory limit exceeded |
7 |
Correct |
752 ms |
26424 KB |
Output is correct |
8 |
Runtime error |
374 ms |
47200 KB |
Memory limit exceeded |
9 |
Runtime error |
716 ms |
47184 KB |
Memory limit exceeded |
10 |
Runtime error |
2873 ms |
46788 KB |
Memory limit exceeded |