// Nurstan Duisengaliev(REALBOY)
// Respa Gold_2022
// IZHO GOLD_2022
// IOI_2022
/*#pragma GCC target ("avx2")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("O3")*/
#include <bits/stdc++.h>
#define ll long long
#define all(x) x.begin(), x.end()
#define in insert
#define mp make_pair
#define F first
#define S second
#define ppf pop_front
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair <int, int>
#define pll pair <ll, ll>
#define boost() ios_base::sync_with_stdio(0), cin.tie(0)
#define sz(x) (int)x.size()
using namespace std;
const int N = (int)2e5 + 123;
const int mod = (int)1e9 + 7;
const ll INF = (ll)1e18 + 1;
int n;
ll a[N], b[N];
ll mini[N][18][2], LOG[N];
ll ans = 0;
ll Get (int l, int r, int t) {
int ok = LOG[r - l + 1];
return min (mini[l][ok][t], mini[r - (1 << ok) + 1][ok][t]);
}
void calc (int l, int r, int optl, int optr) {
int mid = l + r >> 1;
ll maxi = 0;
int optmid;
assert (optl <= mid);
for (int i = optl; i <= min (optr, mid); i ++) {
if (maxi < Get (i, mid, 0) * Get (i, mid, 1) * (mid - i + 1)) {
maxi = Get (i, mid, 0) * Get (i, mid, 1) * (mid - i + 1);
optmid = i;
}
}
ans = max (ans, maxi);
if (l == r) return;
calc (l, mid, optl, optmid);
calc (mid + 1, r, optmid, optr);
}
void solve () {
cin >> n;
for (int i = 1; i <= n; i ++) {
cin >> a[i] >> b[i];
LOG[i] = log2 (i);
}
pll suf = mp (mod, mod);
for (int i = n; i >= 1; i --) {
suf.F = min (suf.F, a[i]);
suf.S = min (suf.S, b[i]);
mini[i][0][0] = a[i];
mini[i][0][1] = b[i];
for (int j = 1; j <= 17; j ++) {
if (i + (1 << (j - 1)) <= n) {
mini[i][j][0] = min (mini[i][j - 1][0], mini[i + (1 << (j - 1))][j - 1][0]);
mini[i][j][1] = min (mini[i][j - 1][1], mini[i + (1 << (j - 1))][j - 1][1]);
}
else {
mini[i][j][0] = suf.F;
mini[i][j][1] = suf.S;
}
}
}
calc (1, n, 1, n);
cout << ans;
}
main () {
// freopen (".in", "r", stdin);
// freopen (".out", "w", stdout);
boost ();
int TT = 1;
// cin >> TT;
while (TT --) {
solve ();
}
return 0;
}
Compilation message
tenis.cpp: In function 'void calc(int, int, int, int)':
tenis.cpp:42:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
42 | int mid = l + r >> 1;
| ~~^~~
tenis.cpp: At global scope:
tenis.cpp:84:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
84 | main () {
| ^~~~
tenis.cpp: In function 'void calc(int, int, int, int)':
tenis.cpp:54:7: warning: 'optmid' may be used uninitialized in this function [-Wmaybe-uninitialized]
54 | calc (l, mid, optl, optmid);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |