QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#578399 | #9313. Make Max | goliter | WA | 1ms | 7984kb | C++14 | 709b | 2024-09-20 18:53:51 | 2024-09-20 18:53:51 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=4e5+5;
int n,a[N],l[N],r[N],stk[N];
int main(){
int t;
cin>>t;
while(t--){
ll ans=0;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
}
int top=0;
for(int i=1;i<=n;i++){
while(top&&a[i]>a[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]>a[stk[top]]){
top--;
}
r[i]=stk[top]-1;
// if(a[r[i]+1]==a[i]){
// r[i]=i;
// }
stk[++top]=i;
}
for(int i=1;i<=n;i++){
cout<<l[i]<<" "<<r[i]<<endl;
ans+=r[i]-l[i];
}
printf("%lld\n",ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 7984kb
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3
output:
1 1 1 2 1 4 1 2 2 -3 4 1 2 2 3 3 4 4 5 5 6 6 7 7 -3 9 1 9 2 9 3 -21
result:
wrong answer 2nd numbers differ - expected: '0', found: '1'