제출 #1348979

#제출 시각아이디문제언어결과실행 시간메모리
1348979po_rag526XOR (IZhO12_xor)C++17
100 / 100
79 ms23224 KiB
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
const ll mod = 1000000007;
const ll MOD = 1511100007;
using namespace std;
int n,x,lim;
vector<int> fg,v;
int jum[2000005][2],miva[2000005],cn;
int pos,len;
int pre[250005];
void add(int id){
    int rt = 0;
    for(int i = 0;i < v.size();i++){
        x = v[i];
        if(jum[rt][x] == 0)jum[rt][x] = ++cn;
        rt = jum[rt][x];
        miva[rt] = min(miva[rt],id);
    }
}
void tim(int id){
    int stt = n+1;
    int rt = 0;
    bool ok = 1;
    for(int i = 0;i < v.size();i++){
        int x = v[i],u = fg[i];
        int z = x;z ^= u;
        if(u == 0){
            int rz = x;rz ^= 1;
            if(jum[rt][rz] != 0)stt = min(stt,miva[jum[rt][rz]]);
        }
        if(jum[rt][z] == 0){
            ok = 0;
            break;
        }
        rt = jum[rt][z];
    }
    if(ok)stt = min(stt,miva[rt]);
    if(stt != n+1){
        int le = id-stt;
        if(le > len){
            len = le;
            pos = stt+1;
        }
    }
}
void solve(){
    cin >> n >> x;
    lim = x;
    for(int i = 0;i <= 2e6;i++)miva[i] = n+1;
    while(x > 0){
        fg.push_back(x%2);
        x /= 2;
    }
    while(fg.size() < 31)fg.push_back(0);
    reverse(fg.begin(),fg.end());
    pos = 1,len = 0;
    while(v.size() < 31)v.push_back(0);
    add(0);
    for(int i = 1;i <= n;i++){
        int cr;cin >> cr;
        pre[i] = pre[i-1]^cr;
        v.clear();
        cr = pre[i];
        while(cr > 0){
            v.push_back(cr%2);
            cr /= 2;
        }
        while(v.size() < 31)v.push_back(0);
        reverse(v.begin(),v.end());
        tim(i);
        add(i);
    }
    cout << pos << " " << len;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    if(fopen("deH.INP","r")){
        freopen("deH.INP","r",stdin);
        freopen("deH.OUT","w",stdout);
    }
    int ts = 1;//cin >> ts;
    while(ts--)solve();
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

xor.cpp: In function 'int main()':
xor.cpp:80:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |         freopen("deH.INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
xor.cpp:81:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |         freopen("deH.OUT","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...