大概率是爆long long了
求调QAQ
#include <bits/stdc++.h>
#define maxn 1000010
#define mod 998244353
#define int long long
using namespace std;
int n,q,maxr;
struct node{
long long s;int val,x;//方差 val 有几个l[i]没被消
}t[maxn];
int all;
struct sp{
int l,r;
bool operator <(sp a) const{
return l<a.l;
}
}lr[maxn];
inline int power(int a,int b)
{
int sum;
for(sum=1;b;b>>=1,a=(int)a*a%mod)if(b&1)
sum=(int)sum*a%mod;
return sum;
}
int tonl[maxn],tonr[maxn];
int check(int x){
int l = 0,r = maxr;
int ans = 0;
while(l<=r){
int mid = (l+r)>>1;
if(t[mid].val<=x){
l = mid+1;
ans = mid;
} else {
r = mid-1;
}
}
return ans;
}
long long sv;
signed main(){
scanf("%lld%lld",&n,&q);
for(int i = 1;i<=n;i++){
scanf("%lld%lld",&lr[i].l,&lr[i].r);tonl[lr[i].l]++,tonr[lr[i].r]++,maxr = max(lr[i].r,maxr);
all+=lr[i].l;
sv = (sv%mod+(lr[i].l*lr[i].l)%mod+mod)%mod;
}
sort(lr+1,lr+1+n);
int now = 0;
for(int i = 1;i<=1000002;i++){
t[i].s = (t[i-1].s%mod+(t[i-1].x*(2*i-1))%mod+mod)%mod;
t[i].val = t[i-1].val+now;
if(tonl[i]>=1) now+=tonl[i];
if(tonr[i]>=1) now-=tonr[i];
t[i].x = now;
}
// for(int i = 1;i<=5;i++) cout<<i<<" "<<t[i].val<<" "<<t[i].s<<endl;
// cout<<endl;
// cout<<check(t[1].val);
while(q--){
int fir;
int x;scanf("%lld",&x);fir = x;
x-=all;
int locat = check(x);
// int locat = upper_bound(tmp+1,tmp+len+1,x)-tmp-1;
int vat = x-t[locat].val;
// cout<<x<<" "<<locat<<" "<<vat<<" "<<t[locat].s<<" ";
long long a = (((((sv+t[locat].s)%mod+vat*(2*locat+1)%mod+mod)%mod)*n)%mod-(fir*fir)%mod+mod)%mod;
a%=mod;
// cout<<a;
printf("%lld\n",a*power(n*n%mod,mod-2)%mod);
}
return 0;
}