Submission #502844

# Submission time Handle Problem Language Result Execution time Memory
502844 2022-01-06T16:02:11 Z gozonite Secret (JOI14_secret) C++14
100 / 100
512 ms 4412 KB
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <deque>
#include <queue>
#include <tuple>
#include <cmath>
#include <cctype>
#include <stack>
#include <cassert>
#include "secret.h"
using namespace std;
using ll = long long;

int dat[11][1000];
int mask[1000];
int a[1000];

void build(int l, int r, int A[], int lev) {
    if (l == r) return;
    int mid = (l+r)/2;
    dat[lev][mid] = A[mid]; dat[lev][mid+1] = A[mid+1];
    for (int i = mid-1; i >= l; i--) dat[lev][i] = Secret(A[i], dat[lev][i+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;
    build(l, mid, A, lev+1); build(mid+1, r, A, lev+1);
}

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

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]);
}
# Verdict Execution time Memory Grader output
1 Correct 138 ms 2436 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 136 ms 2480 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 131 ms 2408 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 509 ms 4320 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 488 ms 4412 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 490 ms 4404 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 461 ms 4376 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 512 ms 4392 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 481 ms 4280 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 501 ms 4360 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1