이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "horses.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5e5 + 10;
const ll mod = 1e9 + 7;
ll x[maxn], y[maxn], n;
ll prod_tree[4 * maxn];
void build_prod_tree(int root, int left, int right)
{
if (left == right)
{
prod_tree[root] = x[left];
return;
}
int mid = (left + right) / 2;
build_prod_tree(root * 2, left, mid);
build_prod_tree(root * 2 + 1, mid + 1, right);
prod_tree[root] = (prod_tree[root * 2] * prod_tree[root * 2 + 1]) % mod;
}
void update_prod(int root, int left, int right, int pos)
{
if (left == right)
{
prod_tree[root] = x[left];
return;
}
int mid = (left + right) / 2;
if (pos <= mid)
update_prod(root * 2, left, mid, pos);
else
update_prod(root * 2 + 1, mid + 1, right, pos);
prod_tree[root] = (prod_tree[root * 2] * prod_tree[root * 2 + 1]) % mod;
}
ll prod_query(int root, int left, int right, int qleft, int qright)
{
if (left > qright || right < qleft)
return 1;
if (left >= qleft && right <= qright)
return prod_tree[root];
int mid = (left + right) / 2;
return (prod_query(root * 2, left, mid, qleft, qright) *
prod_query(root * 2 + 1, mid + 1, right, qleft, qright)) % mod;
}
ll action()
{
ll up = y[n - 1], dw = 1, pos = n - 1;
ll div = 1;
for (int i = n - 2; i >= 0; i --)
{
div = div * x[i + 1];
if (div > 1e9)
break;
///cout << i << " : " << y[i] << " " << div << endl;
/// y[i] / div >? up / dw
if (y[i] * dw >= up * div)
{
///cout << " " << up << " : " << dw << endl;
up = y[i];
dw = div;
pos = i;
}
}
///cout << pos << endl;
ll ans = prod_query(1, 0, n - 1, 0, pos);
//for (int i = 0; i <= pos; i ++)
// ans = (ans * x[i]) % mod;
ans = (ans * y[pos]) % mod;
return ans;
}
int init(int N, int X[], int Y[])
{
n = N;
for (int i = 0; i < n; i ++)
{
x[i] = X[i];
y[i] = Y[i];
}
build_prod_tree(1, 0, n - 1);
return action();
}
int updateX(int pos, int val)
{
x[pos] = val;
update_prod(1, 0, n - 1, pos);
return action();
}
int updateY(int pos, int val)
{
y[pos] = val;
return action();
}
컴파일 시 표준 에러 (stderr) 메시지
horses.cpp: In function 'll action()':
horses.cpp:61:20: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
61 | for (int i = n - 2; i >= 0; i --)
| ~~^~~
horses.cpp:64:13: warning: conversion from 'll' {aka 'long long int'} to 'double' may change value [-Wconversion]
64 | if (div > 1e9)
| ^~~
horses.cpp:79:33: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
79 | ll ans = prod_query(1, 0, n - 1, 0, pos);
| ~~^~~
horses.cpp:79:41: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
79 | ll ans = prod_query(1, 0, n - 1, 0, pos);
| ^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:93:29: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
93 | build_prod_tree(1, 0, n - 1);
| ~~^~~
horses.cpp:94:18: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
94 | return action();
| ~~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:100:25: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
100 | update_prod(1, 0, n - 1, pos);
| ~~^~~
horses.cpp:101:18: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
101 | return action();
| ~~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:107:18: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
107 | return action();
| ~~~~~~^~
# | 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... |