QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#578958 | #9313. Make Max | skrt_real | WA | 1ms | 5876kb | C++20 | 1.3kb | 2024-09-20 23:48:07 | 2024-09-20 23:48:07 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
const ll M=0x7fffffff;
inline ll read(){
char c=getchar();ll _x=0, f=1;
for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=getchar()) _x=_x*10+c-'0';
return _x*f;
}
ll t, n, m, head, ed_ans;
ll find_fir[N], lef_fir[N];
struct node{
ll num, fir_ip, ans;
}a[N];
bool cmp(node x, node y){
return x.num>y.num;
}
int main(){
t=read();
while( t-- ){
ed_ans=0;
n=read();
for(int i=1;i<=n;i++) a[i].num=read();
for(int i=n;i>=1;i--){
while( head && a[ find_fir[head] ].num <= a[i].num ) head--;
a[i].fir_ip = find_fir[head];
find_fir[ ++head ] = i;
}
head=0;
for(int i=1;i<=n;i++){
while( head && a[ find_fir[head] ].num <= a[i].num ) head--;
lef_fir[i] = find_fir[head];
find_fir[ ++head ] = i;
}
for(int i=1;i<=n;i++)
if( !a[i].fir_ip ) a[i].fir_ip = lef_fir[i];
else if( a[ a[i].fir_ip ].num < a[ lef_fir[i] ].num && lef_fir[i] ) a[i].fir_ip = lef_fir[i];
sort(a+1, a+n+1, cmp);
for(int i=2;i<=n;i++){
if( a[i].num==a[i-1].num ) continue;
a[i].ans = a[ a[i].fir_ip ].ans+1;
ed_ans+=a[i].ans;
}
printf("%lld\n", ed_ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5876kb
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3
output:
1 0 1 3
result:
wrong answer 3rd numbers differ - expected: '3', found: '1'