Submission #197748

#TimeUsernameProblemLanguageResultExecution timeMemory
197748brcodeRelativnost (COCI15_relativnost)C++14
140 / 140
3826 ms27288 KiB
#include <iostream> #include <bits/stdc++.h> using namespace std; const int MOD = 10007; const int MAXN = 1e5+5; int seg[4*MAXN][25]; int n,c; int a[MAXN]; int b[MAXN]; void build(int curr,int l,int r){ if(l==r){ seg[curr][0] = b[l]; seg[curr][1] = a[l]; seg[curr][0]%=MOD; seg[curr][1]%=MOD; return; } // cout<<curr<<endl; int mid = (l+r)/2; build(2*curr,l,mid); build(2*curr+1,mid+1,r); for(int i=0;i<=c;i++){ for(int j=0;j<=c;j++){ seg[curr][min(i+j,c)] += (1LL*seg[2*curr][i]*seg[2*curr+1][j]); seg[curr][min(i+j,c)]%=MOD; } } } void update(int curr,int l,int r,int target){ if(l==r){ seg[curr][0] = b[l]; seg[curr][1] = a[l]; seg[curr][0]%=MOD; seg[curr][1]%=MOD; return; } int mid = (l+r)/2; if(target<=mid){ update(2*curr,l,mid,target); for(int i=0;i<=c;i++){ seg[curr][i] = 0; } for(int i=0;i<=c;i++){ for(int j=0;j<=c;j++){ seg[curr][min(i+j,c)] += (1LL*seg[2*curr][i]*seg[2*curr+1][j]); seg[curr][min(i+j,c)]%=MOD; } } }else{ update(2*curr+1,mid+1,r,target); for(int i=0;i<=c;i++){ seg[curr][i] = 0; } for(int i=0;i<=c;i++){ for(int j=0;j<=c;j++){ seg[curr][min(i+j,c)] += (1LL*seg[2*curr][i]*seg[2*curr+1][j]); seg[curr][min(i+j,c)]%=MOD; } } } } int main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); cin>>n>>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(1,1,n); int q; cin>>q; while(q--){ int pos; cin>>pos; cin>>a[pos]>>b[pos]; update(1,1,n,pos); cout<<seg[1][c]<<endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...