This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "horses.h"
#include "bits/stdc++.h"
using namespace std;
const int mod = 1e9 + 7;
using ll = long long;
struct SegTreeY {
vector<int> tree;
int size;
int neutral_element = -1e9;
int merge(int a, int b) {
return max(a, b);
}
void build(const vector<int> &a) {
size = 1;
while (size < a.size()) size *= 2;
tree.assign(2 * size, neutral_element);
for (int i = size; i < size + a.size(); i++) tree[i] = a[i - size];
for (int i = size - 1; i > 0; i--) tree[i] = merge(tree[i << 1], tree[i << 1 | 1]);
}
void upd(int i, int v) {
i += size;
tree[i] = v;
for (; i > 1; i >>= 1) tree[i >> 1] = merge(tree[i], tree[i ^ 1]);
}
int get(int l, int r) {
if (l > r) return neutral_element;
int res = neutral_element;
for (l += size, r += size + 1; l < r; l >>= 1, r >>= 1) {
if (l & 1) res = merge(res, tree[l++]);
if (r & 1) res = merge(res, tree[--r]);
}
return res;
}
};
struct SegTreeX {
vector<int> tree;
int size;
int neutral_element = 1;
int merge(int a, int b) {
return 1ll * a * b % mod;
}
void build(const vector<int> &a) {
size = 1;
while (size < a.size()) size *= 2;
tree.assign(2 * size, neutral_element);
for (int i = size; i < size + a.size(); i++) tree[i] = a[i - size];
for (int i = size - 1; i > 0; i--) tree[i] = merge(tree[i << 1], tree[i << 1 | 1]);
}
void upd(int i, int v) {
i += size;
tree[i] = v;
for (; i > 1; i >>= 1) tree[i >> 1] = merge(tree[i], tree[i ^ 1]);
}
int get(int l, int r) {
if (l > r) return neutral_element;
int res = neutral_element;
for (l += size, r += size + 1; l < r; l >>= 1, r >>= 1) {
if (l & 1) res = merge(res, tree[l++]);
if (r & 1) res = merge(res, tree[--r]);
}
return res;
}
};
int n;
vector<int> x, y;
int get_ans() {
ll best = 1;
int mul = 1;
for (int i = 0; i < n; i++) {
mul *= x[i];
best = max(best, ll(mul) * y[i]);
}
return best % mod;
}
int init(int N, int X[], int Y[]) {
n = N;
x.resize(n), y.resize(n);
for (int i = 0; i < n; i++) x[i] = X[i], y[i] = Y[i];
return get_ans();
}
int updateX(int pos, int val) {
x[pos] = val;
return get_ans();
}
int updateY(int pos, int val) {
y[pos] = val;
return get_ans();
}
Compilation message (stderr)
horses.cpp: In member function 'void SegTreeY::build(const std::vector<int>&)':
horses.cpp:18:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | while (size < a.size()) size *= 2;
| ~~~~~^~~~~~~~~~
horses.cpp:20:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for (int i = size; i < size + a.size(); i++) tree[i] = a[i - size];
| ~~^~~~~~~~~~~~~~~~~
horses.cpp: In member function 'int SegTreeX::merge(int, int)':
horses.cpp:47:22: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
47 | return 1ll * a * b % mod;
| ~~~~~~~~~~~~^~~~~
horses.cpp: In member function 'void SegTreeX::build(const std::vector<int>&)':
horses.cpp:52:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | while (size < a.size()) size *= 2;
| ~~~~~^~~~~~~~~~
horses.cpp:54:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for (int i = size; i < size + a.size(); i++) tree[i] = a[i - size];
| ~~^~~~~~~~~~~~~~~~~
horses.cpp: In function 'int get_ans()':
horses.cpp:85:14: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
85 | return best % 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... |