QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#585766 | #9313. Make Max | WeCun | WA | 0ms | 3568kb | C++14 | 753b | 2024-09-23 22:06:16 | 2024-09-23 22:06:22 |
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3568kb
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'