QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#30634 | #975. Game | RivenOmega# | WA | 139ms | 16892kb | C++14 | 1.0kb | 2022-04-30 17:51:41 | 2022-04-30 17:51:41 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+5,Mod=998244353,iM=(Mod+1)>>1;
typedef long long ll;
ll a[N],pre[N],suf[N];
inline int po(int x, int y)
{
int r=1;
for(;y;y>>=1,x=1ll*x*x%Mod) if(y&1) r=1ll*r*x%Mod;
return r;
}
set<pair<int,ll>> s;
priority_queue<pair<ll,int>> q;
int main()
{
int n; scanf("%d",&n);
for(int i=1;i<=n;++i) scanf("%lld",&a[i]);
int ans=(a[1]+a[n])%Mod;
s.insert(make_pair(1,a[1]));
s.insert(make_pair(n,a[n]));
for(int i=2;i<n;++i) q.push(make_pair(a[i],i));
while(!q.empty())
{
ll w=q.top().first;
int i=q.top().second;
q.pop();
auto itr=s.lower_bound(make_pair(i,0)),itl=itr; --itl;
ll w2=itr->second+itl->second;
if(w2 + itl->second*(itr->first-i-1) + itr->second*(i-itl->first-1) > 2ll*w + w*(itr->first-i-1) + w*(i-itl->first-1))
ans=(ans+w2%Mod*iM)%Mod;
else ans=(ans+w)%Mod,s.insert(make_pair(i,w));
}
printf("%d\n",1ll*ans*po(n,Mod-2)%Mod);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 5808kb
input:
3 3 1 2
output:
499122179
result:
ok "499122179"
Test #2:
score: 0
Accepted
time: 3ms
memory: 5808kb
input:
6 6 1 2 5 3 4
output:
582309211
result:
ok "582309211"
Test #3:
score: -100
Wrong Answer
time: 139ms
memory: 16892kb
input:
500000 131592496991 614154464278 882215024371 954828734583 997777248498 677111110098 927405745589 218490006270 743425189504 391435077446 972647376673 630405853326 714899101544 90679613430 530369364312 763893201576 838136940841 261795310871 187042095193 941416320169 688136558810 554872601435 54089147...
output:
40996619
result:
wrong answer 1st words differ - expected: '131032905', found: '40996619'