QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#951#56129#1907. 博弈chuangshigameCharlieVinnieFailed.2024-10-12 20:40:092024-10-12 20:40:09

详细

Extra Test:

Accepted
time: 6ms
memory: 6200kb

input:

10 10
0 1 1 12160
1 0 1 97440
0 1 1 3920
0 1 47880 99036
1 0 80388 62460
1 0 16200 1
1 0 92736 57600
1 0 34000 54450
0 1 54750 32400
0 1 96624 82824
2 6
8 10
4 6
5 9
6 9
3 3
2 10
1 1
4 9
2 3

output:

YNYYYNNNYN

result:

ok single line: 'YNYYYNNNYN'

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#56129#1907. 博弈CharlieVinnie100 ✓132ms8920kbC++202.2kb2022-10-17 11:42:292024-10-08 15:30:32

answer

#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(int i=a;i>=b;i--)
#define Fin(file) freopen(file,"r",stdin)
#define Fout(file) freopen(file,"w",stdout)
using namespace std;
const int N=2e5+5; typedef long long ll;
int pr[N],cnt,vis[N];
int n,Q,pcnt[N],pcnt0[N]; ll num[N],star[N];
pair<ll,ll> Solve0(int a,int b){
    if(pcnt[a]==pcnt[b]) return make_pair(0,0);
    int flg=0; if(pcnt[a]<pcnt[b]) { flg=1; swap(a,b); }
    int ww=pcnt[b]+1; ll res=1;
    while(a!=1){
        if(ww) ww--; else res=res*vis[a]+1;
        a/=vis[a];
    }
    return make_pair(flg==0?res:-res,0);
}
pair<ll,ll> Solve1(int a,int b){
    if(a%2==0||b%2==0) return make_pair(0,(pcnt0[a]^pcnt0[b])+1);
    else return make_pair(0,pcnt0[a]^pcnt0[b]);
}
pair<ll,ll> Solve2(int a,int b){
    ll res=1; if(a==1) res=0; else { a/=vis[a]; while(a!=1) { res=res*vis[a]+1; a/=vis[a]; } }
    return make_pair(1ll*res*b,pcnt0[b]+(b%2==0));
}
signed main(){
    // Fin("hh.in"); Fout("hh.out");
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    For(i,2,N-5){
        if(!vis[i]) { vis[i]=i; pr[++cnt]=i; }
        For(j,1,cnt){
            if(1ll*pr[j]*i>N-5||pr[j]>vis[i]) break;
            vis[i*pr[j]]=pr[j];
        }
    }
    // For(i,1,20) cout<<vis[i]<<' '; cout<<endl;
    For(i,1,N-5){
        int t=i,cur=0;
        while(t!=1){
            int x=vis[t]; pcnt[i]++;
            if(x!=2) pcnt0[i]++;
            cur=x; t/=x;
        }
        // if(i<=12) printf("(%d,%d)\n",pcnt[i],pcnt0[i]);
    }
    cin>>n>>Q;
    For(i,1,n){
        int x,y,a,b; cin>>x>>y>>a>>b; pair<ll,ll> res; swap(x,y);
        if(x==0&&y==0) res=Solve0(a,b);
        else if(x==1&&y==1) res=Solve1(a,b);
        else if(x==0&&y==1) res=Solve2(a,b);
        else { res=Solve2(b,a); res.first=-res.first; }
        // printf("res=(%lld,%lld)\n",res.first,res.second);
        num[i]=num[i-1]+res.first; star[i]=star[i-1]^res.second;
    }
    while(Q--){
        int l,r; cin>>l>>r;
        if( num[r]-num[l-1]>0 || (num[r]-num[l-1]==0&&star[r]!=star[l-1]) ) cout<<"Y";
        else cout<<"N";
    }
    cout<<'\n';
    cerr<<"Time = "<<clock()<<" ms"<<endl;
    return 0;
}

// START TYPING IF YOU DON'T KNOW WHAT TO DO