Submission #485879

# Submission time Handle Problem Language Result Execution time Memory
485879 2021-11-09T15:37:38 Z leductoan Relativnost (COCI15_relativnost) C++11
126 / 140
4000 ms 12568 KB
#include<bits/stdc++.h>

using namespace std;

#define task "sol"
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define zs(v) ((int)(v).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define CNTBIT __builtin_popcountll
#define ALL(v) (v).begin(),(v).end()
#define endl '\n'

typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;

const int dx[4]={-1, 0, 1, 0}, dy[4]={0, 1, 0, -1};
const int dxx[8]={-1, -1, 0, 1, 1, 1, 0, -1}, dyy[8]={0, 1, 1, 1, 0, -1, -1, -1};
const ll mod = 10007; /// 998244353
const ll base = 331;
const int N=1e5+1;

int n,c,a[N],b[N];
short st[N<<2][21];

void join(int p, short dp[21], short f[21], short g[21])
{
    for (int i=0;i<=c;++i) dp[i]=0;
    for (int i=0;i<=c;++i) if (f[i])
    for (int j=0;j<=c;++j) if (g[j])
    {
        int k=min(i+j,c);
        dp[k]+=(int)f[i]*g[j]%mod*b[p]%mod;
        k++;
        k=min(k,c);
        dp[k]+=(int)f[i]*g[j]%mod*a[p]%mod;
        dp[k]%=mod;
    }
}
void update(int p)
{
    int l=0, r=n, i=1;
    vector<pii> path;
    while (true)
    {
        if (l==r)
        {
            assert(l==p);
            for (int j=0;j<=c;++j) st[i][j]=0;
            st[i][0]=1;
            break;
        }
        int mid=(l+r)>>1;
        path.pb(mp(mid+1,i));
        if (p<=mid) r=mid, i=i*2;
        else l=mid+1, i=i*2+1;
    }
    reverse(ALL(path));
    for (pii i:path) join(i.fi,st[i.se],st[i.se<<1],st[i.se<<1|1]);
}
void gogo()
{
    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;
    for (int i=0;i<=n;++i) update(i);
    int q;
    cin>>q;
    while (q--)
    {
        int i,x,y;
        cin>>i>>x>>y;
        a[i]=x, b[i]=y;
        a[i]%=mod;
        b[i]%=mod;
//        cout<<a[i]<<" "<<b[i]<<endl;
        update(i);
        cout<<st[1][c]<<endl;
    }
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    if (fopen(task".inp", "r"))
    {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    gogo();
}

Compilation message

relativnost.cpp: In function 'int main()':
relativnost.cpp:91:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
relativnost.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 332 KB Output is correct
2 Correct 16 ms 332 KB Output is correct
3 Correct 27 ms 424 KB Output is correct
4 Correct 586 ms 6568 KB Output is correct
5 Correct 1905 ms 12224 KB Output is correct
6 Correct 2975 ms 12568 KB Output is correct
7 Correct 1234 ms 6572 KB Output is correct
8 Correct 675 ms 12084 KB Output is correct
9 Correct 1247 ms 12356 KB Output is correct
10 Execution timed out 4040 ms 12296 KB Time limit exceeded