結果

問題 No.2658 L-R Nim
ユーザー Rubikun
提出日時 2024-03-01 22:10:41
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,732 bytes
コンパイル時間 2,220 ms
コンパイル使用メモリ 203,416 KB
最終ジャッジ日時 2025-02-19 22:35:53
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 26 TLE * 1 -- * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=1<<20,INF=1<<30;

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

int cn[MAX];
int A[MAX],rui[MAX];
int la[MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,K;cin>>N>>K;
    for(int i=0;i<N;i++){
        cin>>A[i];
        rui[i+1]=rui[i]^A[i];
    }
    
    int L=-1,R=N;
    
    for(int i=0;i<MAX;i++) la[i]=-1;
    
    for(int i=0;i<=N;i++){
        if(la[rui[i]]!=-1){
            chmax(L,la[rui[i]]+1);
            chmin(R,i);
        }
        la[rui[i]]=i;
    }
    
    if(L==-1){
        cout<<"Yes\n";
        return 0;
    }
    
    if(L>R){
        cout<<"No\n";
        return 0;
    }
    
    vector<ll> cn(MAX);
    for(int i=0;i<L;i++){
        for(int j=L;j<=N;j++){
            cn[rui[i]^rui[j]]++;
        }
    }
    
    //cout<<L<<" "<<R<<endl;
    
    for(int s=L;s<=R;s++){
        int l=max(1,A[s-1]-K),r=A[s-1]+K,y=A[s-1];
        int ans=0;
        for(int x=l;x<=r;x++){
            ans+=(cn[x^y]==0);
        }
        if(ans){
            cout<<"Yes\n";
            return 0;
        }
        
        int z=rui[s];
        for(int i=0;i<s;i++) cn[rui[i]^z]--;
        for(int i=s+1;i<=N;i++) cn[rui[i]^z]++;
    }
    
    cout<<"No\n";
}

0