답안 #41568

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
41568 2018-02-19T07:52:52 Z funcsr 비밀 (JOI14_secret) C++14
100 / 100
624 ms 12536 KB
#include "secret.h"
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(x) x.begin(), x.end()
#define uniq(x) x.erase(unique(all(x)), x.end())
#define index(x, y) (int)(lower_bound(all(x), y) - x.begin())
#define pb push_back
#define MAX_N (1<<10)
int N;
int A[1000];
int Tleft[1000][1000], Tright[1000][1000];
void precalc(int l, int r) {
  if (l == r) return;
  int mid = (l+r)/2;
  Tleft[mid][mid] = A[mid];
  for (int x=mid-1; x>=l; x--) Tleft[mid][x] = Secret(A[x], Tleft[mid][x+1]);
  Tright[mid][mid+1] = A[mid+1];
  for (int x=mid+2; x<=r; x++) Tright[mid][x] = Secret(Tright[mid][x-1], A[x]);

  precalc(l, mid);
  precalc(mid+1, r);
}
int f(int l, int r, int a, int b) {
  if (l == r) return A[l];
  int mid = (l+r)/2;
  if (a <= mid && mid <= b) {
    int x = Tleft[mid][a];
    if (mid < b) x = Secret(x, Tright[mid][b]);
    return x;
  }
  if (b < mid) return f(l, mid, a, b);
  else return f(mid+1, r, a, b);
}

void Init(int NN, int AA[]) {
  N = NN;
  rep(i, N) A[i] = AA[i];
  precalc(0, N-1);
}

int Query(int L, int R) {
  return f(0, N-1, L, R);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 171 ms 6392 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 176 ms 6496 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 184 ms 6548 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 594 ms 12388 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 624 ms 12448 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 602 ms 12448 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 616 ms 12448 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 610 ms 12448 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 598 ms 12536 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 596 ms 12536 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1