QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#573171#9313. Make Maxcmdgbb_fanTL 0ms0kbC++17784b2024-09-18 17:35:322024-09-18 17:35:34

Judging History

This is the latest submission verdict.

  • [2024-09-18 17:35:34]
  • Judged
  • Verdict: TL
  • Time: 0ms
  • Memory: 0kb
  • [2024-09-18 17:35:32]
  • Submitted

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

result: