QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#240975 | #6190. Graph Problem | Crysfly | AC ✓ | 1286ms | 6628kb | C++17 | 3.8kb | 2023-11-05 21:32:00 | 2023-11-05 21:32:00 |
Judging History
answer
// what is matter? never mind.
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
#define ull unsigned long long
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
#define mod 998244353
struct modint{
int x;
modint(int o=0){x=o;}
modint &operator = (int o){return x=o,*this;}
modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
modint &operator ^=(int b){
modint a=*this,c=1;
for(;b;b>>=1,a*=a)if(b&1)c*=a;
return x=c.x,*this;
}
modint &operator /=(modint o){return *this *=o^=mod-2;}
friend modint operator +(modint a,modint b){return a+=b;}
friend modint operator -(modint a,modint b){return a-=b;}
friend modint operator *(modint a,modint b){return a*=b;}
friend modint operator /(modint a,modint b){return a/=b;}
friend modint operator ^(modint a,int b){return a^=b;}
friend bool operator ==(modint a,int b){return a.x==b;}
friend bool operator !=(modint a,int b){return a.x!=b;}
bool operator ! () {return !x;}
modint operator - () {return x?mod-x:0;}
bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}
vector<modint> fac,ifac,iv;
inline void initC(int n)
{
if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
int m=iv.size(); ++n;
if(m>=n)return;
iv.resize(n),fac.resize(n),ifac.resize(n);
For(i,m,n-1){
iv[i]=iv[mod%i]*(mod-mod/i);
fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
}
}
inline modint C(int n,int m){
if(m<0||n<m)return 0;
return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 400005
#define inf 0x3f3f3f3f
#define N 505
/*
https://_rqy.blog.uoj.ac/blog/8048
*/
int n,m;
struct mat{
modint a[N][N];
modint*operator [](int x){return a[x];}
void print(int n){
For(i,1,n)For(j,1,n)cout<<a[i][j].x<<" \n"[j==n];
puts("-----");
}
};
bool inv(mat&a,int n){
static int pi[N],pj[N];
For(k,1,n){
pi[k]=pj[k]=0;
For(i,k,n)For(j,k,n)if(a[i][j].x){pi[k]=i,pj[k]=j;break;}
if(!pi[k])return 0;
For(i,1,n)swap(a[k][i],a[pi[k]][i]);
For(i,1,n)swap(a[i][k],a[i][pj[k]]);
if(!a[k][k].x)return 0;
a[k][k]=1/a[k][k];
For(j,1,n)if(j!=k)a[k][j]*=a[k][k];
For(i,1,n)if(i!=k)For(j,1,n)if(j!=k)a[i][j]-=a[i][k]*a[k][j];
For(i,1,n)if(i!=k)a[i][k]=-a[i][k]*a[k][k];
}
Rep(k,n,1){
For(i,1,n)swap(a[pj[k]][i],a[k][i]);
For(i,1,n)swap(a[i][pi[k]],a[i][k]);
}
return 1;
}
mat g,ig,a;
mt19937_64 rnd(time(0));
int R(int l,int r){
return rnd()%(r-l+1)+l;
}
int pos[10];
signed main()
{
n=read(),m=read();
For(i,1,m){
int u=read(),v=read();
g[u][v]=R(1,mod-1);
}
For(u,1,n) g[u][u]=R(0,mod-1);
ig=g;
assert(inv(ig,n));
int Q=read(),cnt=0;
For(_,1,Q){
int k=read();
For(i,1,k)pos[i]=(read()+cnt-1)%n+1;
For(i,1,k)
For(j,1,k)
a[i][j]=ig[pos[i]][pos[j]];
inv(a,k);
int q2=read();
while(q2--){
int s=(read()+cnt-1)%n+1,t=(read()+cnt-1)%n+1;
modint res=0;
For(i,1,k)
For(j,1,k)
res+=ig[s][pos[i]]*a[i][j]*ig[pos[j]][t];
if(res.x==ig[s][t].x) putchar('0');
else putchar('1'),++cnt;
}
puts("");
}
return 0;
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 6572kb
input:
5 4 1 2 2 3 3 4 4 5 2 1 4 2 1 5 1 3 3 5 3 4 1 1 2
output:
01 1
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 2ms
memory: 6520kb
input:
100 4870 1 4 1 9 2 1 2 6 2 8 4 5 4 10 5 2 5 3 5 7 6 2 6 4 6 8 7 1 7 2 7 8 7 10 8 1 8 2 8 3 8 4 8 5 8 6 8 7 8 9 8 13 8 16 8 17 9 1 9 2 9 3 9 4 9 5 9 6 9 7 9 8 9 18 10 1 10 2 10 3 10 4 10 5 10 6 10 7 10 11 10 15 11 1 11 2 11 3 11 4 11 5 11 6 11 7 11 8 11 9 11 10 11 12 11 18 11 20 12 1 12 2 12 3 12 4 1...
output:
1011000010 1010110101 0001010000 0000101001 1000010000 0111001101 0011001101 1100010010 0001100010 0010110101 0011001111 0001000101 1101010010 0100001100 1000100001 0100000000 1110100000 0101111010 0111001001 1110000000 1011000011 0110000000 0000000100 0001011000 1000111000 1111000010 1000110000 011...
result:
ok 100 lines
Test #3:
score: 0
Accepted
time: 3ms
memory: 6568kb
input:
100 4839 1 2 1 7 1 12 1 13 1 15 1 17 1 21 1 22 1 24 2 1 2 4 2 5 2 7 2 12 2 16 2 19 2 22 2 24 3 7 3 8 3 13 3 20 3 22 4 8 4 12 4 14 4 19 5 2 5 3 5 4 5 6 5 7 5 10 5 13 5 14 5 19 5 24 6 3 6 7 6 8 6 10 6 12 6 13 6 15 6 17 6 19 6 21 6 23 6 24 7 2 7 6 7 8 7 9 7 10 7 12 7 13 7 16 7 23 8 1 8 9 8 11 8 12 8 13...
output:
1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111100111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 111...
result:
ok 100 lines
Test #4:
score: 0
Accepted
time: 3ms
memory: 6496kb
input:
100 4650 1 7 1 12 1 20 1 22 2 7 2 9 2 10 2 11 2 14 2 18 2 20 3 1 3 4 3 8 3 12 3 14 3 16 3 17 3 20 3 21 3 22 4 1 4 6 4 8 4 11 4 12 4 13 4 16 4 21 5 2 5 4 5 9 5 16 5 19 5 21 6 7 6 9 6 10 6 21 7 2 7 8 7 9 7 19 7 20 7 22 8 5 8 7 8 11 8 12 8 14 8 21 9 1 9 5 9 6 9 7 9 8 9 12 9 17 9 21 9 22 10 4 10 9 10 12...
output:
1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 111...
result:
ok 100 lines
Test #5:
score: 0
Accepted
time: 3ms
memory: 6444kb
input:
100 4945 1 2 1 3 1 5 1 7 1 8 1 9 1 10 1 13 1 15 2 1 2 3 2 4 2 9 2 11 2 12 2 15 3 1 3 10 3 12 3 16 4 1 4 5 4 10 4 12 4 13 4 15 4 16 5 6 5 11 5 16 5 17 6 2 6 10 6 11 6 14 7 1 7 2 7 3 7 4 7 5 7 6 7 8 7 9 7 10 7 11 7 16 7 21 7 22 7 23 7 24 7 25 7 27 7 28 7 30 7 31 7 32 7 35 7 38 7 39 8 1 8 2 8 3 8 4 8 5...
output:
1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1110101101 1111111111 1111111111 1111111111 1111111111 1100011011 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 111...
result:
ok 100 lines
Test #6:
score: 0
Accepted
time: 314ms
memory: 6452kb
input:
500 124582 1 12 1 14 2 4 2 7 2 9 2 13 2 14 2 18 3 1 3 4 3 7 3 14 3 17 4 1 4 3 4 6 4 12 4 15 4 18 5 3 6 1 6 3 6 8 6 10 6 11 6 13 6 15 6 17 6 18 7 3 7 4 7 5 7 8 7 9 7 17 8 2 8 6 9 10 9 13 9 17 10 2 10 5 10 17 11 1 11 2 11 3 11 4 11 5 11 6 11 7 11 8 11 9 11 10 11 17 11 18 11 19 11 26 12 1 12 2 12 3 12 ...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok 100000 lines
Test #7:
score: 0
Accepted
time: 317ms
memory: 6444kb
input:
500 125402 1 3 1 7 1 10 1 13 1 16 1 21 1 23 1 25 1 28 1 36 1 37 2 3 2 4 2 6 2 7 2 9 2 11 2 16 2 17 2 19 2 20 2 24 2 26 2 28 2 30 2 37 3 2 3 18 3 19 3 21 3 25 3 26 3 32 4 7 4 9 4 10 4 11 4 12 4 14 4 15 4 18 4 19 4 24 4 33 4 35 4 36 5 1 5 4 5 10 5 11 5 17 5 19 5 20 5 21 5 23 5 24 5 31 5 32 5 36 5 38 5...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok 100000 lines
Test #8:
score: 0
Accepted
time: 316ms
memory: 6448kb
input:
500 123930 1 6 1 11 1 13 1 16 1 22 1 25 1 26 1 34 1 38 1 41 1 42 1 43 1 44 1 46 1 48 1 49 1 51 1 53 1 56 2 6 2 9 2 13 2 15 2 24 2 31 2 33 2 36 2 37 2 43 2 44 2 50 2 53 2 56 3 2 3 4 3 5 3 16 3 18 3 19 3 25 3 31 3 32 3 40 3 43 3 44 3 47 3 48 3 50 3 51 3 53 4 1 4 2 4 3 4 5 4 6 4 8 4 14 4 18 4 20 4 26 4...
output:
0 1 1 0 1 1 1 1 1 1 1 1 0 1 1 0 1 1 0 1 1 0 0 1 0 1 0 1 0 1 1 1 0 1 0 0 1 0 0 1 1 1 0 1 1 0 0 1 0 0 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 0 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 1 0 1 1 0 0 1 0 1 0 1 1 0 1 0 0 0 1 0 1 1 1 1 0 0 0 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 0 0 1 1 0 0 1 1 0 0 0 0 1 1 1 1 1 1 0 0 0 0 1 0 1 1 1 ...
result:
ok 100000 lines
Test #9:
score: 0
Accepted
time: 311ms
memory: 6496kb
input:
500 123484 1 5 1 8 1 10 1 11 1 12 1 20 1 23 1 26 1 27 1 28 1 29 1 31 1 33 1 41 2 4 2 7 2 10 2 18 2 20 2 34 2 35 2 39 2 41 2 42 2 44 2 46 2 52 3 4 3 5 3 6 3 7 3 9 3 14 3 17 3 19 3 23 3 25 3 26 3 32 3 36 3 38 3 39 3 40 3 44 3 46 3 48 3 51 4 1 4 7 4 11 4 12 4 14 4 16 4 17 4 19 4 21 4 23 4 24 4 25 4 29 ...
output:
0 0 1 1 1 0 1 1 1 1 0 0 0 1 0 1 1 1 1 0 0 1 1 0 0 0 1 1 1 0 0 1 1 0 0 0 1 1 0 1 0 0 0 1 1 1 1 1 0 0 0 0 0 1 1 0 0 1 0 0 1 1 1 0 1 0 1 0 0 1 1 0 0 1 1 0 0 1 0 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 0 0 0 0 1 0 0 0 1 1 0 0 1 1 0 0 1 1 1 0 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 1 1 0 1 1 1 1 1 0 0 1 0 0 0 1 0 1 0 ...
result:
ok 100000 lines
Test #10:
score: 0
Accepted
time: 1286ms
memory: 6444kb
input:
500 3278 2 5 2 7 3 5 4 6 4 9 5 6 5 7 5 8 6 8 6 9 6 10 7 8 7 9 8 9 9 13 9 20 9 22 9 23 9 24 9 27 9 29 9 31 10 12 10 14 10 17 10 21 10 23 10 24 10 25 10 26 10 27 11 15 11 17 11 20 11 21 11 25 12 16 12 20 12 21 12 22 12 24 12 28 12 32 12 33 12 39 12 42 12 45 12 46 12 47 12 48 13 14 13 20 13 21 13 23 13...
output:
1011111110 1010010110 0011111011 0101110101 0101011111 1111100001 1111111101 1110000110 1111111011 1111101011 1100101011 1110110111 1100111011 1110100100 1010011111 1111110111 0110111111 1111011100 1110011111 1001101000 1110100111 0111110111 1110111110 1101110001 1111010111 0100100011 1111010011 111...
result:
ok 400000 lines
Test #11:
score: 0
Accepted
time: 1232ms
memory: 6484kb
input:
500 3720 1 3 1 8 1 9 1 11 1 12 1 13 1 18 1 24 1 25 2 4 2 6 2 9 2 10 2 12 2 13 2 18 2 23 2 24 3 8 3 15 3 18 3 19 3 22 3 25 3 26 4 10 4 15 4 17 4 19 5 7 5 9 5 10 5 12 5 13 5 14 5 21 6 8 6 9 6 13 6 16 6 24 7 9 7 11 7 13 7 14 7 15 7 16 7 18 7 26 8 10 8 15 8 18 8 19 8 21 8 22 9 14 9 15 9 16 9 20 9 21 9 2...
output:
1111111101 1111111100 1110111110 1111111110 1111111111 1111111110 1101111011 1111111111 1111110111 1111111101 1111111111 0001010100 1111111111 1111111111 0011110111 1111111101 1111111111 1111111111 1110111111 1111111111 1011110011 1011111111 1111101101 1111111110 1111111111 1111111110 1111001111 110...
result:
ok 400000 lines
Test #12:
score: 0
Accepted
time: 1243ms
memory: 6500kb
input:
500 4232 1 2 1 6 1 14 1 16 2 4 2 6 2 10 2 16 2 17 2 18 2 25 2 26 2 28 3 4 3 6 3 12 3 13 3 17 3 18 3 25 4 8 4 12 4 18 4 23 4 28 5 8 5 9 5 10 5 12 5 13 5 17 5 18 5 21 5 26 5 28 6 8 6 9 6 12 6 23 6 24 6 25 6 26 6 27 6 29 7 15 7 23 7 24 7 25 7 28 8 12 8 14 8 16 8 19 8 29 9 12 9 13 9 15 9 16 9 17 9 20 9 ...
output:
1111011011 1111111111 1111111111 0111111011 1111111011 1110111111 0111111110 1110110111 1110001110 1011111111 0111111111 1111111111 1011111110 1111111111 1011111111 1111111111 1111011111 1111111011 1110111111 0111111111 0111110111 1111101111 0111110111 0111111111 1111111111 1111110011 1111111111 111...
result:
ok 400000 lines
Test #13:
score: 0
Accepted
time: 1260ms
memory: 6592kb
input:
500 6443 1 5 1 9 1 12 1 15 1 18 1 20 1 21 1 22 1 24 1 26 1 27 1 30 1 34 1 35 1 37 1 40 1 42 1 45 1 47 1 48 1 49 1 55 1 58 1 64 1 67 1 68 1 71 1 72 2 3 2 6 2 8 2 9 2 16 2 17 2 19 2 23 2 26 2 29 2 31 2 35 2 36 2 37 2 38 2 41 2 45 2 47 2 52 2 53 2 57 2 69 2 70 2 73 2 76 2 77 3 6 3 12 3 14 3 15 3 20 3 2...
output:
1001111111 0101111010 1111011111 1111111010 1111101111 0111111111 0110111111 1110111111 1111101101 1011111111 1111111111 1111111101 1110111110 1101111111 1011111111 1011111111 1111111111 1111110110 1111110101 1011111011 1111101110 1111111010 0011101101 1011111101 1111101111 1111100110 1101101000 111...
result:
ok 400000 lines
Test #14:
score: 0
Accepted
time: 1243ms
memory: 6624kb
input:
500 123824 2 4 2 6 3 1 3 10 4 2 4 6 4 7 4 8 5 2 5 3 5 4 5 7 5 8 5 11 6 7 7 3 7 5 7 6 7 8 7 11 8 2 8 4 9 1 9 2 9 3 9 4 9 5 9 6 9 7 9 8 9 12 9 14 9 17 9 21 9 23 9 24 9 25 9 26 9 27 10 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 13 10 15 10 18 10 19 10 23 11 1 11 2 11 3 11 4 11 5 11 6 11 7 11 8 11 10 11 15...
output:
0111110011 0110111111 1011001110 0101001011 0111110111 0011011000 1011110010 1000001101 1111000111 0101101111 1000001010 1010101010 0100000100 1011101110 1100011000 0000111110 0010100011 0110010101 1000111111 1101000001 0111110010 0011110100 0011101010 1001001111 0001010011 1010110110 0110111110 000...
result:
ok 400000 lines
Test #15:
score: 0
Accepted
time: 1190ms
memory: 6628kb
input:
500 124816 1 3 1 8 1 9 1 11 1 12 1 13 1 18 1 24 1 25 2 3 2 5 2 8 2 9 2 11 2 12 2 17 2 22 2 23 3 5 3 12 3 15 3 16 3 19 3 22 3 23 4 3 4 9 4 11 4 13 4 22 4 24 4 25 5 1 5 2 5 3 5 11 5 18 5 19 5 23 5 26 6 9 6 13 6 15 6 17 6 18 6 19 6 20 6 22 7 4 7 6 7 12 7 15 7 16 7 18 7 19 8 2 8 3 8 4 8 9 8 10 8 11 8 16...
output:
1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 111...
result:
ok 400000 lines
Test #16:
score: 0
Accepted
time: 1211ms
memory: 6612kb
input:
500 124872 1 2 1 6 1 14 1 16 2 1 2 4 2 6 2 10 2 16 2 17 2 18 2 25 2 26 2 28 3 1 3 2 3 5 3 11 3 12 3 16 3 17 3 24 4 1 4 5 4 9 4 15 4 20 4 25 4 30 5 1 5 2 5 3 5 6 5 7 5 11 5 12 5 15 5 20 5 22 5 26 5 27 5 30 6 1 6 13 6 14 6 15 6 16 6 17 6 19 6 28 7 1 7 8 7 9 7 10 7 13 7 19 7 21 7 23 7 26 8 1 8 7 8 12 8...
output:
0001111111 1101111010 1110011011 1011001101 0110111111 0000111000 1101010111 0101001111 1001101011 1111111101 1111110011 0010011010 0001000001 0101101111 1111000101 1100100001 0011010101 1010010110 0011111011 0000011011 1100010000 1011011011 1111010001 0110111011 0111000111 0111111000 1111000111 011...
result:
ok 400000 lines
Test #17:
score: 0
Accepted
time: 1180ms
memory: 6448kb
input:
500 124293 1 5 1 9 1 12 1 15 1 18 1 20 1 21 1 22 1 24 1 26 1 27 1 30 1 34 1 35 1 37 1 40 1 42 1 45 1 47 1 48 1 49 1 55 1 58 1 64 1 67 1 68 1 71 1 72 2 1 2 5 2 7 2 8 2 15 2 16 2 18 2 22 2 25 2 28 2 30 2 34 2 35 2 36 2 37 2 40 2 44 2 46 2 51 2 52 2 56 2 68 2 69 2 72 2 75 2 76 3 2 3 9 3 11 3 12 3 17 3 ...
output:
1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111101 1111111111 1111111111 1111111111 1111111111 1100100100 1111111111 1111111111 1111111111 111...
result:
ok 400000 lines