Submission #242436

# Submission time Handle Problem Language Result Execution time Memory
242436 2020-06-27T16:29:26 Z AM1648 Secret (JOI14_secret) C++17
100 / 100
520 ms 4600 KB
/* be name khoda */

// #define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <vector>
#include <fstream>
#include <set>
#include <map>
#include "secret.h"
using namespace std;

#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif

typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;

#define forifrom(i, s, n) for (ll i = s; i < n; ++i)
#define forirto(i, n, e) for (ll i = (n) - 1; i >= e; --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))

#define debug(x) cout << #x << " -> " << (x) << endl
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl

const ll MOD = 1000000007;
const ll INF = 2000000000;
const long long BIG = 1446803456761533460LL;

#define XL (x << 1)
#define XR (XL | 1)
#define MD ((l + r) >> 1)
#define Add(a, b) a = ((a) + (b)) % MOD
#define Mul(a, b) a = (1LL * (a) * (b)) % MOD

// -----------------------------------------------------------------------

const ll maxn = 1002;
const ll maxnlg = 10;

ll n, A[maxn];
ll pre[maxnlg][maxn];

void calc(ll h, ll l, ll r) {
    if (r - l <= 2) return;
    ll mid = (l + r) / 2;
    pre[h][mid] = A[mid], pre[h][mid - 1] = A[mid - 1];
    forifrom (i, mid + 1, r) pre[h][i] = Secret(pre[h][i - 1], A[i]);
    forirto (i, mid - 1, l) pre[h][i] = Secret(A[i], pre[h][i + 1]);
    calc(h + 1, l, mid);
    calc(h + 1, mid, r);
}

ll find(ll L, ll R, ll h = 0, ll l = 0, ll r = n) {
    ll mid = (l + r) / 2;
    if (R <= mid) return find(L, R, h + 1, l, mid);
    else if (L >= mid) return find(L, R, h + 1, mid, r);
    else return Secret(pre[h][L], pre[h][R - 1]);
}

void Init(ll N, ll I[]) {
    n = N;
    fori (i, n) A[i] = I[i];
    calc(0, 0, n);
}

ll Query(ll l, ll r) {
    ++r;
    if (r - l == 1) return A[l];
    else if (r - l == 2) return Secret(A[l], A[l + 1]);
    else return find(l, r);
}

# Verdict Execution time Memory Grader output
1 Correct 152 ms 2552 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 158 ms 2552 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 150 ms 2552 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 510 ms 4448 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 516 ms 4448 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 4600 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 514 ms 4396 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 511 ms 4436 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 508 ms 4472 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 520 ms 4400 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1