답안 #47717

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
47717 2018-05-06T16:48:05 Z tieunhi Relativnost (COCI15_relativnost) C++14
0 / 140
2 ms 484 KB
#include <bits/stdc++.h>
#define N 100005
#define mid (r + l)/2
#define L id*2
#define R id*2+1
#define mod 10007
using namespace std;

int n, C, a[N], b[N];

struct IntervalTree
{
	int t[N << 2][21];
	int s[N << 2];
	void build(int l, int r, int id)
	{
		if (l == r)
		{
			t[id][1] = a[l];
			t[id][0] = b[l];
			s[id] = a[l] + b[l];
			return;
		}
		build(l, mid, L);
		build(mid+1, r, R);
		for (int i = 0; i < C; i++)
			for (int j = 0; j < C; j++)
				if (i + j < C)
					t[id][i+j] = (t[id][i+j] + (t[L][i]*t[R][j]) % mod) % mod;
		s[id] = (s[L]*s[R]) % mod;
	}
	void update(int l, int r, int id, int x)
	{
		if (l > x || r < x) return;
		if (l == r)
		{
			t[id][1] = a[l];
			t[id][0] = b[l];
			s[id] = a[l] + b[l];
			return;
		}
		if (x <= mid) update(l, mid, L, x);
		else update(mid+1, r, R, x);
		for (int i = 0; i < C; i++) t[id][i] = 0;
		for (int i = 0; i < C; i++)
			for (int j = 0; j < C; j++)
				if (i + j < C)
					t[id][i+j] = (t[id][i+j] + (t[L][i]*t[R][j]) % mod) % mod;
		s[id] = (s[L]*s[R]) % mod;
	}
	int get()
	{
		int res = 0;
		for (int i = 0; i < C; i++)
			res = (res + t[1][i]);
		return (s[1] - res + mod) % mod;
	}
}t;
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	//freopen("INP.TXT", "r", stdin);
	cin >> n >> C;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= n; i++) cin >> b[i];
	t.build(1, n, 1);
	int numQuery; cin >> numQuery;
	while (numQuery--)
	{
		int pos, u, v; cin >> pos >> u >> v;
		a[pos] = u; b[pos] = v;
		t.update(1, n, 1, pos);
		cout <<t.get()<<'\n';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 2 ms 248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 1 ms 320 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 1 ms 336 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 1 ms 336 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 1 ms 336 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 1 ms 364 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 1 ms 440 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 1 ms 456 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 1 ms 484 KB Execution killed with signal 11 (could be triggered by violating memory limits)