QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#563882 | #5121. Square Grid | XY_Eleven | TL | 33ms | 64324kb | C++23 | 5.8kb | 2024-09-14 16:41:25 | 2024-09-14 16:41:26 |
Judging History
answer
#include <bits/stdc++.h>
// #include <windows.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
//#pragma GCC optimize(3)
#define DB double
#define LL long long
#define ULL unsigned long long
#define in128 __int128
#define cint const int
#define cLL const LL
#define For(z,e1,e2) for(int z=(e1);z<=(e2);z++)
#define Rof(z,e1,e2) for(int z=(e2);z>=(e1);z--)
#define For_(z,e1,e2) for(int z=(e1);z<(e2);z++)
#define Rof_(z,e1,e2) for(int z=(e2);z>(e1);z--)
#define inint(e) scanf("%d",&e)
#define inll(e) scanf("%lld",&e)
#define inpr(e1,e2) scanf("%d%d",&e1,&e2)
#define in3(e1,e2,e3) scanf("%d%d%d",&e1,&e2,&e3)
#define outint(e) printf("%d\n",e)
#define outint_(e) printf("%d%c",e," \n"[i==n])
#define outint2_(e,e1,e2) printf("%d%c",e," \n"[(e1)==(e2)])
#define outll(e) printf("%lld\n",e)
#define outll_(e) printf("%lld%c",e," \n"[i==n])
#define outll2_(e,e1,e2) printf("%lld%c",e," \n"[(e1)==(e2)])
#define exc(e) if(e) continue
#define stop(e) if(e) break
#define ret(e) if(e) return
#define ll(e) (1ll*(e))
#define pb push_back
#define ft first
#define sc second
#define pii pair<int,int>
#define pli pair<LL,int>
#define vct vector
#define clean(e) while(!e.empty()) e.pop()
#define all(ev) ev.begin(),ev.end()
#define sz(ev) ((int)ev.size())
#define debug(x) printf("%s=%d\n",#x,x)
#define x0 __xx00__
#define y1 __yy11__
#define ffo fflush(stdout)
cLL mod=998244353,G=404;
// cLL mod[2]={1686688681ll,1888686661ll},base[2]={166686661ll,188868881ll};
template <typename Type> void get_min(Type &w1,const Type w2) { if(w2<w1) w1=w2; } template <typename Type> void get_max(Type &w1,const Type w2) { if(w2>w1) w1=w2; }
template <typename Type> Type up_div(Type w1,Type w2) { return (w1/w2+(w1%w2?1:0)); }
template <typename Type> Type gcd(Type X_,Type Y_) { Type R_=X_%Y_; while(R_) { X_=Y_; Y_=R_; R_=X_%Y_; } return Y_; } template <typename Type> Type lcm(Type X_,Type Y_) { return (X_/gcd(X_,Y_)*Y_); }
template <typename Type> Type md(Type w1,const Type w2=mod) { w1%=w2; if(w1<0) w1+=w2; return w1; } template <typename Type> Type md_(Type w1,const Type w2=mod) { w1%=w2; if(w1<=0) w1+=w2; return w1; }
void ex_gcd(LL &X_,LL &Y_,LL A_,LL B_) { if(!B_) { X_=1ll; Y_=0ll; return ; } ex_gcd(Y_,X_,B_,A_%B_); X_=md(X_,B_); Y_=(1ll-X_*A_)/B_; } LL inv(LL A_,LL B_=mod) { LL X_=0ll,Y_=0ll; ex_gcd(X_,Y_,A_,B_); return X_; }
template <typename Type> void add(Type &w1,const Type w2,const Type M_=mod) { w1=md(w1+w2,M_); } void mul(LL &w1,cLL w2,cLL M_=mod) { w1=md(w1*md(w2,M_),M_); } template <typename Type> Type pw(Type X_,Type Y_,Type M_=mod) { Type S_=1; while(Y_) { if(Y_&1) mul(S_,X_,M_); Y_>>=1; mul(X_,X_,M_); } return S_; }
template <typename Type> Type bk(vector <Type> &V_) { auto T_=V_.back(); V_.pop_back(); return T_; } template <typename Type> Type tp(stack <Type> &V_) { auto T_=V_.top(); V_.pop(); return T_; } template <typename Type> Type frt(queue <Type> &V_) { auto T_=V_.front(); V_.pop(); return T_; }
template <typename Type> Type bg(set <Type> &V_) { auto T_=*V_.begin(); V_.erase(V_.begin()); return T_; } template <typename Type> Type bk(set <Type> &V_) { auto T_=*prev(V_.end()); V_.erase(*prev(V_.end())); return T_; }
mt19937 gen(time(NULL)); int rd() { return abs((int)gen()); }
int rnd(int l,int r) { return rd()%(r-l+1)+l; }
mt19937_64 genll(time(NULL));
cint D=20,L=1<<D|11;
LL z[D+1][L];
int rev[L];
int minsz(int w)
{
return (__lg(w)+(w!=(w&-w)));
}
struct Poly
{
vct <LL> v;
void NTT(bool opt)
{
int d=minsz(sz(v)),l=1<<d;
v.resize(l);
For_(i,1,l)
{
rev[i]=(rev[i>>1]>>1)|((i&1)<<d-1);
if(i<rev[i]) swap(v[i],v[rev[i]]);
}
For_(k,0,d)
{
for(int i=0;i<l;i+=(1<<k+1)) For_(j,i,i|(1<<k))
{
int j2=(j|(1<<k)); LL t=v[j2]*z[k+1][(i^j)]%mod;
v[j2]=v[j]-t; v[j]+=t;
}
if(k==11) for(auto &i:v) i=md(i);
}
for(auto &i:v) i=md(i);
ret(!opt);
LL t=inv(1ll*l); for(auto &i:v) mul(i,t);
reverse(v.begin()+1,v.end());
}
void operator *= (Poly A)
{
int len=sz(v)+sz(A.v)-1,d=minsz(len),l=1<<d;
v.resize(l),A.v.resize(l);
NTT(false),A.NTT(false);
For_(i,0,l) mul(v[i],A.v[i]);
NTT(true);
v.resize(len);
}
};
void main_init()
{
For(i,0,D)
{
LL t=pw(G,(mod-1ll)>>i),s=1ll;
For_(j,0,1<<i) z[i][j]=s,mul(s,t);
}
}
cint N=1.02e5;
int n,m,m2,Q;
LL d[N<<2];
void get(Poly &w,int len)
{
int len2=sz(w.v);
For_(i,len,len2) add(w.v[i-len],w.v[i]);
w.v.resize(len);
}
void init(int &w)
{
Poly s,x; s.v.resize(m2),x.v.resize(m2);
For_(i,0,m2) s.v[i]=x.v[i]=0ll; s.v[0]=x.v[1]=x.v[m2-1]=1ll;
while(w)
{
if(w&1)
{ s*=x; get(s,m2); }
w>>=1;
x*=x; get(x,m2);
}
For_(i,0,m2) d[i]=s.v[i];
// For_(i,0,m2) printf("%d:%lld\n",i,d[i]);
}
void fun(int &x,int &y)
{
x+=y; y=x-(y<<1);
}
LL solve2(int x1,int y1,int x2,int y2)
{
return (d[md(x2-x1,m2)]*d[md(y2-y1,m2)]%mod);
}
LL solve(int x1,int y1,int x2,int y2)
{
fun(x1,y1),fun(x2,y2);
return (solve2(x1,y1,x2,y2)+solve2(x1+m,y1+m,x2,y2))%mod;
}
void main_solve()
{
int stp; in3(n,stp,Q); m=n+2<<1,m2=m<<1;
init(stp);
while(Q--)
{
int x1,y1,x2,y2; scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
outll(md(solve(x1,y1,x2,y2)+solve(m-x1-2,m-y1-2,x2,y2)-solve(x1,m-y1-2,x2,y2)-solve(m-x1-2,y1,x2,y2)));
}
}
int main()
{
// ios::sync_with_stdio(0); cin.tie(0);
// freopen("in.txt","r",stdin);
// freopen("out1.txt","w",stdout);
// srand(time(NULL));
main_init();
// int _; inint(_); For(__,1,_) // T>1 ?
// printf("\n------------\n\n"),
main_solve();
return 0;
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 7ms
memory: 54040kb
input:
2 5 3 0 0 1 2 1 1 2 1 0 0 2 2
output:
30 64 0
result:
ok 3 number(s): "30 64 0"
Test #2:
score: 0
Accepted
time: 15ms
memory: 54292kb
input:
5 20 5 0 0 5 5 1 1 4 4 2 2 3 3 2 3 2 3 1 2 5 2
output:
615136704 443203969 899931333 464755094 679729107
result:
ok 5 number(s): "615136704 443203969 899931333 464755094 679729107"
Test #3:
score: 0
Accepted
time: 11ms
memory: 55052kb
input:
10 10 100 9 3 0 6 10 10 4 4 10 1 2 6 7 8 2 3 0 3 9 2 3 6 1 10 1 5 2 9 7 3 1 5 9 10 3 0 0 6 9 3 0 8 2 0 3 10 8 1 9 7 8 2 1 0 7 6 5 8 4 2 2 5 0 7 8 6 7 5 4 2 3 7 10 3 1 10 5 6 5 0 9 1 3 5 7 6 5 7 7 5 0 10 3 1 8 8 4 0 2 4 5 7 3 9 6 2 6 9 6 7 10 3 10 9 5 10 3 5 7 5 6 5 7 0 2 10 6 9 0 9 4 1 7 6 9 4 6 8 5...
output:
0 0 0 252 10 8040 0 1200 0 0 45 0 5148 0 0 20790 52470 5400 0 1925 210 0 0 0 8250 29040 0 2310 2970 14400 4950 0 0 29040 5400 0 29040 0 2520 8250 0 0 0 0 1155 7392 0 2310 0 320 0 29700 1980 0 63404 0 0 42075 27710 0 0 2520 5544 0 63403 24750 0 45 2310 13860 5544 52900 11340 6930 19800 0 3300 5138 25...
result:
ok 100 numbers
Test #4:
score: 0
Accepted
time: 33ms
memory: 54120kb
input:
100 998244353 100000 30 78 89 46 12 26 33 24 16 4 68 89 51 48 88 35 12 83 76 24 73 11 48 13 89 3 13 15 67 61 56 85 47 13 96 33 59 38 71 37 67 37 35 20 85 26 1 19 38 90 14 41 7 52 66 64 68 6 13 66 78 28 50 84 15 35 98 87 44 0 55 82 50 74 56 49 88 98 75 74 6 5 18 18 90 75 16 17 17 74 91 11 57 41 17 14...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 100000 numbers
Test #5:
score: 0
Accepted
time: 10ms
memory: 64324kb
input:
1 234567890 100 1 1 0 0 0 0 1 0 0 1 0 1 0 0 0 0 1 1 0 0 1 0 0 1 1 0 0 1 1 1 1 1 0 1 1 1 1 1 0 1 0 0 0 0 0 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 0 1 1 1 1 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 1 0 0 1 0 0 1 1 1 1 1 1 1 1 0 0 1 1 0 0 0 0 0 1 0 0 1 0 1 1 0 1 1 0 0 0 0 0 0 0 0 0 1 0 0 1 1 0 1 1 0 0 0 0 0 0 0 0 0 0 1 ...
output:
562097306 0 562097306 562097306 562097306 562097306 562097306 562097306 0 0 562097306 0 562097306 0 562097306 562097306 562097306 562097306 0 0 562097306 562097306 562097306 0 562097306 562097306 562097306 562097306 562097306 562097306 0 562097306 562097306 562097306 562097306 562097306 562097306 56...
result:
ok 100 numbers
Test #6:
score: -100
Time Limit Exceeded
input:
100000 1000000000 300000 401 24053 58285 18046 98210 71066 13326 96996 35754 75165 22182 67209 34695 62569 98038 25962 25823 83198 3812 44322 40127 22699 32134 158 2721 51519 79219 46775 71309 3160 73856 6217 75906 67973 22027 11684 93792 19353 432 89701 26433 63842 6090 20535 49837 36247 57729 4509...