Submission #965102

# Submission time Handle Problem Language Result Execution time Memory
965102 2024-04-18T06:47:02 Z Esgeer Secret (JOI14_secret) C++17
100 / 100
413 ms 4532 KB
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <unistd.h>
using namespace __gnu_pbds;
template <class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#ifndef Local
    #pragma GCC optimize("O3,unroll-loops")
#endif
//#define int long long
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpi vector<pii>
#define vvpi vector<vpi>
#define vb vector<bool>
#define vvb vector<vb>
#define endl '\n'
#define sp << " " <<
#define F(i, s, n) for(int i = s; i < (int) n; i++)
#define pb push_back
#define fi first
#define se second

#include "secret.h"

int mod = 1e9+7;
int inf = 1e6;
const int N = 1005;
int dat[11][N];
int mask[N];
int a[N];

void divi(int l, int r, int layer) {
    if(l == r) return;
    int m = (l + r) >> 1;
    dat[layer][m] = a[m];
    for(int i = m-1; i >= l; i--) dat[layer][i] = Secret(a[i], dat[layer][i+1]);
    dat[layer][m+1] = a[m+1];
    for(int i = m+2; i <= r; i++) dat[layer][i] = Secret(dat[layer][i-1], a[i]);
    for(int i = m+1; i <= r; i++) mask[i] ^= (1 << layer);
    divi(l, m, layer+1);
    divi(m+1, r, layer+1);
}

void Init(int N, int A[]) {
  F(i, 0, N) a[i] = A[i];
  divi(0, N-1, 0);
}

int Query(int l, int r) {
  if(l == r) return a[l];
  int layer = __builtin_ctz(mask[l] ^ mask[r]);
  return Secret(dat[layer][l], dat[layer][r]);
}
# Verdict Execution time Memory Grader output
1 Correct 111 ms 2652 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 112 ms 2808 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 109 ms 2804 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 402 ms 4352 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 392 ms 4372 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 409 ms 4356 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 403 ms 4436 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 413 ms 4532 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 399 ms 4344 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 398 ms 4460 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1