Submission #639912

# Submission time Handle Problem Language Result Execution time Memory
639912 2022-09-12T16:48:54 Z ghostwriter Secret (JOI14_secret) C++14
100 / 100
446 ms 8264 KB
#include "secret.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debug.h>
#include "grader.cpp"
#endif
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define mtp make_tuple
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
typedef long long ll; typedef unsigned long long ull;
typedef double db; typedef long double ldb;
typedef pair<int, int> pi; typedef pair<ll, ll> pll;
typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll;
typedef string str;
template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
#define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
#define EACH(i, x) for (auto &(i) : (x))
#define WHILE while
#define file "TEST"
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); }
/*
    Tran The Bao
    CTL - Da Lat
    Cay ngay cay dem nhung deo duoc cong nhan
*/
const int MAXN = 1000;
int n, d[MAXN][MAXN];
void build(int l, int r, int a[]) {
    if (l == r) {
        d[l][l] = a[l];
        return;
    }
    int mid = (l + r) / 2;
    FOR(i, mid + 1, r)
        if (i == mid + 1) d[i][i] = a[i];
        else d[mid + 1][i] = Secret(d[mid + 1][i - 1], a[i]);
    FOS(i, mid, l)
        if (i == mid) d[i][i] = a[i];
        else d[i][mid] = Secret(a[i], d[i + 1][mid]);
    build(l, mid, a);
    build(mid + 1, r, a);
}
void Init(int N, int A[]) {
    n = N;
    build(0, N - 1, A);
}
int Query(int L, int R) {
    int l = 0, r = n - 1;
    WHILE(1) {
        int mid = l + (r - l) / 2;
        if (L <= mid && mid <= R) {
            int a = d[L][mid], b = (mid + 1 > R? -1 : d[mid + 1][R]);
            if (b != -1) return Secret(a, b);
            return a;
        }
        if (mid < L) l = mid + 1;
        else r = mid;
    }
    return 0;
}

Compilation message

secret.cpp: In function 'void build(int, int, int*)':
secret.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
secret.cpp:46:5: note: in expansion of macro 'FOR'
   46 |     FOR(i, mid + 1, r)
      |     ^~~
secret.cpp:27:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   27 | #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
      |                               ^
secret.cpp:49:5: note: in expansion of macro 'FOS'
   49 |     FOS(i, mid, l)
      |     ^~~
# Verdict Execution time Memory Grader output
1 Correct 127 ms 4460 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 127 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 120 ms 4300 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 438 ms 8244 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 446 ms 8080 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 442 ms 8148 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 435 ms 8228 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 438 ms 8144 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 427 ms 8264 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 443 ms 8220 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1