답안 #268675

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
268675 2020-08-16T17:43:57 Z mayhoubsaleh Relativnost (COCI15_relativnost) C++14
70 / 140
4000 ms 51124 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define left 2*i+1
#define righ 2*i+2
#define mid (l+r)/2
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);


using namespace std;
const ll maxn=1e5+100;
const ll inf=1e9+10;
const ll mod=1e4+7;

ll n,a[maxn],b[maxn],c,q;
ll st[4*maxn][22];

void build(ll i,ll l,ll r){
    if(l==r){
        st[i][0]=b[r]%mod;
        st[i][1]=a[r]%mod;
        return;
    }
    build(left,l,mid);
    build(righ,mid+1,r);

    for(ll j=0;j<=c;j++){
        for(ll k=0;k<=c;k++){
            st[i][min(j+k,c)]=(st[i][min(j+k,c)]+(st[left][j]*st[righ][k])%mod)%mod;
        }
    }
}

void upd(ll i,ll l,ll r,ll id){
    if(r<id||l>id)return;
    if(l==r){
        st[i][0]=b[id]%mod;
        st[i][1]=a[id]%mod;
        return;
    }
    upd(left,l,mid,id);
    upd(righ,mid+1,r,id);

    for(ll j=0;j<=c;j++)st[i][j]=0;

    for(ll j=0;j<=c;j++){
        for(ll k=0;k<=c;k++){
            st[i][min(j+k,c)]=(st[i][min(j+k,c)]+(st[left][j]*st[righ][k])%mod)%mod;
        }
    }
}
int main()
{
    IOS
    cin>>n>>c;
    for(ll i=0;i<n;i++)cin>>a[i];
    for(ll i=0;i<n;i++)cin>>b[i];

    build(0,0,n-1);

    cin>>q;
    while(q--){
        ll p;
        cin>>p;
        p--;
        cin>>a[p]>>b[p];
        //for(ll i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl;
        //for(ll j=0;j<n;j++)cout<<b[j]<<' ';cout<<endl;
        upd(0,0,n-1,p);
        cout<<st[0][c]<<endl;
    }
    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 768 KB Output is correct
2 Correct 19 ms 768 KB Output is correct
3 Correct 31 ms 768 KB Output is correct
4 Correct 662 ms 26868 KB Output is correct
5 Runtime error 1864 ms 51124 KB Memory limit exceeded
6 Runtime error 2651 ms 50952 KB Memory limit exceeded
7 Correct 1276 ms 27184 KB Output is correct
8 Runtime error 741 ms 50296 KB Memory limit exceeded
9 Runtime error 1268 ms 50876 KB Memory limit exceeded
10 Execution timed out 4030 ms 46684 KB Time limit exceeded