Submission #1020054

# Submission time Handle Problem Language Result Execution time Memory
1020054 2024-07-11T13:19:44 Z vako_p Relativnost (COCI15_relativnost) C++14
140 / 140
1217 ms 27728 KB
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define pb push_back

const int mxN = 4e5 + 5;
ll n,C,a[mxN],b[mxN],q,mod = 10007,ans,sz,v[mxN][20],v1[mxN],i,a1,b1;

struct segtree{	
	void init(){	
		sz = 1;
		while(sz < n) sz *= 2;
		for(int i = 0; i < 2 * sz; i++) v[i][0] = v1[i] = 1;
	}
	
	void set(ll i, ll x, ll l, ll r){
		if(r - l == 1){
			v[x][0] = b[i];
			v[x][1] = a[i];
			v1[x] = (a[i] + b[i]) % mod;
			return;
		}	
		ll mid = l + (r - l) / 2;
		if(i < mid) set(i, 2 * x + 1, l, mid);
		else set(i, 2 * x + 2, mid, r);
		for(int j = 0; j < C; j++) v[x][j] = 0;
		for(int j = 0; j < C; j++) for(int k = 0; k + j < C; k++) 
			v[x][k + j] = (v[x][j + k] + v[2 * x + 1][j] * v[2 * x + 2][k]) % mod;	
		v1[x] = v1[2 * x + 1] *  v1[2 * x + 2] % mod;
	}
	
	void set(ll i){
		set(i, 0, 0, sz);
	}
};


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> C;
	segtree s;
	s.init();
	for(int i = 0; i < n; i++){
		cin >> a[i];
		a[i] %= mod;
	}
	for(int i = 0; i < n; i++){
		cin >> b[i];
		b[i] %= mod;
		s.set(i);
	}
	cin >> q;
	while(q--){
		cin >> i >> a1 >> b1;
		i--;
		a[i] = a1 % mod;
		b[i] = b1 % mod;
		s.set(i);
		ans = v1[0];
		for(int i1 = 0; i1 < C; i1++){
			ans = (ans - v[0][i1] + mod) % mod;
		}
		cout << ans << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6488 KB Output is correct
2 Correct 5 ms 6492 KB Output is correct
3 Correct 9 ms 6492 KB Output is correct
4 Correct 154 ms 17296 KB Output is correct
5 Correct 572 ms 27728 KB Output is correct
6 Correct 968 ms 27556 KB Output is correct
7 Correct 357 ms 17308 KB Output is correct
8 Correct 233 ms 27224 KB Output is correct
9 Correct 327 ms 27568 KB Output is correct
10 Correct 1217 ms 27568 KB Output is correct