Submission #957984

# Submission time Handle Problem Language Result Execution time Memory
957984 2024-04-04T15:26:33 Z wksp Secret (JOI14_secret) C++14
0 / 100
378 ms 4880 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(r <= mid){
        return find_in_tree(a, b, lvl - 1, l, mid);
    }
    if(l > mid){
        return find_in_tree(a, b, lvl - 1, mid + 1, r);
    }
    return check(tab[lvl][l], tab[lvl][r]);
}

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 Incorrect 102 ms 2824 KB Wrong Answer: Query(222, 254) - expected : 34031541, actual : 536870912.
2 Incorrect 102 ms 2900 KB Wrong Answer: Query(60, 375) - expected : 669221184, actual : 401641632.
3 Incorrect 104 ms 3064 KB Wrong Answer: Query(211, 401) - expected : 674373968, actual : 76914976.
4 Incorrect 377 ms 4864 KB Wrong Answer: Query(90, 497) - expected : 397934825, actual : 909656650.
5 Incorrect 369 ms 4860 KB Wrong Answer: Query(587, 915) - expected : 752404486, actual : 605686794.
6 Incorrect 378 ms 4864 KB Wrong Answer: Query(738, 741) - expected : 983692994, actual : 824886811.
7 Incorrect 367 ms 4768 KB Wrong Answer: Query(84, 976) - expected : 742463504, actual : 95595635.
8 Incorrect 374 ms 4844 KB Wrong Answer: Query(58, 987) - expected : 20022464, actual : 231973200.
9 Incorrect 376 ms 4860 KB Wrong Answer: Query(33, 967) - expected : 676869696, actual : 412627009.
10 Incorrect 375 ms 4880 KB Wrong Answer: Query(116, 961) - expected : 68487362, actual : 607431565.