Submission #316223

#TimeUsernameProblemLanguageResultExecution timeMemory
316223mohamedsobhi777말 (IOI15_horses)C++14
34 / 100
1596 ms14712 KiB
#include "horses.h"
#include <bits/stdc++.h>
#pragma GCC optimize("trapv")

using namespace std;
using ll = long long;
using ld = long double;

const int _N = 5e5 + 7, mod = 1e9 + 7;
const ll inf = 2e18;
int n, m;
ll X[_N], Y[_N];
ll bit[_N];

inline ll mul(ll x, ll y) { return 1ll * (x % mod) * (y % mod) % mod; }

ll faspow(ll x, ll y)
{
        if (!y)
                return 1ll;
        ll ret = faspow(x, y / 2);
        ret = 1ll * ret * ret % mod;
        if (y & 1)
                ret = 1ll * ret * x % mod;
        return ret;
}

ll inv(ll x)
{
        return faspow(x, mod - 2);
}

void add(int x, ll v, ll old = 1ll)
{
        ++x;
        for (; x < _N; x += x & -x)
                bit[x] = mul(bit[x], mul(v, inv(old)));
}

ll eval(int x)
{
        ++x;
        ll ret = 1ll;
        for (; x; x -= x & -x)
                ret = 1ll * ret * bit[x] % mod;
        return ret;
}

ll add(ll x, ll y)
{
        return (x + y >= mod ? x + y - mod : x + y);
}
ll solve()
{
        ll ret = 1ll;
        ll suf = 1ll;
        int i = n - 1;
        int cnt = 0;
        double tot = 0;
        double mx = 0;
        int k = 0;

        int de = n - 1;
        double lg = 0;
        for (int j = n - 1; ~j; --j)
        {
                lg += log(X[j]);
                de = j;
                if (lg > log(1e9))
                {
                        break;
                }
        }
        for (int i = 0; i < de; ++i)
                tot += log(X[i]);
        for (int j = de; j < n; ++j)
        {
                tot += log(X[j]);
                if (tot + log(Y[j]) > mx)
                {
                        k = j;
                        mx = tot + log(Y[j]);
                }
        }
        return mul(eval(k), Y[k]);
}

int init(int N, int _X[], int _Y[])
{
        n = N;
        fill(bit, bit + _N, 1);
        for (int i = 0; i < N; ++i)
        {
                add(i, _X[i]);
                X[i] = _X[i];
                Y[i] = _Y[i];
        }
        return solve();
}

int updateX(int pos, int val)
{
        add(pos, val, X[pos]);
        X[pos] = val;
        return solve();
}

int updateY(int pos, int val)
{
        Y[pos] = val;
        return solve();
}

Compilation message (stderr)

horses.cpp: In function 'll solve()':
horses.cpp:74:18: warning: declaration of 'i' shadows a previous local [-Wshadow]
   74 |         for (int i = 0; i < de; ++i)
      |                  ^
horses.cpp:57:13: note: shadowed declaration is here
   57 |         int i = n - 1;
      |             ^
horses.cpp:55:12: warning: unused variable 'ret' [-Wunused-variable]
   55 |         ll ret = 1ll;
      |            ^~~
horses.cpp:56:12: warning: unused variable 'suf' [-Wunused-variable]
   56 |         ll suf = 1ll;
      |            ^~~
horses.cpp:57:13: warning: unused variable 'i' [-Wunused-variable]
   57 |         int i = n - 1;
      |             ^
horses.cpp:58:13: warning: unused variable 'cnt' [-Wunused-variable]
   58 |         int cnt = 0;
      |             ^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:98:21: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   98 |         return solve();
      |                ~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:105:21: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  105 |         return solve();
      |                ~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:111:21: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  111 |         return solve();
      |                ~~~~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...