QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#578280#9313. Make MaxfyCompile Error//C++14891b2024-09-20 17:57:402024-09-20 17:57:41

Judging History

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

  • [2024-09-20 17:57:41]
  • 评测
  • [2024-09-20 17:57:40]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 999;
int stk[N], l[N], r[N], top;
int a[N];
void solve()
{
    int n;cin>>n;
    for(int i = 1; i <= n; i ++)cin>>a[i];
    
    stk[top = 0] = 0;
    for(int i = 1; i <= n; i ++)
    {
        while(top && a[stk[top]] < a[i])top --;
        l[i] = stk[top] + 1;
        stk[++ top] = i;
    }
    
    stk[top = 0] = n + 1;
    a[n + 1] = 0;
    for(int i = n; i >= 1; i --)
    {
        while(top && a[stk[top]] < a[i])top --;
        r[i] = stk[top] - 1;
        if(a[i] == a[r[i] + 1])r[i] = i;
        stk[++ top] = i;
    }
    
    int res = 0;
    for(int i = 1; i <= n; i ++)res += r[i] - l[i];
    cout<<res<<endl;
}

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;cin>>t;
    while(t --)
        solve();
    return 0;
}

详细

cc1plus: error: ‘::main’ must return ‘int’