답안 #383885

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
383885 2021-03-30T23:58:24 Z JerryLiu06 비밀 (JOI14_secret) C++11
100 / 100
536 ms 4460 KB
#include <bits/stdc++.h>
#include "secret.h"

using namespace std;

int dat[10][1010], mask[1010], A[1010];

void divide(int L, int R, int lev, int A[]) {
    if (L == R) return ; int mid = (L + R) / 2;

    dat[lev][mid] = A[mid]; for (int i = mid - 1; i >= L; i--) dat[lev][i] = Secret(A[i], dat[lev][i + 1]);
    dat[lev][mid + 1] = A[mid + 1]; for (int i = mid + 2; i <= R; i++) dat[lev][i] = Secret(dat[lev][i - 1], A[i]);

    for (int i = mid + 1; i <= R; i++) mask[i] ^= (1 << lev);

    divide(L, mid, lev + 1, A); divide(mid + 1, R, lev + 1, A);
}
void Init(int N, int arr[]) { for (int i = 0; i < N; i++) A[i] = arr[i]; divide(0, N - 1, 0, A); }

int Query(int L, int R) { if (L == R) return A[L];
    int lev = __builtin_ctz(mask[L] ^ mask[R]); return Secret(dat[lev][L], dat[lev][R]);
}

Compilation message

secret.cpp: In function 'void divide(int, int, int, int*)':
secret.cpp:9:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
    9 |     if (L == R) return ; int mid = (L + R) / 2;
      |     ^~
secret.cpp:9:26: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
    9 |     if (L == R) return ; int mid = (L + R) / 2;
      |                          ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 143 ms 2412 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 145 ms 2540 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 144 ms 2420 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 499 ms 4332 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 506 ms 4332 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 536 ms 4332 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 507 ms 4448 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 507 ms 4332 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 509 ms 4332 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 513 ms 4460 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1