QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#572863#9313. Make MaxtantianWA 1ms3604kbC++14827b2024-09-18 16:36:592024-09-18 16:37:06

Judging History

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

  • [2024-09-18 16:37:06]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3604kb
  • [2024-09-18 16:36:59]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int FieldSum(vector<int> &v)
{
    v.push_back(INT_MAX);
    stack<int> st;
    int sum = 0;
    for (int i = 0; i < (int)v.size(); i++)
    {
        if (st.empty() || v[st.top()] > v[i])
        {
            st.push(i);
        }
        else
        {
            while (!st.empty() && v[st.top()] <= v[i])
            {
                int top = st.top();
                st.pop();
                sum += (i - top - 1);
            }
            st.push(i);
        }
    }
    return sum;
}
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        vector<int> v(n + 1);
        for (int i = 0; i < n; i++)
            cin >> v[i];
        cout << FieldSum(v) << endl;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3604kb

input:

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

output:

1
1
1
1

result:

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