QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#594185 | #9313. Make Max | Light_Pursuer | TL | 0ms | 0kb | C++14 | 1.3kb | 2024-09-27 20:03:05 | 2024-09-27 20:03:07 |
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 5, inf = 2e9;
int n, a[N], ans, cnt, all;
struct node {
int x, cnt;
};
void ipt () {
scanf ("%d", &n);
for (int i = 1; i <= n; i++) {
scanf ("%d", &a[i]);
}
a[n + 1] = inf;
}
void solve () {
stack <node> s;
ans = 0;
for (int i = 1; i <= n + 1; i++) {
if (s.empty () || a[i] < s.top().x) {
node pu = {a[i], 1};
s.push (pu);
} else if (a[i] == s.top().x) {
node p = s.top();
s.pop();
p.cnt ++;
s.push (p);
} else {
int XD = 0, cnt = 0;
while (!s.empty () && a[i] > s.top ().x) {
XD += s.top ().cnt;
cnt += XD;
s.pop();
}
if (s.empty () || a[i] < s.top ().x) {
node p = {a[i], XD + 1};
s.push (p);
} else if (a[i] == s.top ().x) {
node p = s.top ();
p.cnt += (XD + 1);
s.pop ();
s.push (p);
}
ans += cnt;
}
}
printf ("%d\n", ans - n);
}
signed main () {
int T; scanf ("%d", &T);
while (T--) {
ipt ();
solve ();
}
return 0;
}
詳細信息
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 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ...