Submission #268677

# Submission time Handle Problem Language Result Execution time Memory
268677 2020-08-16T17:48:04 Z mayhoubsaleh Relativnost (COCI15_relativnost) C++14
140 / 140
4000 ms 24268 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 int maxn=1e5+100;
const int inf=1e9+10;
const int mod=1e4+7;

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

void build(int i,int l,int 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(int j=0;j<=c;j++){
        for(int 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(int i,int l,int r,int 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(int j=0;j<=c;j++)st[i][j]=0;

    for(int j=0;j<=c;j++){
        for(int 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;
    scanf("%d%d",&n,&c);
    for(int i=0;i<n;i++)scanf("%d",a+i);//cin>>a[i];
    for(int i=0;i<n;i++)scanf("%d",b+i);//cin>>b[i];

    build(0,0,n-1);

    //cin>>q;
    scanf("%d",&q);
    while(q--){
        int p;
        //cin>>p;
        scanf("%d",&p);
        p--;
        //cin>>a[p]>>b[p];
        scanf("%d%d",a+p,b+p);
        //for(int i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl;
        //for(int j=0;j<n;j++)cout<<b[j]<<' ';cout<<endl;
        upd(0,0,n-1,p);
        //cout<<st[0][c]<<endl;
        printf("%d\n",st[0][c]);
    }
    return 0;
}

Compilation message

relativnost.cpp: In function 'int main()':
relativnost.cpp:56:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   56 |     scanf("%d%d",&n,&c);
      |     ~~~~~^~~~~~~~~~~~~~
relativnost.cpp:57:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   57 |     for(int i=0;i<n;i++)scanf("%d",a+i);//cin>>a[i];
      |                         ~~~~~^~~~~~~~~~
relativnost.cpp:58:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   58 |     for(int i=0;i<n;i++)scanf("%d",b+i);//cin>>b[i];
      |                         ~~~~~^~~~~~~~~~
relativnost.cpp:63:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   63 |     scanf("%d",&q);
      |     ~~~~~^~~~~~~~~
relativnost.cpp:67:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   67 |         scanf("%d",&p);
      |         ~~~~~^~~~~~~~~
relativnost.cpp:70:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   70 |         scanf("%d%d",a+p,b+p);
      |         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 512 KB Output is correct
2 Correct 15 ms 512 KB Output is correct
3 Correct 29 ms 512 KB Output is correct
4 Correct 536 ms 12664 KB Output is correct
5 Correct 1691 ms 23944 KB Output is correct
6 Correct 2529 ms 23992 KB Output is correct
7 Correct 1104 ms 12368 KB Output is correct
8 Correct 594 ms 23800 KB Output is correct
9 Correct 1081 ms 24056 KB Output is correct
10 Correct 4000 ms 24268 KB Output is correct