이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "horses.h"
#include <vector>
#include <algorithm>
#include <cstdio>
#define MAX 500001
typedef int64_t ll;
#define MOD (1e9 + 7)
using namespace std;
ll seg[4 * MAX];
vector<pair<ll, ll>> lazy(4 * MAX, {1, 1});
ll n;
ll pp[MAX];
ll y[MAX];
ll x[MAX];
void build(ll v, ll tl, ll tr) {
if (tl == tr) seg[v] = pp[tl] * y[tr];
else {
ll mid = (tl + tr) / 2;
build(v * 2, tl, mid);
build((v * 2) + 1, mid + 1, tr);
seg[v] = max(seg[v * 2], seg[(v * 2) + 1]);
}
}
void push(ll v) {
if (lazy[v].first != 1 || lazy[v].second != 1) {
ll f = lazy[v].first, s = lazy[v].second;
lazy[v * 2].first *= f; lazy[v * 2].second *= s;
lazy[(v * 2) + 1].first *= f; lazy[(v * 2) + 1].second *= s;
lazy[v] = {1, 1};
seg[v * 2] /= s; seg[v * 2] *= f;
seg[(v * 2) + 1] /= s; seg[(v * 2) + 1] *= f;
}
}
void update(ll numer, ll denom, ll v, ll l, ll r, ll tl, ll tr) {
if (l > r) return;
if (tl == l && tr == r) {
lazy[v].first *= numer;
lazy[v].second *= denom;
seg[v] /= denom;
seg[v] *= numer;
return;
}
push(v);
ll mid = (tl + tr) / 2;
update(numer, denom, v * 2, l, min(r, mid), tl, mid);
update(numer, denom, v * 2, max(l, mid + 1), r, mid + 1, tr);
seg[v] = max(seg[v * 2], seg[(v * 2) + 1]);
}
void update_specific(ll v, ll idx, ll l, ll r, ll nw) {
if (l > r) return;
if (l == idx && r == idx) {
seg[v] /= y[idx];
seg[v] *= nw;
return;
}
push(v);
ll mid = (l + r) / 2;
if (idx <= mid) update_specific(v * 2, idx, l, mid, nw);
else update_specific((v * 2) + 1, idx, mid + 1, r, nw);
seg[v] = max(seg[v * 2], seg[(v * 2) + 1]);
}
int init(int N, int X[], int Y[]) {
n = (ll)N;
for (ll i = 0; i < n; ++i) y[i] = (ll)Y[i];
for (ll i = 0; i < n; ++i) x[i] = (ll)X[i];
pp[0] = X[0];
for (ll i = 1; i < n; ++i) pp[i] = pp[i - 1] * (ll)X[i];
build(1, 0, n - 1);
return seg[1];
}
int updateX(int pos, int val) {
update((ll)val, x[pos], 1, (ll)pos, n - 1, 0, n - 1);
x[pos] = (ll)val;
return seg[1];
}
int updateY(int pos, int val) {
update_specific(1, (ll)pos, 0, n - 1, val);
y[pos] = (ll)val;
return seg[1];
}
컴파일 시 표준 에러 (stderr) 메시지
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:80:14: warning: conversion to 'int' from 'll {aka long int}' may alter its value [-Wconversion]
return seg[1];
~~~~~^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:86:14: warning: conversion to 'int' from 'll {aka long int}' may alter its value [-Wconversion]
return seg[1];
~~~~~^
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:92:14: warning: conversion to 'int' from 'll {aka long int}' may alter its value [-Wconversion]
return seg[1];
~~~~~^
# | 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... |