답안 #222925

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
222925 2020-04-14T10:54:51 Z lyc 비밀 (JOI14_secret) C++14
100 / 100
529 ms 4488 KB
#include "secret.h"
using namespace std;

#define SZ(x) ((int)(x).size())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)

struct DST {
    static const int MX_N = 1024;
    static const int LG_N = 10;
    static const int E = 0;
    static inline int func(int x, int y) { return Secret(x,y); }

    int N, v[LG_N+1][MX_N];

    inline void build(int n, int *a) {
        for (N = 1; N < n; N <<= 1);
        FOR(i,0,n-1) v[0][i] = a[i];
        FOR(i,n,N-1) v[0][i] = E;

        for (int h = 1, seg = 2; seg <= N; ++h, seg <<= 1) {
            for (int i = seg>>1, ss = (seg>>1)-1; i < n; i += seg) {
                v[h][i] = a[i];

                v[h][i-1] = a[i-1];
                FOR(j,1,ss){
                    v[h][i-1-j] = func(a[i-1-j],v[h][i-j]);
                    if (i+j < n) v[h][i+j] = func(v[h][i+j-1],a[i+j]);   // NOT commutative!
                }
            }
        }
    }

    int query(int i, int j) {
        if (i == j) return v[0][i];
        int h = (31-__builtin_clz(i^j)) + 1; // MSB + 1
        return func(v[h][i],v[h][j]);
    }
} dst;

void Init(int N, int A[]) {
    dst.build(N,A);
}

int Query(int L, int R) {
    return dst.query(L,R);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 148 ms 2552 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 150 ms 2552 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 152 ms 2528 KB Output is correct - number of calls to Secret by Init = 4097, maximum number of calls to Secret by Query = 1
4 Correct 509 ms 4472 KB Output is correct - number of calls to Secret by Init = 7979, maximum number of calls to Secret by Query = 1
5 Correct 525 ms 4488 KB Output is correct - number of calls to Secret by Init = 7986, maximum number of calls to Secret by Query = 1
6 Correct 529 ms 4384 KB Output is correct - number of calls to Secret by Init = 7986, maximum number of calls to Secret by Query = 1
7 Correct 516 ms 4464 KB Output is correct - number of calls to Secret by Init = 7986, maximum number of calls to Secret by Query = 1
8 Correct 519 ms 4472 KB Output is correct - number of calls to Secret by Init = 7986, maximum number of calls to Secret by Query = 1
9 Correct 512 ms 4344 KB Output is correct - number of calls to Secret by Init = 7986, maximum number of calls to Secret by Query = 1
10 Correct 528 ms 4460 KB Output is correct - number of calls to Secret by Init = 7986, maximum number of calls to Secret by Query = 1