# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1193503 | InvMOD | Relativnost (COCI15_relativnost) | C++17 | 0 ms | 0 KiB |
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define pi pair<int,int>
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define compact(v) (v).erase(unique(all(v)), (v).end())
template<class T> using upq = priority_queue<T, vector<T>, greater<T>>;
template<class T> int lwrbound(const vector<T>& a, const T& b, const int s = 0){return int(lower_bound(s + all(a), b) - a.begin());}
template<class T> int uprbound(const vector<T>& a, const T& b, const int s = 0){return int(upper_bound(s + all(a), b) - a.begin());}
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define ROF(i, a, b) for(int i = (a); i >= (b); i--)
#define sumof(x) accumulate(all(x), 0ll)
#define dbg(x) "[" << #x " = " << (x) << "]"
#define el "\n"
using ll = long long;
using ld = long double;
template<class T> bool ckmx(T& a, const T b){return (a < b ? a = b, true : false);}
template<class T> bool ckmn(T& a, const T b){return (a > b ? a = b, true : false);}
const int N = 2e5 + 5;
const int MOD = 10007;
const ll INF = numeric_limits<ll>::max() / 8;
void add(int16_t& x, int y){
x += y;
if(x >= MOD) x -= MOD;
}
int mul(int x, int y){
return x * y % MOD;
}
struct SMT{
struct Node{
vector<int16_t> dp;
Node(int c = 0): dp(c + 1, 0) {}
friend Node operator + (const Node& a, const Node& b){
int16_t c = sz(a.dp) - 1;
Node ans(c);
for(int i = 0; i <= c; i++){
for(int j = 0; j <= c; j++){
add(ans.dp[min(i + j, c)], mul(a.dp[i], b.dp[j]));
}
}
return ans;
}
};
vector<Node> st; int trsz;
SMT(int n = 0, int c = 0): trsz(n), st((n << 2 | 1), Node(c)) {}
void update(int id, int l, int r, int x, int a, int b){
if(l == r){
st[id].dp[0] = b % MOD;
st[id].dp[1] = a % MOD;
}
else{
int m = l+r>>1;
if(x <= m)
update(id << 1, l, m, x, a, b);
else update(id << 1|1, m+1, r, x, a, b);
st[id] = st[id << 1] + st[id << 1|1];
}
}
void update(int x, int a, int b){
update(1, 1, trsz, x, a, b);
}
int ans(){
return st[1].dp.back();
}
};
void Main()
{
int n,C; cin >> n >> C;
SMT st(n, C); vi a(n + 1), b(n + 1);
FOR(i, 1, n) cin >> a[i];
FOR(i, 1, n) cin >> b[i];
FOR(i, 1, n){
st.update(i, a[i], b[i]);
}
int q; cin >> q;
while(q--){
int p; cin >> p >> a[p] >> b[p];
st.update(p, a[p], b[p]);
cout << st.ans() << el;
}
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define name "InvMOD"
if(fopen(name".INP", "r")){
freopen(name".INP", "r", stdin);
freopen(name".OUT", "w", stdout);
}
int t = 1; while(t--) Main();
return 0;
}