Submission #98681

# Submission time Handle Problem Language Result Execution time Memory
98681 2019-02-25T03:49:01 Z tduong0806 Relativnost (COCI15_relativnost) C++14
0 / 140
363 ms 33792 KB
#include<bits/stdc++.h>
using namespace std;
#define forinc(i,a,b) for(int i=a;i<=b;++i)
#define fordec(i,a,b) for(int i=a;i>=b;--i)
#define int long long
#define forv(a,b) for(auto &a:b)
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define all(a) a.begin(),a.end()
#define reset(f,x) memset(f,x,sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define onbit(x,i) (x|(1<<(i-1)))
#define offbit(x,i) (x&~(1<<(i-1)))
#define read2(a,b) read(a),read(b)
#define read3(a,b,c) read(a),read(b),read(c)
const int N=100010,mod=10007;
int n,c,q,a[N],b[N],T,t[4*N][22];
int pw(int a,int i)
{
    int b=1;
    for(;i;i>>=1,a=a*a%mod) if(i&1) b=b*a%mod;
    return b;
}
void tran(int s)
{
    forinc(i,0,c-1) t[s][i]=0;
    forinc(i,0,c-1) forinc(j,0,c-i-1)
    {
        //cout<<s<<" "<<i<<" "<<j<<" "<<t[2*s][i]<<" "<<t[2*s+1][j]<<endl;
        t[s][i+j]=(t[s][i+j]+t[2*s][i]*t[2*s+1][j])%mod;
    }
}
void build(int s,int l,int r)
{
    if(l==r)
    {
        t[s][1]=a[l];
        t[s][0]=b[l];
        return;
    }
    int mid=(l+r)/2;
    build(2*s,l,mid);
    build(2*s+1,mid+1,r);
    tran(s);
}
void update(int s,int l,int r,int u,pii x)
{
    if(u<l||u>r) return;
    if(l==r)
    {
        t[s][1]=x.fi;
        t[s][0]=x.se;
        return;
    }
    int mid=(l+r)/2;
    update(2*s,l,mid,u,x);
    update(2*s+1,mid+1,r,u,x);
    tran(s);
}
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("RELATIVNOST.inp","r",stdin);
    //freopen("RELATIVNOST.out","w",stdout);
    cin>>n>>c;
    T=1;
    forinc(i,1,n)
    {
        cin>>a[i]>>b[i];
        T=(T*(a[i]+b[i]))%mod;
    }
    build(1,1,n);
    cin>>q;
    while(q--)
    {
        int i,A,B;
        cin>>i>>A>>B;
        T=(T*pw(a[i]+b[i],mod-2)%mod*(A+B))%mod;
        a[i]=A,b[i]=B;
        update(1,1,n,i,{A,B});
        int kq=T;
        forinc(i,0,c-1) kq=(kq-t[1][i])%mod;
        if(kq<0) kq+=mod;
        cout<<kq<<"\n";
    }
}

Compilation message

relativnost.cpp:62:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 768 KB Output isn't correct
2 Incorrect 5 ms 768 KB Output isn't correct
3 Incorrect 9 ms 768 KB Output isn't correct
4 Incorrect 312 ms 24188 KB Output isn't correct
5 Runtime error 78 ms 33792 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 84 ms 33792 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Incorrect 363 ms 24336 KB Output isn't correct
8 Runtime error 73 ms 33792 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 75 ms 33792 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 82 ms 33792 KB Execution killed with signal 9 (could be triggered by violating memory limits)