답안 #985753

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
985753 2024-05-18T16:40:44 Z tfgs 비밀 (JOI14_secret) C++17
0 / 100
397 ms 4624 KB
#include "secret.h"
#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9;

#ifdef LOCAL
#include "algo/debug.h"
#endif

#define f first
#define s second
template<class T> using V = vector<T>; 
using vi = V<int>;
using vb = V<bool>;
using vs = V<string>;

#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x) 
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T> int lwb(V<T>& a, const T& b) { return lb(all(a),b)-bg(a); }
template<class T> int upb(V<T>& a, const T& b) { return ub(all(a),b)-bg(a); }

const int max_n = 1000, max_bit = 10;
int dat[max_bit][max_n+1];
int mask[max_n];
int n, a[max_n];
void precalc(int l, int r, int lvl) {
    if (l == r-1) return;
    int m = (l+r)/2;
    dat[lvl][m] = inf;
    dat[lvl][m-1] = a[m-1];
    dat[lvl][m+1] = a[m];
    for (int i = m-2; i >= l; i--) dat[lvl][i] = Secret(dat[lvl][i+1], a[i]);
    for (int i = m+2; i < r; i++) dat[lvl][i] = Secret(dat[lvl][i-1], a[i]);
    for (int i = m; i < r; i++) mask[i] |= 1<<lvl;
    precalc(l, m, lvl+1);
    precalc(m, r, lvl+1);
}

void Init(int N, int A[]) {
    n = N;
    for (int i = 0; i < N; i++) a[i] = A[i];
    precalc(0, n, 0);
}

int Query(int L, int R) {
    R++;
    if (L == R-1) return a[L];
    if (R == n) {
        int tz = __builtin_ctz(~mask[L]);
        return Secret(dat[tz][L], dat[tz][n]);
    }
    int tz = __builtin_ctz(mask[L]^mask[R]);
    int ans = dat[tz][L];
    if (dat[tz][R] != inf) ans = Secret(ans, dat[tz][R]);
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 102 ms 2808 KB Wrong Answer: Query(222, 254) - expected : 34031541, actual : 34607541.
2 Incorrect 101 ms 2812 KB Wrong Answer: Query(60, 375) - expected : 669221184, actual : 245445024.
3 Incorrect 109 ms 2808 KB Wrong Answer: Query(211, 401) - expected : 674373968, actual : 143003988.
4 Incorrect 374 ms 4352 KB Wrong Answer: Query(90, 497) - expected : 397934825, actual : 16302203.
5 Incorrect 375 ms 4624 KB Wrong Answer: Query(587, 915) - expected : 752404486, actual : 488148290.
6 Incorrect 373 ms 4352 KB Wrong Answer: Query(738, 741) - expected : 983692994, actual : 850129153.
7 Incorrect 375 ms 4484 KB Wrong Answer: Query(84, 976) - expected : 742463504, actual : 30084216.
8 Incorrect 373 ms 4356 KB Wrong Answer: Query(58, 987) - expected : 20022464, actual : 29729984.
9 Incorrect 397 ms 4468 KB Wrong Answer: Query(33, 967) - expected : 676869696, actual : 819334665.
10 Incorrect 373 ms 4348 KB Wrong Answer: Query(116, 961) - expected : 68487362, actual : 611033094.