QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#140213 | #5500. Bars | PhantomThreshold# | WA | 263ms | 5832kb | C++20 | 882b | 2023-08-15 14:51:12 | 2023-08-15 14:51:15 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define int long long
using namespace std;
const int maxn = 500050;
ll ans;
int n;
int pi[maxn];
pair<int,int>ai[maxn];
void go(int l,int r,int i)
{
if(i>n || ( pi[l]>=ai[i].first && pi[r]>=ai[i].first ) ) return;
int pos= ai[i].second;
if(pos<=l||pos>=r)
{
go(l,r,i+1);
return;
}
ll temp= 1ll*(pos-l)*(ai[i].first-pi[r])+ 1ll*(r-pos)*(ai[i].first-pi[l]);
if(temp<=0) go(l,r,i+1);
else
{
ans+=temp;
go(l,pos,i+1);
go(pos,r,i+1);
}
}
signed main()
{
ios_base::sync_with_stdio(false);
int Tcase; cin>>Tcase;
while(Tcase--)
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>pi[i];
ai[i]=make_pair(pi[i],i);
}
sort(ai+1,ai+n+1,greater< pair<int,int> >());
ans=1ll*(n-1)*(pi[1]+pi[n]);
go(1,n,1);
cout<<ans<<endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5584kb
input:
2 4 5 2 2 6 5 1 5 4 4 1
output:
33 29
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 263ms
memory: 5832kb
input:
10000 4 5 2 2 6 5 1 5 4 4 1 197 763787596 15221694 898228999 187472305 466351873 822742732 437754202 800092772 843092246 915675776 166265020 346340615 796714085 497548541 182089610 64356048 363276768 181268733 257949015 236568898 752096761 928725929 443146784 114577469 833053207 38120723 14891030 41...
output:
33 29 381268324603 661441328080 546841323654 458946673513 296420749955 874819701323 632716482449 584888108745 225238172734 716027782821 466644027129 283438270642 585094154153 201537244906 336548832140 483213442818 604125593314 586771956643 408018096564 826785029425 975377092201 923726716973 26408806...
result:
wrong answer 3rd lines differ - expected: '382465638565', found: '381268324603'