QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#573171#9313. Make Maxcmdgbb_fanTL 0ms0kbC++17784b2024-09-18 17:35:322024-09-18 17:35:34

Judging History

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

  • [2024-09-18 17:35:34]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-09-18 17:35:32]
  • 提交

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

result: