QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#575673#9313. Make MaxWulongQAQWA 0ms7716kbC++141.3kb2024-09-19 16:12:442024-09-19 16:12:46

Judging History

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

  • [2024-09-19 16:12:46]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:7716kb
  • [2024-09-19 16:12:44]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
// typedef long long ll;
#define endl '\n'
#define int long long
#define lowbit(x) ((x) & (-x))
const int N = 1e6 + 7, M = 207, inf = 0x3f3f3f3f, mod = 1e9 + 7;
int l[N], r[N], st[N], a[N];

void solve()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    int id = 0;
    for (int i = 1; i <= n; i++)
    {
        while (id && a[i] > a[st[id]])
            id--;
        l[i] = st[id] + 1;
        st[++id] = i;
    }
    id = 0;
    st[id] = n + 1;
    for (int i = n; i >= 1; i--)
    {
        while (id && a[i] > a[st[id]])
            id--;
        r[i] = st[id] - 1;
        if (a[i] == a[st[id]])
            r[i] = i;
        st[++id] = i;
    }
    // for (int i = 1; i <= n; i++)
    //     cout << l[i] << " ";
    // cout << endl;
    // for (int i = 1; i <= n; i++)
    //     cout << r[i] << " ";
    // cout << endl;
    int ans = 0;
    for (int i = 1; i <= n; i++)
        ans = ans + (r[i] - l[i]);
    cout << ans << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T = 1;
    cin >> T;
    while (T--)
    {
        solve();
    }
    // cout << fixed << setprecision(10) << c << endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 7716kb

input:

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

output:

1
-3
-3
-21

result:

wrong answer 2nd numbers differ - expected: '0', found: '-3'