이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using ld = long double;
template<typename T1, typename T2> bool chkmin(T1& x, T2 y) {
return y < x ? (x = y, true) : false;
}
template<typename T1, typename T2> bool chkmax(T1& x, T2 y) {
return y > x ? (x = y, true) : false;
}
void debug_out() {
cerr << endl;
}
template<typename T1, typename... T2> void debug_out(T1 A, T2... B) {
cerr << ' ' << A;
debug_out(B...);
}
template<typename T> void mdebug_out(T* a, int n) {
for (int i = 0; i < n; ++i) {
cerr << a[i] << ' ';
}
cerr << endl;
}
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mdebug(a, n) cerr << #a << ": ", mdebug_out(a, n)
#else
#define debug(...) 1337
#define mdebug(a, n) 1337
#endif
template<typename T> ostream& operator << (ostream& stream, const vector<T>& v) {
for (auto& x : v) {
stream << x << ' ';
}
return stream;
}
template<typename T1, typename T2> ostream& operator << (ostream& stream, const pair<T1, T2>& p) {
return stream << p.first << ' ' << p.second;
}
const int MOD = 1e9 + 7;
struct Num {
int a;
bool big;
Num(): a(0), big(0) {}
Num(ll _a) {
assert(_a >= 0);
a = _a % MOD;
big = _a >= MOD;
}
Num(const Num& oth): a(oth.a), big(oth.big) {}
Num& operator += (const Num& oth) {
big |= oth.big;
if ((a += oth.a) >= MOD) {
big = true;
a -= MOD;
}
return *this;
}
Num& operator *= (const Num& oth) {
ll prod = a * (ll)oth.a;
big |= oth.big || prod >= MOD;
a = prod % MOD;
return *this;
}
};
Num operator + (const Num& lhs, const Num& rhs) {
return Num(lhs) += rhs;
}
Num operator * (const Num& lhs, const Num& rhs) {
return Num(lhs) *= rhs;
}
struct Node {
Num f;
Num p;
ld ratio;
Node() {
f = Num();
p = 1;
ratio = 0;
}
Node(int x, int y) {
f = Num(x * (ll)y);
p = x;
ratio = y;
}
};
Node operator * (const Node& lhs, const Node& rhs) {
Node res;
res.p = lhs.p * rhs.p;
if (rhs.f.big || rhs.f.a > lhs.ratio) {
res.f = rhs.f * lhs.p;
res.ratio = rhs.ratio;
} else {
res.f = lhs.f;
res.ratio = lhs.ratio / (ld)rhs.p.a;
}
return res;
}
const int logN = 19;
const int N = 1 << logN;
int n;
Node t[2 * N];
int X[N], Y[N];
void build() {
for (int i = 0; i < n; ++i) {
t[i + N] = Node(X[i], Y[i]);
}
for (int v = N - 1; v >= 1; --v) {
t[v] = t[v << 1] * t[v << 1 | 1];
}
}
void mdf(int i, int x, int y) {
X[i] = x;
Y[i] = y;
int v = i + N;
t[v] = Node(x, y);
for (v >>= 1; v >= 1; v >>= 1) {
t[v] = t[v << 1] * t[v << 1 | 1];
}
}
int gt() {
return t[1].f.a;
}
int init(int _n, int* x, int* y) {
n = _n;
memcpy(X, x, n << 2);
memcpy(Y, y, n << 2);
build();
return gt();
}
int updateX(int i, int x) {
mdf(i, x, Y[i]);
return gt();
}
int updateY(int i, int y) {
mdf(i, X[i], y);
return gt();
}
#ifdef DEBUG
int32_t main() {
#ifdef DEBUG
freopen("in", "r", stdin);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
int* x = new int[n];
for (int i = 0; i < n; ++i) {
cin >> x[i];
}
int* y = new int[n];
for (int i = 0; i < n; ++i) {
cin >> y[i];
}
cout << init(n, x, y) << '\n';
int Q;
cin >> Q;
while (Q--) {
int tp, pos, val;
cin >> tp >> pos >> val;
if (tp == 1) {
cout << updateX(pos, val) << '\n';
} else {
cout << updateY(pos, val) << '\n';
}
}
return 0;
}
#endif
컴파일 시 표준 에러 (stderr) 메시지
horses.cpp: In constructor 'Num::Num(ll)':
horses.cpp:63:12: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
63 | a = _a % MOD;
| ~~~^~~~~
horses.cpp: In member function 'Num& Num::operator*=(const Num&)':
horses.cpp:79:14: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
79 | a = prod % MOD;
| ~~~~~^~~~~
horses.cpp: In constructor 'Node::Node()':
horses.cpp:96:13: warning: implicitly-declared 'constexpr Num& Num::operator=(const Num&)' is deprecated [-Wdeprecated-copy]
96 | f = Num();
| ^
horses.cpp:66:3: note: because 'Num' has user-provided 'Num::Num(const Num&)'
66 | Num(const Num& oth): a(oth.a), big(oth.big) {}
| ^~~
horses.cpp:97:9: warning: implicitly-declared 'constexpr Num& Num::operator=(const Num&)' is deprecated [-Wdeprecated-copy]
97 | p = 1;
| ^
horses.cpp:66:3: note: because 'Num' has user-provided 'Num::Num(const Num&)'
66 | Num(const Num& oth): a(oth.a), big(oth.big) {}
| ^~~
horses.cpp: In constructor 'Node::Node(int, int)':
horses.cpp:101:22: warning: implicitly-declared 'constexpr Num& Num::operator=(const Num&)' is deprecated [-Wdeprecated-copy]
101 | f = Num(x * (ll)y);
| ^
horses.cpp:66:3: note: because 'Num' has user-provided 'Num::Num(const Num&)'
66 | Num(const Num& oth): a(oth.a), big(oth.big) {}
| ^~~
horses.cpp:102:9: warning: implicitly-declared 'constexpr Num& Num::operator=(const Num&)' is deprecated [-Wdeprecated-copy]
102 | p = x;
| ^
horses.cpp:66:3: note: because 'Num' has user-provided 'Num::Num(const Num&)'
66 | Num(const Num& oth): a(oth.a), big(oth.big) {}
| ^~~
horses.cpp: In function 'Node operator*(const Node&, const Node&)':
horses.cpp:108:23: warning: implicitly-declared 'constexpr Num& Num::operator=(const Num&)' is deprecated [-Wdeprecated-copy]
108 | res.p = lhs.p * rhs.p;
| ^
horses.cpp:66:3: note: because 'Num' has user-provided 'Num::Num(const Num&)'
66 | Num(const Num& oth): a(oth.a), big(oth.big) {}
| ^~~
horses.cpp:110:25: warning: implicitly-declared 'constexpr Num& Num::operator=(const Num&)' is deprecated [-Wdeprecated-copy]
110 | res.f = rhs.f * lhs.p;
| ^
horses.cpp:66:3: note: because 'Num' has user-provided 'Num::Num(const Num&)'
66 | Num(const Num& oth): a(oth.a), big(oth.big) {}
| ^~~
horses.cpp:113:17: warning: implicitly-declared 'constexpr Num& Num::operator=(const Num&)' is deprecated [-Wdeprecated-copy]
113 | res.f = lhs.f;
| ^
horses.cpp:66:3: note: because 'Num' has user-provided 'Num::Num(const Num&)'
66 | Num(const Num& oth): a(oth.a), big(oth.big) {}
| ^~~
# | 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... |