Submission #197745

#TimeUsernameProblemLanguageResultExecution timeMemory
197745brcodeRelativnost (COCI15_relativnost)C++14
70 / 140
1291 ms58232 KiB
#include <iostream> #include <bits/stdc++.h> using namespace std; const long long MOD = 10007; const long long MAXN = 1e5+5; long long seg[2*MAXN][25]; long long n,c; long long a[MAXN]; long long b[MAXN]; void build(long long curr,long long l,long long r){ if(l==r){ seg[curr][0] = b[l]; seg[curr][1] = a[l]; seg[curr][0]%=MOD; seg[curr][1]%=MOD; return; } long long mid = (l+r)/2; build(2*curr,l,mid); build(2*curr+1,mid+1,r); for(long long i=0;i<=c;i++){ for(long long 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(long long curr,long long l,long long r,long long target){ if(l==r){ seg[curr][0] = b[l]; seg[curr][1] = a[l]; seg[curr][0]%=MOD; seg[curr][1]%=MOD; return; } long long mid = (l+r)/2; if(target<=mid){ update(2*curr,l,mid,target); for(long long i=0;i<=c;i++){ seg[curr][i] = 0; } for(long long i=0;i<=c;i++){ for(long long 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(long long i=0;i<=c;i++){ seg[curr][i] = 0; } for(long long i=0;i<=c;i++){ for(long long 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(){ cin>>n>>c; for(long long i=1;i<=n;i++){ cin>>a[i]; } for(long long i=1;i<=n;i++){ cin>>b[i]; } build(1,1,n); long long q; cin>>q; while(q--){ long long pos; cin>>pos; cin>>a[pos]>>b[pos]; update(1,1,n,pos); cout<<seg[1][c]<<endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...