QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#573171 | #9313. Make Max | cmdgbb_fan | TL | 0ms | 0kb | C++17 | 784b | 2024-09-18 17:35:32 | 2024-09-18 17:35:34 |
Judging History
answer
#include <algorithm>
#include <cstdio>
#include <vector>
#define x first
#define y second
#define pb emplace_back
#define int long long
using namespace std;
signed main() {
int T;
scanf("%d", &T);
while (T--) {
int n;
scanf("%d", &n);
vector<int> a(n + 1, 0LL);
for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
vector<pair<int, int>> p;
long long ans = 0;
for (int i = 1; i <= n; ++i) {
int j = i;
while (!p.empty() && p.back().x < a[i]) {
j = p.back().y;
p.pop_back();
ans += i - j;
}
if (p.empty() || p.back().x > a[i]) p.pb(a[i], j);
}
while (p.size() > 1) {
ans += n + 1 - p.back().x;
p.pop_back();
}
printf("%lld\n", ans);
}
}
詳細信息
Test #1:
score: 0
Time Limit Exceeded
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3
output:
1 0 3 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...