QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#578959 | #9313. Make Max | skrt_real | WA | 59ms | 9976kb | C++20 | 1.3kb | 2024-09-20 23:49:28 | 2024-09-20 23:49:29 |
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[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: 100
Accepted
time: 0ms
memory: 3780kb
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3
output:
1 0 3 3
result:
ok 4 number(s): "1 0 3 3"
Test #2:
score: -100
Wrong Answer
time: 59ms
memory: 9976kb
input:
2 198018 875421126 585870339 471894633 383529988 625397685 944061047 704695631 105113224 459022561 760848605 980735314 847376362 980571959 329939331 644635272 326439858 752879510 837384394 175179068 182094523 397239381 1199016 185143405 279638454 252374970 822030887 860312140 137248166 993229443 164...
output:
340430 647181
result:
wrong answer 1st numbers differ - expected: '4084978', found: '340430'