QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#594185#9313. Make MaxLight_PursuerTL 0ms0kbC++141.3kb2024-09-27 20:03:052024-09-27 20:03:07

Judging History

你现在查看的是最新测评结果

  • [2024-09-27 20:03:07]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-09-27 20:03:05]
  • 提交

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
...

result: