Submission #1271962

#TimeUsernameProblemLanguageResultExecution timeMemory
1271962DaciejMaciejSecret (JOI14_secret)C++20
0 / 100
326 ms4500 KiB
#include <bits/stdc++.h>
#include "secret.h"

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/rope>

using namespace std;
// using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;

template <class T>

using VV = vector<vector<T>>;

using VI = vector<int>;
using VVI = vector<vector<int>>;

using VL = vector<long long>;
using VVL = vector<vector<long long>>;

using VC = vector<char>;
using VVC = vector<vector<char>>;

using VB = vector<bool>;
using VVB = vector<vector<bool>>;

using VD = vector<double>;
using VVD = vector<vector<double>>;

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using PIL = pair<int, long long>;
using PLI = pair<long long, int>;

using VPII = vector<pair<int, int>>;
using VPLL = vector<pair<long long, long long>>;

#define LINE '\n'
#define SPACE ' '
#define PB push_back
#define FOR(i, a, b) for (int i = (a); i < (int(b)); i++)
#define FORE(i, a, b) for (int i = (a); i <= (int)((b)); i++)
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
#define sq(a) ((a) * (a))
#define sz(x) ((int)x.size())

#define fastio()                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(nullptr);                 \
    cout.tie(nullptr)
#define debug(x) cerr << #x << " = " << x << endl;

const ll MOD = 1e9 + 7;

template <class T>
inline void maxi(T &a, T b)
{
    a = max(a, b);
}

template <class T>
inline void mini(T &a, T b)
{
    a = min(a, b);
}

template <class T>
inline void addi(T &a, T b)
{
    a = (a + b) % MOD;
}

template <class T>
inline void subi(T &a, T b)
{
    a = (a - b + MOD) % MOD;
}

template <class T>
inline T add(T a, T b)
{
    return (a + b) % MOD;
}

template <class T>
inline T sub(T a, T b)
{
    return (a - b + MOD) % MOD;
}

template <class T>
inline T mul(T a, T b)
{
    return ((a % MOD) * (b % MOD)) % MOD;
}

constexpr ll binpow(ll a, ll b, ll mod)
{
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
        {
            res = (res * a) % mod;
        }
        a = (a * a) % mod;
        b >>= 1;
    }

    return res;
}

const int INF = 1e9;

const int MAX_N = 2e5 + 3;

int n;

int dat[18][MAX_N];
int mask[MAX_N];
int *arr;

void divi(int l, int r, int lev)
{
    if (l == r)
        return;
    int m = (l + r) / 2;

    dat[lev][m] = arr[m];
    for (int i = m - 1; i >= l; i--)
        dat[lev][i] = min(arr[i], dat[lev][i + 1]);

    dat[lev][m + 1] = arr[m + 1];
    for (int i = m + 2; i <= r; i++)
        dat[lev][i] = min(dat[lev][i - 1], arr[i]);

    FOR(i, m + 1, r + 1)
    {
        mask[i] ^= 1 << lev;
    }

    divi(l, m, lev + 1);
    divi(m + 1, r, lev + 1);
}

void Init(int N, int A[])
{
    n = N;
    arr = A;
    divi(0, n - 1, 0);
}

int Query(int L, int R)
{
    if(L == R) return arr[L];


    int bits = __builtin_ctz(mask[L] ^ mask[R]);
    int ans = Secret(dat[bits][L], dat[bits][R]);
    return ans;
}



#Verdict Execution timeMemoryGrader output
Fetching results...