Submission #217211

#TimeUsernameProblemLanguageResultExecution timeMemory
217211bharat2002Relativnost (COCI15_relativnost)C++14
140 / 140
1375 ms25156 KiB
/*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 timeMemoryGrader output
Fetching results...