# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
217211 | bharat2002 | Relativnost (COCI15_relativnost) | C++14 | 1375 ms | 25156 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*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];
tree[i].tot%=mod;tree[i].ans[1]%=mod;tree[i].ans[0]%=mod;
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];
tree[i].tot%=mod;tree[i].ans[1]%=mod;tree[i].ans[0]%=mod;
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];a[i]%=mod;}
for(int i=1;i<=n;i++) {cin>>b[i];b[i]%=mod;}
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;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |