이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "horses.h"
using namespace std;
const int mod = 1e9 + 7;
int n, x[1 << 19], y[1 << 19];
struct node {
int ans, x, y;
double rans, rx, ry;
} st[1 << 20];
node Merge(node l, node r) {
node ans;
ans.x = 1LL * l.x * r.x % mod;
ans.rx = l.rx + r.rx;
if (l.rans > l.rx + r.rans)
ans.ans = l.ans, ans.rans = l.rans;
else
ans.ans = 1LL * l.x * r.ans % mod, ans.rans = l.rx + r.rans;
return ans;
}
void Build(int node = 1, int left = 1, int right = n) {
if (left == right) {
st[node].x = x[left - 1];
st[node].rx = log(x[left - 1]);
st[node].ry = log(y[left - 1]);
st[node].y = y[left - 1];
st[node].ans = 1LL * st[node].x * st[node].y % mod;
st[node].rans = st[node].rx + st[node].ry;
return;
}
int m = (left + right) / 2;
Build(2 * node, left, m), Build(2 * node + 1, m + 1, right);
st[node] = Merge(st[2 * node], st[2 * node + 1]);
}
void Update(int pos, pair<int, int> val, int node = 1, int left = 1, int right = n) {
if (left == right) {
if (val.first) {
st[node].x = val.first;
st[node].rx = log(val.first);
}
else {
st[node].y = val.second;
st[node].ry = log(val.second);
}
st[node].ans = 1LL * st[node].x * st[node].y % mod;
st[node].rans = st[node].rx + st[node].ry;
return;
}
int m = (left + right) / 2;
if (pos <= m)
Update(pos, val, 2 * node, left, m);
else
Update(pos, val, 2 * node + 1, m + 1, right);
st[node] = Merge(st[2 * node], st[2 * node + 1]);
}
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();
return st[1].ans;
}
int updateX(int pos, int val) {
Update(pos + 1, {val,0});
return st[1].ans;
}
int updateY(int pos, int val) {
Update(pos + 1, {0, val});
return st[1].ans;
}
컴파일 시 표준 에러 (stderr) 메시지
horses.cpp: In function 'node Merge(node, node)':
horses.cpp:16:26: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
16 | ans.x = 1LL * l.x * r.x % mod;
| ~~~~~~~~~~~~~~~~^~~~~
horses.cpp:21:31: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
21 | ans.ans = 1LL * l.x * r.ans % mod, ans.rans = l.rx + r.rans;
| ~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'void Build(int, int, int)':
horses.cpp:31:48: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
31 | st[node].ans = 1LL * st[node].x * st[node].y % mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'void Update(int, std::pair<int, int>, int, int, int)':
horses.cpp:50:48: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
50 | st[node].ans = 1LL * st[node].x * st[node].y % mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# | 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... |