Submission #656657

# Submission time Handle Problem Language Result Execution time Memory
656657 2022-11-08T03:14:06 Z CDuong Secret (JOI14_secret) C++17
100 / 100
524 ms 8352 KB
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
*/
#include <bits/stdc++.h>
#include "secret.h"
#define taskname "bai3"
#define all(x) x.begin(), x.end()
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int, int>
using namespace std;
const int mxN = 1e3 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
int n, a[mxN], pref[4 * mxN][mxN];
void build(int l, int r, int idx, int dir) {
    if(l == r) {
        pref[idx][1] = a[l];
        return;
    }
    if(l == r - 1) {
        if(dir) pref[idx][1] = a[l];
        else pref[idx][1] = a[r];
        pref[idx][2] = Secret(a[l], a[r]);
        return;
    }
    int mid = (l + r) >> 1;
    build(l, mid, idx * 2, 0);
    build(mid + 1, r, idx * 2 + 1, 1);
    if(l == 1 && r == n) return;
    if(dir) {
        pref[idx][1] = a[l];
        for(int i = 2; i <= (r - l + 1); ++i) pref[idx][i] = Secret(pref[idx][i - 1], a[l + i - 1]);
        return;
    }
    pref[idx][1] = a[r];
    for(int i = 2; i <= (r - l + 1); ++i) pref[idx][i] = Secret(a[r + 1 - i], pref[idx][i - 1]);
}
void Init(int N, int A[]) {
    n = N;
    for(int i = 1; i <= n; ++i) a[i] = A[i - 1];
    build(1, n, 1, 0);
}

int query(int l, int r, int idx, int u, int v) {
    int mid = (l + r) >> 1;
    if(u <= mid && mid <= v) {
        if(v == mid) return pref[idx * 2][v - u + 1];
        int tmp1 = pref[idx * 2][mid - u + 1];
        int tmp2 = pref[idx * 2 + 1][v - mid];
        int ans = Secret(tmp1, tmp2);
        return ans;
    }
    if(mid > v) return query(l, mid, idx * 2, u, v);
    return query(mid + 1, r, idx * 2 + 1, u, v);
}

int Query(int L, int R) {
    ++L; ++R;
    if(L == R) return a[L];
    if(L == R - 1) return Secret(a[L], a[R]);
    return query(1, n, 1, L, R);
}
# Verdict Execution time Memory Grader output
1 Correct 133 ms 4372 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 154 ms 4288 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 143 ms 4372 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 485 ms 8192 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 524 ms 8348 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 488 ms 8352 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 500 ms 8296 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 453 ms 8276 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 494 ms 8280 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 478 ms 8272 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1