1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
using namespace std; namespace Debug{ Tp I void _debug(Cn char* f,Ty t){cerr<<f<<'='<<t<<endl;} Ts I void _debug(Cn char* f,Ty x,Ar... y){W(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);} Tp ostream& operator<<(ostream& os,Cn vector<Ty>& V){os<<"[";for(Cn auto& vv:V) os<<vv<<",";os<<"]";return os;} }using namespace Debug; namespace FastIO{ int OT;char oc,FI[FS],FO[FS],OS[FS],*FA=FI,*FB=FI,*FC=FO,*FE=FO+FS; I void clear() {fwrite(FO,1,FC-FO,stdout),FC=FO;} Tp I void read(Ty& x) {x=0;W(!isdigit(oc=tc()));W(x=(x<<3)+(x<<1)+(oc&15),isdigit(oc=tc()));} Ts I void read(Ty& x,Ar&... y) {read(x),read(y...);} Tp I void writeln(Ty x) {W(OS[++OT]=x%10+48,x/=10);W(OT) pc(OS[OT--]);pc('\n');} }using namespace FastIO; Cn int N=4e5+10,p=998244353,Inv2=(p+1)/2; int n,S,bl[N],fac[N],ifac[N],l,r,cnt;LL ans[N],Ans; struct node{int l,r,id;}q[N]; struct Que{int l,r,x,id;}Q[N]; I int C(CI n,CI m){return 1LL*fac[n]*ifac[m]%p*ifac[n-m]%p;} I int QP(RI a,RI b){RI s=1;W(b) b&1&&(s=1LL*s*a%p),a=1LL*a*a%p,b>>=1;return s;} I bool cmp(Cn node& x,Cn node& y){return bl[x.l]^bl[y.l]?x.l<y.l:bl[x.l]&1?x.r<y.r:x.r>y.r;} I void add(LL& x,CI y){(x+=y)>=p&&(x-=p);} int main(){ RI i;for(read(n),i=1;i<=n;i++) read(Q[i].l,Q[i].r,Q[i].x),q[++cnt]=(node){Q[i].x,Q[i].r,i},q[++cnt]=(node){Q[i].x,Q[i].l-1,-i}; for(S=sqrt(cnt),i=1;i<=cnt;i++) bl[i]=(i-1)/S+1;for(fac[0]=1,i=1;i<N;i++) fac[i]=1LL*fac[i-1]*i%p;for(ifac[N-1]=QP(fac[N-1],p-2),i=N-2;~i;i--) ifac[i]=1LL*ifac[i+1]*(i+1)%p; for(sort(q+1,q+cnt+1,cmp),Ans=l=1,r=0,i=1;i<=cnt;i++){ W(l<q[i].l) Ans=(2LL*Ans%p-C(l,r)+p)%p,l++;W(r>q[i].r) add(Ans,p-C(l,r)),r--; W(l>q[i].l) Ans=(1LL*Inv2*(Ans+C(l-1,r))%p)%p,l--;W(r<q[i].r) add(Ans,C(l,r+1)),r++; add(ans[abs(q[i].id)],q[i].id<0?p-Ans:Ans); }for(i=1;i<=n;i++) writeln((ans[i]+p)%p);return cerr<<clock()<<'\n',clear(),0; }
|