QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#318978#6161. 作业题XY_Eleven100 ✓123ms5552kbC++235.9kb2024-02-01 12:59:322024-02-01 12:59:33

Judging History

你现在查看的是最新测评结果

  • [2024-02-01 12:59:33]
  • 评测
  • 测评结果:100
  • 用时:123ms
  • 内存:5552kb
  • [2024-02-01 12:59:32]
  • 提交

answer

#include <bits/stdc++.h>
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) ((LL)(e))
#define pb push_back
#define ft first
#define sc second
#define clean(e) while(!e.empty()) e.pop()
#define all(ev) ev.begin(),ev.end()
#define debug(x) cerr<<#x<<'='<<x<<'\n'
cLL mod=998244353;
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 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_); }
LL pw(LL X_,LL Y_,LL M_=mod) { LL S_=1ll; while(Y_) { if(Y_&1) mul(S_,X_,M_); Y_>>=1; mul(X_,X_,M_); } return S_; }
mt19937 gen(time(NULL)); int rd() { return abs((int)gen()); }
cint N=35,M=500,W=1.6e5;
int n,m;
bool vis[M],b[W+1];
vector <int> prim;
struct Ed
{
    int x,y,w;
};
vector <Ed> v;
LL f[W+1];
struct Node
{
    LL x,y;
    bool operator == (const Node &A) const
    {
        return (x==A.x&&y==A.y);
    }
    Node operator + (const Node &A) const
    {
        return {md(x+A.x),md(y+A.y)};
    }
    Node operator - (const Node &A) const
    {
        return {md(x-A.x),md(y-A.y)};
    }
    Node operator - () const
    {
        return {md(-x),md(-y)};
    }
    Node operator * (const Node &A) const
    {
        return {md(x*A.y+y*A.x),md(y*A.y)};
    }
    Node operator / (const Node &A) const
    {
        LL t=inv(A.y);
        return {md((x*A.y-y*A.x)%mod*(t*t%mod)),md(y*t)};
    }
    bool operator ! () const
    {
        return (x==0ll&&y==0ll);
    }
}a[N][N];
LL dfs(int k)
{
    if(!k) return 1ll;
    bool sp=false;
    if(!a[k][k])
    {
        For_(i,1,k)
        {
            exc(!a[i][k]);
            For(j,1,k) swap(a[i][j],a[k][j]);
            sp=true;
            break;
        }
    }
    Node iv=-Node{0ll,1ll}/a[k][k];
    // if((iv*a[k][k])==Node{0ll,mod-1ll}||a[k][k].y==0ll) printf("Yes\n");
    // else printf("No\n");
    For_(i,1,k)
    {
        auto t=iv*a[i][k];
        For(j,1,k)
            a[i][j]=a[i][j]+(a[k][j]*t);
        if(a[i][k].x|a[i][k].y)
        {
            // assert(false);
            return 0ll;
        }
    }
    return dfs(k-1)*(sp?-1ll:1ll);
}
LL mat_tree()
{
    Node s={0ll,dfs(n-1)};
    For_(i,1,n)
    {
        s=s*a[i][i];
        // printf("> %lld,%lld\n",a[i][i].x,a[i][i].y);
    }
    // printf("%lld,%lld\n",s.x,s.y);
    return md(s.x);
}
ULL xor_shift(ULL x)
{
    x^=x<<25;
    x^=x<<(19+(int)(x%11));
    x^=x>>17;
    x^=x<<14;
    return x;
}
int uf[N];
int fin(int w)
{
    return (w==uf[w]?w:(uf[w]=fin(uf[w])));
}
map <ULL,LL> mp;
vector <int> h;
void add_ed(int x,int y,int w)
{
    Node f={1ll*w,1ll};
    a[x][x]=a[x][x]+f,a[y][y]=a[y][y]+f;
    a[x][y]=a[x][y]-f,a[y][x]=a[y][x]-f;
}
LL work(int g)
{
    ULL hs=1686688681;
    For(i,1,n) uf[i]=i;
    int cnt=0;
    h.clear();
    For(i,1,m)
    {
        auto [x,y,w]=v[i];
        exc(w%g);
        h.pb(i);
        hs=xor_shift(hs^i);
        int fx=fin(x),fy=fin(y);
        exc(fx==fy);
        cnt++;
        if(fx>fy) swap(fx,fy);  uf[fy]=fx;
    }
    if(cnt!=n-1) return 0ll;
    if(mp.count(hs)) return mp[hs];
    For(i,1,n) For(j,1,n) a[i][j]={0ll,0ll};
    for(auto i:h)
        add_ed(v[i].x,v[i].y,v[i].w);
    // printf("%d->%lld\n",g,mat_tree());
    return (mp[hs]=mat_tree());
}
void main_solve()
{
    For(i,2,W)
    {
        if(!b[i]) prim.pb(i);
        for(auto j:prim)
        {
            stop(i*j>W);
            b[i*j]=true;
            stop(i%j==0);
        }
    }
    inpr(n,m);
    v.pb({0,0,0});
    For(i,1,m)
    {
        int x,y,w; in3(x,y,w);
        v.pb({x,y,w});
    }
    // work(1);
    For(i,1,W)
    {
        f[i]=work(i);
        // if(f[i]) printf("%d:%lld\n",i,f[i]);
    }
    for(auto i:prim)
    {
        for(int j=1;j*i<=W;j++)
            add(f[j],-f[j*i]);
    }
    // printf("again\n");
    // For(i,1,W)
    //     if(f[i]) printf("%d:%lld\n",i,f[i]);   
    LL ans=0ll;
    For(i,1,W) add(ans,f[i]*i);
    outll(ans);
}
int main()
{
    // ios::sync_with_stdio(0); cin.tie(0);
    // freopen("in.txt","r",stdin);
    // freopen("out.txt","w",stdout);
    // srand(time(NULL));
    // main_init();
    // int _; inint(_); For(__,1,_) // T>1 ?
        // printf("\n------------\n\n"),
        main_solve();
    return 0;
}
/*

*/

