Submission #952529

# Submission time Handle Problem Language Result Execution time Memory
952529 2024-03-24T07:35:44 Z Whisper Secret (JOI14_secret) C++17
100 / 100
403 ms 8600 KB
#include <bits/stdc++.h>
#include <secret.h>
using namespace std;
using ll = long long;

//#define int long long
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FORD(i, a, b) for (int i = b; i >= a; i --)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPD(i, n) for (int i = n - 1; i >= 0; --i)

#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)

constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//void setupIO(){
//    #define name "Whisper"
//    //Phu Trong from Nguyen Tat Thanh High School for gifted student
//    srand(time(NULL));
//    cin.tie(nullptr)->sync_with_stdio(false); cout.tie(nullptr);
//    freopen(name".inp", "r", stdin);
//    freopen(name".out", "w", stdout);
//    cout << fixed << setprecision(10);
//}

template <class X, class Y>
    bool minimize(X &x, const Y &y){
        X eps = 1e-9;
        if (x > y + eps) {x = y; return 1;}
        return 0;
    }

template <class X, class Y>
    bool maximize(X &x, const Y &y){
        X eps = 1e-9;
        if (x + eps < y) {x = y; return 1;}
        return 0;
    }
vector<int> a;
int nArr;
vector<vector<int>> sum;
//int Secret(int lx, int rx){
//    return (lx + rx);
//}
void dnc(int lx, int rx) {
    if (lx == rx) {
        sum[lx][lx] = a[lx];
        return;
    }

    if (lx > rx)
        return;

    int m = (lx + rx) / 2;

    sum[m][m] = a[m];
    sum[m + 1][m + 1] = a[m + 1];

    for (int i = m - 1; i >= lx; i--)
        sum[i][m] = Secret(a[i], sum[i + 1][m]);

    for (int i = m + 2; i <= rx; i++)
        sum[m + 1][i] = Secret(sum[m + 1][i - 1], a[i]);

    dnc(lx, m - 1);
    dnc(m + 1, rx);
}
void Init(int N, int A[]){
    a.resize(N);
    sum.resize(N, vector<int>(N));
    nArr = N;
    for (int i = 0; i < N; ++i) a[i] = A[i];
    dnc(0, nArr - 1);
}
int Get(int lx, int rx, int l, int r) {
    int m = (lx + rx) / 2;

    if (l <= m && m + 1 <= r) {
        return Secret(sum[l][m], sum[m + 1][r]);
    }

    if (r <= m)
        return Get(lx, m - 1, l, r);

    return Get(m + 1, rx, l, r);
}

int Query(int l, int r){
    return (l == r ? a[l] : Get(0, nArr - 1, l, r));
}
//void Whisper(){
//    int a[8] = {1, 4, 7, 2, 5, 8, 3, 6};
//    Init(8, a);
//    cout << "CASE 1: " << Query(0, 3) << '\n';
//    cout << "CASE 2: " << Query(1, 7) << '\n';
//    cout << "CASE 3: " << Query(5, 5) << '\n';
//    cout << "CASE 4: " << Query(2, 4) << '\n';
//}
//
//
//signed main(){
//    setupIO();
//    int Test = 1;
////    cin >> Test;
//    for ( int i = 1 ; i <= Test ; i++ ){
//        Whisper();
//        if (i < Test) cout << '\n';
//    }
//}


# Verdict Execution time Memory Grader output
1 Correct 109 ms 3752 KB Output is correct - number of calls to Secret by Init = 3331, maximum number of calls to Secret by Query = 1
2 Correct 103 ms 3760 KB Output is correct - number of calls to Secret by Init = 3339, maximum number of calls to Secret by Query = 1
3 Correct 104 ms 3668 KB Output is correct - number of calls to Secret by Init = 3347, maximum number of calls to Secret by Query = 1
4 Correct 376 ms 8600 KB Output is correct - number of calls to Secret by Init = 7467, maximum number of calls to Secret by Query = 1
5 Correct 385 ms 8368 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1
6 Correct 386 ms 8456 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1
7 Correct 367 ms 8204 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1
8 Correct 403 ms 8360 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1
9 Correct 372 ms 8360 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1
10 Correct 379 ms 8364 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1