답안 #217207

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
217207 2020-03-29T08:44:23 Z bharat2002 Relativnost (COCI15_relativnost) C++14
42 / 140
1386 ms 25208 KB
/*input
4 2
1 2 3 4
1 2 3 4
1
4 1 1
*/
#include<bits/stdc++.h>
using namespace std;
const int N=1e5 + 100;
const int mod=1e4 + 7;
#define pii pair<int, int>
#define f first
#define s second 
#define mp make_pair
#define FOR(i, n) for(int i=1;i<=n;i++)
#define TRACE(x) cerr << #x << " = " << x << endl 
//Trace prints the name of the variable and the value.
int n, c;
struct node
{
	int tot, ans[22];
	void calcdp(int a[], int b[])
	{
		for(int i=0;i<=c;i++)
		{
			ans[i]=0;
			for(int j=0;j<=i;j++){
				ans[i]+=a[j]*b[i-j];ans[i]%=mod;
			}
		}
	}
};
node tree[4*N];int a[N], b[N], q;
void build(int i=1, int l=1, int r=n)
{
	if(l==r)
	{
		tree[i].tot=a[l] + b[l];tree[i].ans[1]=a[l];tree[i].ans[0]=b[l];return;
	}
	int mid=(l+r)>>1;
	build(2*i, l, mid);build(2*i+1, mid+1, r);tree[i].calcdp(tree[2*i].ans, tree[2*i+1].ans);
	tree[i].tot=tree[2*i].tot*tree[2*i+1].tot;tree[i].tot%=mod;
}
int ql, qr;
void update(int i=1, int l=1, int r=n)
{
	if(l>qr||r<ql) return;
	if(l==r)
	{
		tree[i].tot=a[l] + b[l];tree[i].ans[1]=a[l];tree[i].ans[0]=b[l];return;
	}
	int mid=(l+r)>>1;
	update(2*i, l, mid);update(2*i+1, mid+1, r);tree[i].calcdp(tree[2*i].ans, tree[2*i+1].ans);
	tree[i].tot=tree[2*i].tot*tree[2*i+1].tot;tree[i].tot%=mod;	
}
signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin>>n>>c;c--;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++) cin>>b[i];
	build();
	cin>>q;
	while(q--)
	{
		int pos, nl, nr;cin>>pos>>nl>>nr;ql=qr=pos;a[pos]=nl;b[pos]=nr;update();
		int ans=0;
		for(int i=0;i<=c;i++)
		{
			ans+=tree[1].ans[i];ans%=mod;
		}
		ans=tree[1].tot-ans;ans+=mod;ans%=mod;cout<<ans<<endl;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 512 KB Output is correct
2 Correct 11 ms 512 KB Output is correct
3 Correct 15 ms 512 KB Output is correct
4 Incorrect 335 ms 13068 KB Output isn't correct
5 Incorrect 657 ms 25080 KB Output isn't correct
6 Incorrect 890 ms 25080 KB Output isn't correct
7 Incorrect 431 ms 13048 KB Output isn't correct
8 Incorrect 304 ms 24952 KB Output isn't correct
9 Incorrect 512 ms 25208 KB Output isn't correct
10 Incorrect 1386 ms 25080 KB Output isn't correct