詳細信息

Test #1:

score: 10
Accepted
time: 6ms
memory: 5460kb

input:

5 10
1 2 113400
1 3 131040
1 4 131040
1 5 126000
2 3 131040
2 4 90720
2 5 138600
3 4 110880
3 5 110880
4 5 95760

output:

549298858

result:

ok 1 number(s): "549298858"

Test #2:

score: 10
Accepted
time: 7ms
memory: 5388kb

input:

6 15
1 2 110880
1 3 141120
1 4 141120
1 5 131040
1 6 151200
2 3 137280
2 4 105840
2 5 138600
2 6 150480
3 4 138600
3 5 131040
3 6 137280
4 5 85680
4 6 151200
5 6 131040

output:

627752274

result:

ok 1 number(s): "627752274"

Test #3:

score: 10
Accepted
time: 6ms
memory: 5552kb

input:

25 24
1 2 147840
1 3 98280
2 4 120960
3 5 128520
5 6 128520
6 7 143640
1 8 138600
7 9 131040
3 10 147840
10 11 120120
5 12 120120
4 13 131040
8 14 151200
13 15 151200
5 16 110880
11 17 120960
6 18 151200
6 19 147840
5 20 147840
1 21 120960
14 22 110880
13 23 120120
18 24 98280
1 25 131040

output:

623404094

result:

ok 1 number(s): "623404094"

Test #4:

score: 10
Accepted
time: 11ms
memory: 5404kb

input:

28 28
1 2 128520
2 3 98280
1 4 138600
4 5 98280
2 6 98280
1 7 131040
3 8 138600
2 9 147840
6 10 120120
1 11 120960
7 12 138600
6 13 147840
3 14 120960
6 15 120960
9 16 120120
4 17 143640
3 18 128520
15 19 147840
9 20 120120
6 21 120960
20 22 147840
10 23 131040
5 24 138600
7 25 143640
5 26 120960
4 ...

