QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#573589#9313. Make MaxAnndy_bonusRE 0ms0kbC++201001b2024-09-18 19:20:312024-09-18 19:20:32

Judging History

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

  • [2024-09-18 19:20:32]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-09-18 19:20:31]
  • 提交

answer

#include <bits/stdc++.h>

using LL = long long;
constexpr int N = 2e5 + 10;

int stk[N], top = -1;

void solve() {
    int n;
    std::cin >> n;
    std::vector<int> a(n + 2);
    for (int i = 1; i <= n; i++) {
        std::cin >> a[i];
    }
    LL ans = 0;
    top = -1;
    stk[++top] = 0;
    for (int i = 1; i <= n; i++) {
        while (top != 0 && a[stk[top]] < a[i]) {
            top--;
        }
        ans += 1LL * i - stk[top] - 1;
        stk[++top] = i;
    }
    top = -1;
    stk[++top] = n + 1;
    for (int i = n; i >= 1; i--) {
        while (top != 0 && a[stk[top]] < a[i]) {
            top--;
        }
        ans += 1LL * stk[top] - i - 1;
        stk[++top] = i;
    }
    std::cout << ans << '\n';
}

int main() {
    freopen("ans.in", "r", stdin);
    freopen("ans.out", "w", stdout);
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
    int T;
    std::cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

詳細信息

Test #1:

score: 0
Dangerous Syscalls

input:

4
2
1 2
2
2 2
7
1 1 1 2 2 2 2
3
1 2 3

output:


result: