답안 #439835

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
439835 2021-06-30T23:56:39 Z julian33 비밀 (JOI14_secret) C++14
100 / 100
755 ms 4492 KB
#include <bits/stdc++.h>
#include "secret.h"

using namespace std;

#ifdef LOCAL
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {
    cerr<<vars<<" = ";
    string delim="";
    (...,(cerr<<delim<<values,delim=", "));
    cerr<<"\n";
}
#else
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {}
#endif

#define pb push_back
#define sz(x) (int)(x.size())
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> inline void maxa(T& a,T b){a=max(a,b);}
template<typename T> inline void mina(T& a,T b){a=min(a,b);} 

const int mxN=1e3+5;

typedef pair<vector<int>,vector<int>> pvv;

int a[mxN];
vector<pair<pii,pvv>> interval;
vector<int> graph[mxN];

// int Secret(int x,int y){
//     return x^y;
// }

int cnt=0;

void build(int l,int r){
    if(l>=r)
        return;
    int mid=(l+r)>>1;
    vector<int> lft,rt;
    lft.pb(a[mid]); rt.pb(a[mid+1]);
    for(int i=mid+2;i<=r;i++){
        cnt++;
        assert(cnt<=8e3);
        rt.pb(Secret(rt.back(),a[i]));
    }
    for(int i=mid-1;i>=l;i--){
        cnt++;
        assert(cnt<=8e3);
        lft.pb(Secret(a[i],lft.back()));
    }
    interval.pb({{l,r},{lft,rt}});
    build(l,mid); build(mid+1,r);
}

int Query(int L, int R){
    L++; R++;
    if(L==R)
        return a[L];
    for(auto u:interval){
        int l=u.first.first;
        int r=u.first.second;
        int mid=(l+r)>>1;
        if(R<mid || R>r)
            continue;
        if(L>mid+1 || L<l)
            continue;
        if(R==mid){
            int want=mid-L;
            return u.second.first[want];
        }
        if(L==mid+1){
            int want=R-mid-1;
            return u.second.second[want];
        }
        int lwant=mid-L;
        int rwant=R-mid-1;
        return Secret(u.second.first[lwant],u.second.second[rwant]);
    }
    assert(false);
}

void Init(int N, int A[]){
    for(int i=0;i<N;i++)
        a[i+1]=A[i];
    build(1,N);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 191 ms 2460 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 193 ms 2452 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 196 ms 2472 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 610 ms 4448 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 603 ms 4476 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 755 ms 4448 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 511 ms 4444 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 520 ms 4388 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 535 ms 4448 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 538 ms 4492 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1