output:

640377458

result:

ok 1 number(s): "640377458"

Test #5:

score: 10
Accepted
time: 12ms
memory: 5424kb

input:

30 30
1 2 110880
1 3 120960
3 4 131040
3 5 120120
3 6 138600
5 7 98280
3 8 120960
5 9 128520
1 10 128520
2 11 138600
5 12 98280
10 13 98280
11 14 143640
3 15 120960
10 16 98280
16 17 138600
5 18 138600
13 19 147840
18 20 120960
13 21 131040
15 22 151200
22 23 131040
2 24 128520
6 25 120960
20 26 138...

output:

309797364

result:

ok 1 number(s): "309797364"

Test #6:

score: 10
Accepted
time: 10ms
memory: 5488kb

input:

25 25
1 2 131040
2 3 120120
2 4 98280
3 5 110880
5 6 120120
4 7 120960
1 8 128520
4 9 110880
3 10 147840
7 11 120960
4 12 120960
2 13 138600
8 14 120960
1 15 128520
8 16 131040
10 17 110880
14 18 98280
9 19 131040
7 20 147840
8 21 138600
14 22 138600
5 23 151200
7 24 131040
13 25 143640
12 1 143640

output:

302382070

result:

ok 1 number(s): "302382070"

Test #7:

score: 10
Accepted
time: 103ms
memory: 5468kb

input:

28 376
1 2 152501
1 3 152501
1 4 152501
1 5 152501
1 6 152501
1 7 152501
1 8 152501
1 9 152501
1 10 152501
1 11 152501
1 12 152501
1 13 152501
1 14 152501
1 15 152501
1 16 152501
1 17 152501
1 18 152501
1 19 152501
1 20 152501
1 21 152501
1 22 152501
1 23 152501
1 24 152501
1 25 152501
1 26 152501
1...

output:

493255263

result:

ok 1 number(s): "493255263"

Test #8:

score: 10
Accepted
time: 122ms
memory: 5400kb

input:

30 431
1 2 152501
1 3 152501
1 4 152501
1 5 152501
1 6 152501
1 7 152501
1 8 152501
1 9 152501
1 10 152501
1 11 152501
1 12 152501
1 13 152501
1 14 152501
1 15 152501
1 16 152501
1 17 152501
1 18 152501
1 19 152501
1 20 152501
1 21 152501
1 22 152501
1 23 152501
1 24 152501
1 25 152501
1 26 152501
1...

output:

441996120

result:

ok 1 number(s): "441996120"

Test #9:

score: 10
Accepted
time: 102ms
memory: 5492kb

input:

28 372
1 2 152501
1 3 152501
1 4 152501
1 5 152501
1 6 152501
1 7 152501
1 8 152501
1 9 152501
1 10 152501
1 11 152501
1 12 152501
1 13 152501
1 14 152501
1 15 152501
1 16 152501
1 17 152501
1 18 152501
1 19 152501
1 20 152501
1 21 152501
1 22 152501
1 23 152501
1 24 152501
1 25 152501
1 26 152501
1...

output:

179882346

result:

ok 1 number(s): "179882346"

Test #10:

score: 10
Accepted
time: 123ms
memory: 5348kb

input:

30 432
1 2 152501
1 3 152501
1 4 152501
1 5 152501
1 6 152501
1 7 152501
1 8 152501
1 9 152501
1 10 152501
1 11 152501
1 12 152501
1 13 152501
1 14 152501
1 15 152501
1 16 152501
1 17 152501
1 18 152501
1 19 152501
1 20 152501
1 21 152501
1 22 152501
1 23 152501
1 24 152501
1 25 152501
1 26 152501
1...

output:

45748263

result:

ok 1 number(s): "45748263"

Extra Test:

score: 0
Extra Test Passed