/**
____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N_MAX = 200002;
const int L_MAX = 1000002;
int n;
int a[N_MAX], b[N_MAX];
vector <pair <int, int> > vp;
bool active[N_MAX];
int root[N_MAX];
deque <int> stL[N_MAX], stR[N_MAX];
int L[N_MAX], R[N_MAX];
int findRoot (int u)
{
if(root[u] == u)
return u;
return root[u] = findRoot(root[u]);
}
void mergeDeques (deque <int>* to, deque <int>* from)
{
if((int)to->size() > (int)from->size())
{
while(from->empty() == false)
{
to->push_back(from->front());
from->pop_front();
}
}
else
{
while(to->empty() == false)
{
from->push_front(to->back());
to->pop_back();
}
swap(to, from);
}
}
vector <int> recalc;
ll maxArea;
ll area (int i)
{
return 1LL * (L[i] + R[i] + 1) * a[i];
}
void join (int u, int v)
{
u = findRoot(u);
v = findRoot(v);
recalc.push_back(stL[v].front());
while(stL[u].empty() == false && a[stL[u].back()] >= a[stL[v].front()])
stL[u].pop_back();
if(stL[u].empty() == true)
L[stL[v].front()] = stL[v].front() - 1;
else
L[stL[v].front()] = stL[v].front() - stL[u].back() - 1;
recalc.push_back(stR[u].front());
while(stR[v].empty() == false && a[stR[v].back()] >= a[stR[u].front()])
stR[v].pop_back();
if(stR[v].empty() == true)
R[stR[u].front()] = n - stR[u].front();
else
R[stR[u].front()] = stR[v].back() - stR[u].front() - 1;
mergeDeques(&stL[v], &stL[u]);
mergeDeques(&stR[v], &stR[u]);
root[u] = v;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i] >> b[i];
for(int i = 1; i <= n; i++)
vp.push_back(make_pair(b[i], i));
sort(vp.begin(), vp.end());
reverse(vp.begin(), vp.end());
for(int i = 1; i <= n; i++)
{
root[i] = i;
active[i] = false;
stL[i].push_back(i);
stR[i].push_back(i);
L[i] = R[i] = 0;
}
ll ans = 0;
for(pair <int, int> p : vp)
{
int i = p.second;
active[i] = true;
if(i > 1 && active[i - 1] == true)
join(i - 1, i);
if(i < n && active[i + 1] == true)
join(i, i + 1);
recalc.push_back(i);
for(int r : recalc)
maxArea = max(maxArea, area(r));
recalc.clear();
ans = max(ans, maxArea * b[i]);
}
cout << ans << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
189 ms |
270012 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
189 ms |
270012 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |