link
solve
我们很容易可以发现,有两种情况,一种是沿着 (x) 折的,一种是沿着 (y) 折的,然后先用垂直关系判断一下是那种方式,最后统计就好了
code
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL TT=998244353;
LL n,v;
LL ans;
struct node{
LL x,y;
}a[1000005];
bool cmp1(node A,node B){
return A.x<B.x||(A.x==B.x&&A.y>B.y);
}
bool cmp2(node A,node B){
return A.y<B.y||(A.y==B.y&&A.x<B.x);
}
struct IO{
static const int S=1<<21;
char buf[S],*p1,*p2;int st[105],Top;
~IO(){clear();}
inline void clear(){fwrite(buf,1,Top,stdout);Top=0;}
inline void pc(const char c){Top==S&&(clear(),0);buf[Top++]=c;}
inline char gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
inline IO&operator >> (char&x){while(x=gc(),x==' '||x=='
'||x=='r');return *this;}
template<typename T>inline IO&operator >> (T&x){
x=0;bool f=0;char ch=gc();
while(ch<'0'||ch>'9'){if(ch=='-') f^=1;ch=gc();}
while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=gc();
f?x=-x:0;return *this;
}
inline IO&operator << (const char c){pc(c);return *this;}
template<typename T>inline IO&operator << (T x){
if(x<0) pc('-'),x=-x;
do{st[++st[0]]=x%10,x/=10;}while(x);
while(st[0]) pc('0'+st[st[0]--]);return *this;
}
}fin,fout;
LL dist(node A,node B){
return ((A.x-B.x)*(A.x-B.x)%TT+(A.y-B.y)*(A.y-B.y)%TT)%TT;
}
LL Pow(LL a,LL b){
LL s=1,w=a;
while(b){
if(b&1)s=s*w%TT;
w=w*w%TT;
b>>=1;
}
return s;
}
int main(){
freopen("b.in","r",stdin);
freopen("b.out","w",stdout);
fin>>n>>v;n++;
for(int i=1;i<=n;i++)fin>>a[i].x>>a[i].y;
sort(a+1,a+1+n,cmp1);
int flg=0;
for(int i=2;i<n;i++){
if((a[i].x-a[i-1].x)*(a[i+1].x-a[i].x)+(a[i].y-a[i-1].y)*(a[i+1].y-a[i].y)){flg=1;break;}
}
if(!flg){
for(int i=1;i<n;i++){
ans=(ans+dist(a[i],a[i+1]))%TT;
}
}
else {
sort(a+1,a+1+n,cmp2);
for(int i=1;i<n;i++){
ans=(ans+dist(a[i],a[i+1]))%TT;
}
}
LL Inv=Pow(v%TT,TT-2);
ans=(ans*Inv%TT)*Inv%TT;
fout<<ans<<'
';
return 0;
}