Submission #197748

# Submission time Handle Problem Language Result Execution time Memory
197748 2020-01-22T18:47:59 Z brcode Relativnost (COCI15_relativnost) C++14
140 / 140
3826 ms 27288 KB
#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 time Memory Grader output
1 Correct 13 ms 504 KB Output is correct
2 Correct 18 ms 504 KB Output is correct
3 Correct 30 ms 632 KB Output is correct
4 Correct 628 ms 13972 KB Output is correct
5 Correct 1813 ms 27128 KB Output is correct
6 Correct 2403 ms 27148 KB Output is correct
7 Correct 1137 ms 14072 KB Output is correct
8 Correct 672 ms 26972 KB Output is correct
9 Correct 1185 ms 27128 KB Output is correct
10 Correct 3826 ms 27288 KB Output is correct