Submission #407653

# Submission time Handle Problem Language Result Execution time Memory
407653 2021-05-19T04:14:35 Z kwongweng Secret (JOI14_secret) C++17
100 / 100
678 ms 98316 KB
#include "secret.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long double ld;
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define ms memset
#define pb push_back
#define F first
#define S second

vi arr[4000][1000];
int n;
vi a(1000);

void build(int v, int l, int r){
    if (l == r){
        arr[v][l].pb(a[l]); return;
    }
    int m = (l+r)/2;
    arr[v][m].pb(a[m]);
    int cnt = 0;
    ROF(i, m-1, l){
        arr[v][m].pb(Secret(a[i], arr[v][m][cnt]));
        cnt++;
    }
    arr[v][m+1].pb(a[m+1]);
    cnt = 0;
    FOR(i, m+2, r+1){
        arr[v][m+1].pb(Secret(arr[v][m+1][cnt], a[i]));
        cnt++;
    }
    build(2*v, l, m);
    build(2*v+1, m+1, r);
}

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

int query(int v, int tl, int tr, int l, int r){
    int tm = (tl + tr) / 2;
    if (l > tm+1) return query(2*v+1, tm+1, tr, l, r);
    if (r < tm) return query(2*v, tl, tm, l, r);
    if (l == tm+1) return arr[v][l][r-l];
    if (r == tm) return arr[v][r][r-l];
    return Secret(arr[v][tm][tm-l], arr[v][tm+1][r-tm-1]);
}
int Query(int L, int R) {
    return query(1, 0, n-1, L, R);
}
# Verdict Execution time Memory Grader output
1 Correct 216 ms 96324 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 201 ms 96276 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 216 ms 96360 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 630 ms 98268 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 598 ms 98244 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 678 ms 98256 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 597 ms 98316 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 615 ms 98264 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 640 ms 98268 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 612 ms 98212 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1