QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#573171 | #9313. Make Max | cmdgbb_fan | TL | 0ms | 0kb | C++17 | 784b | 2024-09-18 17:35:32 | 2024-09-18 17:35:34 |
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);
}
}
Details
Tip: Click on the bar to expand more detailed information
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 ...