QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#721201#7839. 虹KnownError_0 0ms0kbC++143.2kb2024-11-07 15:33:442024-11-07 15:33:47

Judging History

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

  • [2024-11-07 15:33:47]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-11-07 15:33:44]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using ui = unsigned;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,l,r) for(int i=(l);i>=(r);--i)
#define repn(i,n) for(int i=0;i<(n);++i)
#define sizc(x) ((int)(x).size())
#define allc(x) (x).begin(),(x).end()
#define fir first
#define sec second

constexpr int N = 8e4+5, B = 300;

int n,m;
vector<int> G[N];

namespace Sieve{
    bitset<N> vis;
    vector<int> primes;
    void init(){
        rep(i,2,n)if(!vis[i]){
            primes.push_back(i);
            rep(j,2,n/i)vis[i*j]=1;
        }
    }
}
using Sieve::primes;

bitset<N> D[N],S,z,Z;
int g[N];

int f[N];
void dfs(int u,int fa){
    f[u]=fa;
    for(auto v:G[u])if(v!=fa)dfs(v,u);
}
vector<pair<int,int>> Q1[B],Q2[B];

vector<int> Q3[N];
pair<int,int> rg[N];

void dfsu(int x,int val){
    if(x==primes.size()||(ll)val*primes[x]>n){
        for(auto id:Q3[val])D[id]&=Z;
        return;
    }
    dfsu(x+1,val);
    int mul=1;
    while((ll)val*primes[x]<=n){
        val*=primes[x];
        mul*=primes[x];
        for(int i=mul;i<=n;i+=mul){
            g[i]*=primes[x];
            Z[i]=z[g[i]];
        }
        dfsu(x+1,val);
    }
    for(int i=primes[x];i<=n;i+=primes[x]){
        while(g[i]%primes[x]==0)g[i]/=primes[x];
        Z[i]=z[g[i]];
    }
}

signed main(){
	// freopen(".in","r",stdin);
	// freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

    cin>>n>>m;
    rep(i,1,n){
        bool x;cin>>x;
        z[i]=x;
    }
    rep(i,2,n){
        int u,v;cin>>u>>v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    Sieve::init();
    rep(i,1,m){
        int op,l,r;
        cin>>op>>l>>r;
        if(op==1){
            int bl=(l-1)/B+1,br=(r-1)/B+1;
            if(bl==br){
                dfs(l,0),D[i][l]=1;
                rep(j,l+1,r){
                    int p=j;
                    while(!D[i][p])D[i][p]=1,p=f[p];
                }
                continue;
            }
            Q1[bl].emplace_back(l,i);
            Q2[bl].emplace_back(r,i);
        }
        else{
            int u;cin>>u;
            rg[i]={l,r};
            Q3[u].push_back(i);
            assert(l);
            cout<<1;return 0;
        }
    }
    rep(i,1,(n-1)/B){
        int u=i*B;
        dfs(u,0);
        S.reset(),S[u]=1;
        int it=u;
        sort(allc(Q1[i]),greater<pair<int,int>>());
        sort(allc(Q2[i]));
        for(auto p:Q1[i]){
            while(it>p.fir){
                --it;
                int x=it;
                while(!S[x])S[x]=1,x=f[x];
            }
            D[p.sec]=S;
        }
        S.reset(),S[u]=1;
        it=u;
        for(auto p:Q2[i]){
            while(it<p.fir){
                ++it;
                int x=it;
                while(!S[x])S[x]=1,x=f[x];
            }
            D[p.sec]|=S;
        }
    }
    rep(i,1,m)D[i]^=D[i-1];
    rep(i,1,n)Z[i]=z[g[i]=1];
    dfsu(0,1);
    rep(i,1,m)if(rg[i].fir){
        int l,r;tie(l,r)=rg[i];
        D[i]>>=l;
        int s=D[i].count()-(D[i]>>r-l+1).count();
        cout<<(r-l+1+19901990ll*s)%20242024<<'\n';
    }
}

详细

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

input:

998 1000
955556485 952505211 899166521 258704448 894183248 636280051 62949347 983956660 113872828 588367167 208142006 665025449 944228063 284736189 169202015 56096447 404419923 30158095 111191865 717455344 790159420 391379127 208279658 426780799 886604643 940903663 618716147 773652834 385881251 1593...

output:


result:


Subtask #2:

score: 0
Runtime Error

Test #4:

score: 0
Runtime Error

input:

65531 65535
968854923 932574892 192297572 866236747 654755663 148562561 273214896 947434573 938626677 992982166 219888853 229840279 676071061 383387319 372883953 729287797 601010887 31942080 990584163 823724544 181337075 918252129 896876911 768539961 357780649 890577681 819641335 320266037 55445939 ...

output:


result:


Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%