Submission #274487

# Submission time Handle Problem Language Result Execution time Memory
274487 2020-08-19T12:19:00 Z Falcon Secret (JOI14_secret) C++14
100 / 100
541 ms 8440 KB
#pragma GCC optimize("O2")

#include "secret.h"
#include <bits/stdc++.h>
#ifdef DEBUG
    #include "debug.hpp"
#endif

using namespace std;

#define all(c) (c).begin(), (c).end()
#define traverse(c, it) for(auto it = (c).begin(); it != (c).end(); it++)
#define rep(i, N) for(int i = 0; i < (N); i++)
#define rep1(i, N) for(int i = 1; i <= (N); i++)
#define rep2(i, s, e) for(int i = (s); i <= (e); i++)
#define rep3(i, s, e, d) for(int i = (s); (d) >= 0 ? i <= (e) : i >= (e); i += (d))
#define pb push_back


#ifdef DEBUG
    #define debug(x...) {dbg::depth++; string dbg_vals = dbg::to_string(x); dbg::depth--; dbg::fprint(__func__, __LINE__, #x, dbg_vals);}
    #define light_debug(x) {dbg::light = 1; dbg::dout << __func__ << ":" << __LINE__ << "  " << #x << " = " << x << endl; dbg::light = 0;}
#else
    #define debug(x...)
    #define light_debug(x) 
#endif

template<typename T>
T& ckmin(T& a, T b){ return a = a > b ? b : a; }

template<typename T>
T& ckmax(T& a, T b){ return a = a < b ? b : a; }

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

vi A;
int ans[1000][1001];

void build(int l, int r){
    if(l == r) return;
    if(r - l <= 1) return void(ans[l][r] = A[l]);
    int m = (l + r) >> 1;
    build(l, m);
    build(m, r);
    ans[m][m + 1] = A[m];
    ans[m - 1][m] = A[m - 1];
    rep2(i, m + 2, r)
        ans[m][i] = Secret(ans[m][i - 1], A[i - 1]);
    rep3(i, m - 2, l, -1)
        ans[i][m] = Secret(A[i], ans[i + 1][m]);
}

int qry(int l, int r, int L, int R){
    int m = (l + r) >> 1;
    if(m < L) return qry(m, r, L, R);
    if(m > R) return qry(l, m, L, R);
    if(m == L || m == R) return ans[L][R];
    return Secret(ans[L][m], ans[m][R]);
}

void Init(int N, int B[]){
    A.resize(N);
    rep(i, N) A[i] = B[i];
    build(0, N);
}

int Query(int L, int R){
    return qry(0, A.size(), L, R + 1);
}
# Verdict Execution time Memory Grader output
1 Correct 150 ms 4600 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 148 ms 4472 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 148 ms 4472 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 524 ms 8440 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 541 ms 8312 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 519 ms 8312 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 532 ms 8340 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 537 ms 8356 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 522 ms 8312 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 528 ms 8392 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1