이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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];
double bit2[_N];
set<int> st;
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;
}
inline ll inv(ll x) { return faspow(x, mod - 2); }
inline ll add(ll x, ll y) { return (x + y >= mod ? x + y - mod : x + y); }
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;
}
void add2(int pos, double v)
{
++pos;
for (; pos < _N; pos += pos & -pos)
bit2[pos] += v;
}
double get2(int pos)
{
++pos;
double ret = 0;
for (; pos; pos -= pos & -pos)
ret += bit2[pos];
return ret;
}
ll solve()
{
double tot = 0;
double mx = 0;
int k = 0;
int de = n - 1;
double lg = 0;
if (st.size())
{
auto it = st.end();
--it;
int sz = (int)st.size();
while (sz--)
{
lg += log(X[(*it)]);
de = (*it);
if (lg > log(1e9))
break;
--it;
}
if (lg <= log(1e9))
de = 0;
}
else
{
de = 0;
}
tot = get2(de - 1);
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]);
}
void putit(int x, int val)
{
if (val > 1)
st.insert(x);
else
{
st.erase(x);
}
}
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]);
add2(i, _X[i]);
putit(i, _X[i]);
X[i] = _X[i];
Y[i] = _Y[i];
}
return solve();
}
int updateX(int pos, int val)
{
add(pos, val, X[pos]);
add2(pos, log(val) - log(X[pos]));
putit(pos, val);
X[pos] = val;
return solve();
}
int updateY(int pos, int val)
{
Y[pos] = val;
return solve();
}
컴파일 시 표준 에러 (stderr) 메시지
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:127:21: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
127 | return solve();
| ~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:136:21: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
136 | return solve();
| ~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:142:21: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
142 | return solve();
| ~~~~~^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |