Submission #796070

# Submission time Handle Problem Language Result Execution time Memory
796070 2023-07-28T05:47:03 Z Sandarach151 Secret (JOI14_secret) C++17
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
#include "secret.h"
using namespace std;
 
class SparseTable {
private:
    vector<vector<long long>> table;
    vector<long long> arr;
    long long sze;
    long long logSze;
 
    void build(long long depth, long long left, long long right) {
        if (left == right) {
            return;
        } else {
            long long mid = (left + right) / 2;
            table[depth][mid] = arr[mid];
            for (long long i = mid - 1; i >= left; i--) {
                table[depth][i] = Secret(table[depth][i + 1], arr[i]);
            }
            table[depth][mid + 1] = arr[mid + 1];
            for (long long i = mid + 2; i <= right; i++) {
                table[depth][i] = Secret(table[depth][i - 1], arr[i]);
            }
            build(depth + 1, left, mid);
            build(depth + 1, mid + 1, right);
        }
    }
 
    long long privQuery(long long depth, long long queryLeft, long long queryRight, long long posLeft, long long posRight) {
        if (queryLeft > posRight || queryRight <= posLeft) {
            return 0;
        }
        long long mid = (posLeft + posRight) / 2;
        if (queryRight == mid) {
            return table[depth][queryLeft];
        } else if (queryLeft == mid + 1) {
            return table[depth][queryRight];
        } else {
            if (queryLeft <= mid && queryRight >= mid + 1) {
                return Secret(table[depth][queryLeft], table[depth][queryRight]);
            } else {
                if (queryLeft >= mid + 1) {
                    return privQuery(depth + 1, queryLeft, queryRight, mid + 1, posRight);
                } else {
                    return privQuery(depth + 1, queryLeft, queryRight, posLeft, mid);
                }
            }
        }
    }
 
public:
    SparseTable(vector<long long>& vect) {
        sze = vect.size();
        logSze = ceil(log2(sze)) + 1;
        arr.resize(sze);
        for (long long i = 0; i < (long long)vect.size(); i++) {
            arr[i] = vect[i];
        }
        table.resize(logSze, vector<long long>(sze, 0)); // Initialize the table with 0s
        build(0, 0, sze - 1);
    }
 
    long long query(long long left, long long right) {
        return privQuery(0, left, right, 0, sze - 1);
    }
};
 
SparseTable* temp;
vector<long long> array2;
 
void Init(long long N, long long A[]) {
    vector<long long> vect(N);
    array2.resize(vect.size());
    for (long long i = 0; i < N; i++) {
        vect[i] = A[i];
        array2[i] = A[i];
    }
    temp = new SparseTable(vect);
}
 
long long Query(long long L, long long R) {
    if (L == R) return array2[L];
    return temp->query(L, R);
}

Compilation message

/usr/bin/ld: /tmp/ccn3uOjW.o: in function `main':
grader-full.cpp:(.text.startup+0x2a8): undefined reference to `Init(int, int*)'
/usr/bin/ld: grader-full.cpp:(.text.startup+0x30b): undefined reference to `Query(int, int)'
collect2: error: ld returned 1 exit status