제출 #1332411

#제출 시각아이디문제언어결과실행 시간메모리
1332411rana_azka비밀 (JOI14_secret)C++20
30 / 100
393 ms4420 KiB
#include "secret.h"
#include <bits/stdc++.h>
using namespace std;

const int INF = 1e9;
const int MAXN = 1e3;
const int MAXLog = log2(MAXN) + 1;

#define md ((lf+rg)/2)
#define lc (pos*2)
#define rc (pos*2+1)

int n, m;
int arr[MAXN+5];
int segtree[4*MAXN+5];

int merge(int a, int b){
  return Secret(a, b);
}

void build(int lf, int rg, int pos){
  if(lf == rg){
    segtree[pos] = arr[lf];
    return ;
  }
  
  build(lf, md, lc);
  build(md+1, rg, rc);

  segtree[pos] = merge(segtree[lc], segtree[rc]);
}

int res = -1;
void query(int ql, int qr, int lf, int rg, int pos){
  if(rg < ql || qr < lf) return ;

  if(ql <= lf && rg <= qr){
    if(res == -1) res = segtree[pos];
    else res = merge(res, segtree[pos]);
    // cerr << "hah : " << lf << ' ' << rg << " -> " << res << endl;
    return ;
  }
  
  query(ql, qr, lf, md, lc);
  query(ql, qr, md+1, rg, rc);
}

void Init(int N, int A[]) {
  n = N;
  for(int i = 1; i <= n; i++) arr[i] = A[i-1];

  build(1, n, 1);  
}

int Query(int L, int R) {
  int l = L + 1, r = R + 1;

  res = -1;
  query(l, r, 1, n, 1);
  int ans = res;

  return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...