結果
| 問題 | No.1435 Mmm...... |
| コンテスト | |
| ユーザー |
trineutron
|
| 提出日時 | 2021-03-20 00:43:44 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 643 ms / 2,000 ms |
| コード長 | 1,477 bytes |
| 記録 | |
| コンパイル時間 | 2,291 ms |
| コンパイル使用メモリ | 206,748 KB |
| 最終ジャッジ日時 | 2025-01-19 19:56:11 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 24 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++)
{
cin >> a.at(i);
}
priority_queue<int> q;
priority_queue<int, vector<int>, greater<int>> r;
map<int, int> removed_q, removed_r;
int bound = 0;
int64_t ans = 0;
for (int i = 0; i < n; i++)
{
while (bound < n and bound - i < 2)
{
q.push(a.at(bound));
r.push(a.at(bound));
bound++;
}
while (bound <= n)
{
while (removed_q[q.top()])
{
removed_q[q.top()]--;
q.pop();
}
int mmax = q.top();
while (removed_r[r.top()])
{
removed_r[r.top()]--;
r.pop();
}
int m0 = r.top();
r.pop();
while (removed_r[r.top()])
{
removed_r[r.top()]--;
r.pop();
}
int m1 = r.top();
r.push(m0);
if (mmax > m0 + m1)
{
break;
}
if (bound < n)
{
q.push(a.at(bound));
r.push(a.at(bound));
}
bound++;
}
removed_q[a.at(i)]++;
removed_r[a.at(i)]++;
ans += max(0, bound - i - 2);
}
cout << ans << endl;
return 0;
}
trineutron