#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<ll, ll> pii;
typedef pair<ld, ld> pld;
ll n, c, q, mod = 10007;
ll a[100009];
ll b[100009];
ll seg[400009][25];
void merge(ll cur, ll l, ll r){
for(ll i = 0; i < c; ++i){
seg[cur][i] = 0;
for(ll j = 0; j <= i; ++j){
seg[cur][i] += seg[l][j]*seg[r][i-j]%mod;
seg[cur][i] %= mod;
}
}
seg[cur][c] = 0;
for(ll i = 0; i <= c; ++i)
for(ll j = c-i; j <= c; ++j){
seg[cur][c] += seg[l][i]*seg[r][j]%mod;
seg[cur][c] %= mod;
}
}
void upd(ll v, ll tl, ll tr, ll idx){
if(idx < tl || idx > tr)
return;
if(idx == tl && idx == tr){
seg[v][0] = b[tl];
seg[v][1] = a[tl];
}
else{
ll tm = (tl+tr)/2;
upd(2*v, tl, tm, idx);
upd(2*v+1, tm+1, tr, idx);
merge(v, 2*v, 2*v+1);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
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)
upd(1, 0, n-1, i);
cin >> q;
while(q--){
int t1, t2, t3;
cin >> t1 >> t2 >> t3;
--t1;
a[t1] = t2;
b[t1] = t3;
upd(1, 0, n-1, t1);
cout << seg[1][c] << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
760 KB |
Output is correct |
2 |
Correct |
89 ms |
748 KB |
Output is correct |
3 |
Correct |
200 ms |
940 KB |
Output is correct |
4 |
Correct |
3435 ms |
27656 KB |
Output is correct |
5 |
Execution timed out |
4040 ms |
31408 KB |
Time limit exceeded |
6 |
Execution timed out |
4013 ms |
17052 KB |
Time limit exceeded |
7 |
Execution timed out |
4035 ms |
24796 KB |
Time limit exceeded |
8 |
Execution timed out |
4048 ms |
53740 KB |
Time limit exceeded |
9 |
Execution timed out |
4029 ms |
53404 KB |
Time limit exceeded |
10 |
Execution timed out |
4054 ms |
15696 KB |
Time limit exceeded |