Submission #197747

# Submission time Handle Problem Language Result Execution time Memory
197747 2020-01-22T18:43:35 Z brcode Relativnost (COCI15_relativnost) C++14
126 / 140
4000 ms 27248 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(){
    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 14 ms 632 KB Output is correct
2 Correct 24 ms 504 KB Output is correct
3 Correct 31 ms 504 KB Output is correct
4 Correct 798 ms 13984 KB Output is correct
5 Correct 1934 ms 27208 KB Output is correct
6 Correct 2658 ms 27248 KB Output is correct
7 Correct 1305 ms 14028 KB Output is correct
8 Correct 861 ms 27024 KB Output is correct
9 Correct 1503 ms 27196 KB Output is correct
10 Execution timed out 4008 ms 27100 KB Time limit exceeded