QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#585771 | #9313. Make Max | WeCun | WA | 0ms | 3460kb | C++20 | 753b | 2024-09-23 22:07:10 | 2024-09-23 22:07:11 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve()
{
int n;
cin >> n;
vector<int> a(n + 1);
for(int i = 1; i <= n; i++) cin >> a[i];
vector<int> stk(n + 2), l(n + 2), r(n + 2);
int top = 0;
stk[top] = 0;
for(int i = 1; i <= n; i++)
{
while(top && a[i] > stk[top]) top--;
l[i] = stk[top] + 1;
stk[++top] = i;
}
top = 0;
stk[top] = n + 1;
for(int i = n; i >= 1; i--)
{
while(top && a[i] > stk[top]) top--;
r[i] = stk[top] - 1;
if(a[stk[top]] == a[i]) r[i] = i;
stk[++top] = i;
}
ll ans = 0;
for(int i = 1; i <= n; i++) ans += r[i] - l[i];
cout << ans << endl;
}
int main()
{
int t;
cin >> t;
while(t--)
{
solve();
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3460kb
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3
output:
1 1 0 3
result:
wrong answer 2nd numbers differ - expected: '0', found: '1'