답안 #98700

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
98700 2019-02-25T05:01:11 Z duy_tran Relativnost (COCI15_relativnost) C++14
14 / 140
1919 ms 31808 KB
#include<bits/stdc++.h>
using namespace std;

template<typename T> inline void Cin(T &x)
{
    x=0;
    T sign=1;
    char c;

    for(c=getchar();c<'0'||c>'9';c=getchar())
        if(c=='-')sign=-1;

    for(;c>='0'&&c<='9';c=getchar())
        x=x*10+c-'0';

    x*=sign;
}

template<typename T>inline void Out(T x)
{
    if(x==0)return;
    Out(x/10);
    putchar(x%10+'0');
}

template<typename T>inline void Cout(T x)
{
    if(x==0)
    {
        putchar('0');
        return;
    }

    if(x<0)putchar('-'),x=-x;
    Out(x);
}

const int modd=(int)1e4+7;
const int maxn=(int)1e5+50;
int n,c,q,leaf[maxn],a[maxn],b[maxn];
struct X
{
    int l,r,total,f[25],mul;
}tree[4*maxn];

void Combine(int id)
{
    tree[id].total=0;
    for(int i=0;i<c;++i)
    {
        tree[id].f[i]=0;
        for(int j=0;j<=i;++j)
            tree[id].f[i]=(tree[id].f[i]+(tree[id*2].f[j]*tree[id*2+1].f[i-j])%modd)%modd;
        tree[id].total+=tree[id].f[i];
    }

    tree[id].mul=(tree[id*2].mul*tree[id*2+1].mul)%modd;
}

void BuildTree(int id,int le,int ri)
{
    tree[id].l=le;
    tree[id].r=ri;

    if(le==ri)
    {
        leaf[le]=id;
        tree[id].f[0]=b[le];
        tree[id].f[1]=a[le];
        tree[id].mul=(a[le]+b[le])%modd;
        return;
    }

    int mid=(le+ri)/2;
    BuildTree(id*2,le,mid);
    BuildTree(id*2+1,mid+1,ri);

    Combine(id);
}

void Up(int id,int ap,int bp)
{
    tree[id].f[0]=bp;
    tree[id].f[1]=ap;
    tree[id].mul=(ap+bp)%modd;
    id/=2;

    while(id>0)
    {
        Combine(id);
        id/=2;
    }
}

int main()
{
    Cin(n);
    Cin(c);

    for(int i=1;i<=n;++i)
    {
        Cin(a[i]);
        a[i]%=modd;
    }

    for(int i=1;i<=n;++i)
    {
        Cin(b[i]);
        b[i]%=modd;
    }

    BuildTree(1,1,n);

    Cin(q);

    for(int i=1;i<=q;++i)
    {
        int p,ap,bp;
        Cin(p);
        Cin(ap);
        Cin(bp);
        ap%=modd;
        bp%=modd;

        Up(leaf[p],ap,bp);

        Cout((tree[1].mul-tree[1].total+modd)%modd);
        putchar('\n');
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 640 KB Output isn't correct
2 Incorrect 11 ms 640 KB Output isn't correct
3 Incorrect 19 ms 640 KB Output isn't correct
4 Incorrect 273 ms 16220 KB Output isn't correct
5 Incorrect 990 ms 31808 KB Output isn't correct
6 Incorrect 1102 ms 31784 KB Output isn't correct
7 Incorrect 496 ms 16412 KB Output isn't correct
8 Correct 374 ms 31352 KB Output is correct
9 Incorrect 560 ms 31600 KB Output isn't correct
10 Incorrect 1919 ms 31516 KB Output isn't correct