QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#575285 | #9313. Make Max | DUSK777 | WA | 0ms | 3872kb | C++14 | 1.4kb | 2024-09-19 11:50:55 | 2024-09-19 11:50:56 |
Judging History
answer
//
// Created by 夕 on 2024/9/16.
//
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void solu(){
ll n;
cin >> n;
vector <ll> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector <ll> rIndex(n,-1);
vector <ll> lIndex(n,-1);
stack <pair <ll,ll>> s; //单调栈
for (ll i = 0; i < n; ++i) {
while (!s.empty() && s.top().second <= a[i]) {
ll idx = s.top().first;
rIndex[idx] = i;
s.pop();
}
s.emplace(i, a[i]);
}
while (!s.empty()) s.pop();
for (ll i = n - 1; i >= 0; --i) {
while (!s.empty() && s.top().second <= a[i]) {
ll idx = s.top().first;
lIndex[idx] = i;
s.pop();
}
s.emplace(i, a[i]);
}
ll ans = 0;
for (int i = 0; i < n; ++i) {
if (lIndex[i] != -1){
ans += (i - 1 - lIndex[i]);
}
else {
if (a[0] != a[i]){
ans += i;
}
}
if (rIndex[i] != -1){
ans += (rIndex[i] - i - 1);
}
else {
if (a[n-1] != a[i]){
ans += (n - i - 1);
}
}
}
cout<<ans<<endl;
for (int i = 0; i < n; ++i) {
cout<<i<<" "<<lIndex[i]<<" "<<rIndex[i]<<endl;
}
}
int main(){
ll q;
cin >> q;
while (q--){
solu();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3872kb
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3
output:
1 0 -1 1 1 -1 -1 0 0 -1 1 1 0 -1 3 0 -1 1 1 0 2 2 1 3 3 -1 4 4 3 5 5 4 6 6 5 -1 3 0 -1 1 1 -1 2 2 -1 -1
result:
wrong answer 3rd numbers differ - expected: '3', found: '-1'