QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#30613 | #975. Game | wh_ZH# | WA | 160ms | 11620kb | C++ | 961b | 2022-04-30 14:10:36 | 2022-04-30 14:10:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N=500005,Mod=998244353;
#define ll long long
struct Node{
int x;
ll y;
}a[N];
int s[N],top;
ll cross(Node a,Node b,Node c){
ll x=b.x-a.x,xx=c.x-a.x;
ll y=b.y-a.y,yy=c.y-a.y;
return 1ll*y*xx-1ll*x*yy;
}
inline int qpow(int a,int b){
int ans=1;
while (b){
if (b&1) ans=1ll*ans*a%Mod;
a=1ll*a*a%Mod,b>>=1;
}
return ans;
}
int main() {
int n;scanf ("%d",&n);
for (int i=1;i<=n;i++){
a[i].x=i;
scanf ("%lld",&a[i].y);
}
s[top=1]=1;
for (int i=2;i<=n;i++){
while (top>1&&cross(a[s[top-1]],a[s[top]],a[i])<=0) top--;
s[++top]=i;
}
int ans=0,lst=1;
for (int i=1;i<=n;i++){
while (lst<=top&&a[s[lst]].x<i) lst++;
if (a[s[lst]].x==i) ans+=a[i].y;
else ans+=1ll*(1ll*(a[s[lst]].x-i)*a[s[lst-1]].y+1ll*(i-a[s[lst-1]].x)*a[s[lst]].y)%Mod*qpow(a[s[lst]].x-a[s[lst-1]].x,Mod-2)%Mod;
}
printf ("%d",1ll*ans*qpow(n,Mod-2)%Mod);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 5ms
memory: 5760kb
input:
3 3 1 2
output:
499122179
result:
ok "499122179"
Test #2:
score: 0
Accepted
time: 0ms
memory: 5824kb
input:
6 6 1 2 5 3 4
output:
582309211
result:
ok "582309211"
Test #3:
score: -100
Wrong Answer
time: 160ms
memory: 11620kb
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:
-766661968
result:
wrong answer 1st words differ - expected: '131032905', found: '-766661968'