QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#584654#9313. Make MaxwlhWA 29ms7828kbC++171.7kb2024-09-23 16:03:362024-09-23 16:03:36

Judging History

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

  • [2024-09-23 16:03:36]
  • 评测
  • 测评结果:WA
  • 用时:29ms
  • 内存:7828kb
  • [2024-09-23 16:03:36]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define ios ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

#define int long long
typedef pair<int,int> pr;
#define pb(x) push_back(x)
#define all(a) a.begin(),a.end()
#define fi first
#define se second

const int N = 1e6+10;
string YES="YES",Yes="Yes",yes="yes",NO="NO",No="No",no="no";
const int mod=998244353,inf=1e15;
int dx[]={0,0,-1,0,1},dy[]={0,-1,0,1,0};

void solve()
{
    int n; 
    cin >> n;
    vector<int>a(n + 5, 0), mxr(n + 5, 0), sumr(n + 5, 0);
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
    }
    stack<pr>st;
    // st.push({inf, n + 1});
    // for(int i = n; i >= 1; i --){
    //     while(st.size() && st.top().fi <= a[i]){
    //         st.pop();
    //     }
    //     mxr[i] = st.top().se;
    //     st.push({a[i], i});
    // }
    st.push({inf, n + 1});
    for(int i = n; i >= 1; i --){
        while(st.size() && st.top().fi < a[i]){
            st.pop();
        }
        sumr[i] = st.top().se;
        st.push({a[i], i});
    }
    // for(int i = 1; i <= n; i ++) cout << sumr[i] << ' '; cout << endl;

    int ans = 0;
    auto dfs = [&](auto&& dfs, int L, int l, int r) -> void{
        if(l == r) return ;
        int mid = sumr[l];
        if(mid <= r){
            dfs(dfs, L, l, mid - 1);
            if(a[mid] > a[l]){
                ans += (mid - L);
            }
            dfs(dfs, L, mid, r);
        }
        else{
            dfs(dfs, L + 1, l + 1, r);
            ans += (r - l);
        }
    };
    dfs(dfs, 1, 1, n);
    cout << ans << endl;
}

signed main()
{
    ios;
    int t=1;
    cin>>t;
    while(t--) solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3532kb

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

result:

ok 4 number(s): "1 0 3 3"

Test #2:

score: -100
Wrong Answer
time: 29ms
memory: 7828kb

input:

2
198018
875421126 585870339 471894633 383529988 625397685 944061047 704695631 105113224 459022561 760848605 980735314 847376362 980571959 329939331 644635272 326439858 752879510 837384394 175179068 182094523 397239381 1199016 185143405 279638454 252374970 822030887 860312140 137248166 993229443 164...

output:

9824753958
9100671112

result:

wrong answer 1st numbers differ - expected: '4084978', found: '9824753958'