QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#140224 | #5500. Bars | PhantomThreshold# | WA | 277ms | 5828kb | C++20 | 1.0kb | 2023-08-15 15:21:43 | 2023-08-15 15:21:45 |
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;
}
if( i+1<=n && ai[i].first==ai[i+1].first && ai[i+1].second<=r && ai[i+1].second>=l )
{
if( pi[l]<pi[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;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5428kb
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: 277ms
memory: 5828kb
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'