QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#577945 | #9313. Make Max | fufufuf | RE | 0ms | 0kb | C++14 | 752b | 2024-09-20 15:36:37 | 2024-09-20 15:36:37 |
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn = (ll)2e5 + 7;
//求出左边第一个比他大的元素和右边第一个比他大的元素
ll a[maxn];
ll n;
void sol() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
ll ans = 0;
stack<ll> s1;
for (int i = 1; i <= n; i++) {
while (!s1.empty() && a[s1.top()] < a[i]) {
s1.pop();
}
ans += (i - s1.top() - 1);
s1.push(i);
}
stack<ll>s2;
for (int i = n; i >= 1; i--) {
while (!s2.empty() && a[s2.top()] < a[i]) {
s2.pop();
}
if (a[s2.top()] != a[i]) {
ans += (s2.top() - i - 1);
}
s2.push(i);
}
cout << ans << endl;
}
ll T;
int main() {
cin >> T;
while (T--) {
sol();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3