Submission #957998

# Submission time Handle Problem Language Result Execution time Memory
957998 2024-04-04T15:39:57 Z wksp Secret (JOI14_secret) C++14
100 / 100
392 ms 5548 KB
#include<bits/stdc++.h>
#include "secret.h"
using namespace std;

// int Secret(int X, int Y){
//     int a;
//     cin >> a;
//     return a;
// }
const int n_max = 1024;
const int logn = 12;
int tab[logn][n_max];
// int tabr[log][n_max];
map<pair<int, int>, int> result_in_past; 

int check(int a, int b){
    if(result_in_past.find({a, b}) != result_in_past.end()){
        return result_in_past[{a, b}];
    }else{
        int x = Secret(a, b);
        result_in_past[{a, b}] = x;
        return x;
    }
}

void init_tree(int n, int lvl = 10, int l = 0, int r = n_max - 1){
    if(l > n){
        return;
    }
    if(lvl == 0){
        return;
    }
    int mid = (l+r)/2;
    init_tree(n, lvl - 1, l, mid);
    init_tree(n, lvl - 1, mid + 1, r);
    if(mid >= n){
        return;
    }

    tab[lvl][mid] = tab[0][mid];
    for(int i = mid - 1; i >= l; i--){
        tab[lvl][i] = check(tab[0][i], tab[lvl][i+1]);
    }
    tab[lvl][mid + 1] = tab[0][mid+1];
    for(int i = mid + 2; i <= min(n, r); i++){
        tab[lvl][i] = check(tab[lvl][i-1], tab[0][i]);
    }
}

int find_in_tree(int a, int b, int lvl = 10, int l = 0, int r = n_max - 1){
    int mid = (l+r)/2;
    if(b <= mid){
        return find_in_tree(a, b, lvl - 1, l, mid);
    }
    if(a > mid){
        return find_in_tree(a, b, lvl - 1, mid + 1, r);
    }
    //return lvl;
    return check(tab[lvl][a], tab[lvl][b]);
}

void Init(int N, int A[]){
    for(int i = 0; i < N; i++){
        tab[0][i] = A[i];
    }
    init_tree(N);
}

int Query(int L, int R){
    if(L == R){
        return tab[0][L];
    }
    return find_in_tree(L, R);
}
# Verdict Execution time Memory Grader output
1 Correct 108 ms 3408 KB Output is correct - number of calls to Secret by Init = 3332, maximum number of calls to Secret by Query = 1
2 Correct 113 ms 3496 KB Output is correct - number of calls to Secret by Init = 3842, maximum number of calls to Secret by Query = 1
3 Correct 115 ms 3576 KB Output is correct - number of calls to Secret by Init = 3843, maximum number of calls to Secret by Query = 1
4 Correct 388 ms 5544 KB Output is correct - number of calls to Secret by Init = 7488, maximum number of calls to Secret by Query = 1
5 Correct 381 ms 5548 KB Output is correct - number of calls to Secret by Init = 7499, maximum number of calls to Secret by Query = 1
6 Correct 388 ms 5392 KB Output is correct - number of calls to Secret by Init = 7499, maximum number of calls to Secret by Query = 1
7 Correct 377 ms 5544 KB Output is correct - number of calls to Secret by Init = 7499, maximum number of calls to Secret by Query = 1
8 Correct 383 ms 5540 KB Output is correct - number of calls to Secret by Init = 7499, maximum number of calls to Secret by Query = 1
9 Correct 378 ms 5524 KB Output is correct - number of calls to Secret by Init = 7499, maximum number of calls to Secret by Query = 1
10 Correct 392 ms 5544 KB Output is correct - number of calls to Secret by Init = 7499, maximum number of calls to Secret by Query = 1