답안 #796081

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
796081 2023-07-28T06:02:19 Z Sandarach151 비밀 (JOI14_secret) C++17
100 / 100
395 ms 4468 KB
#include <bits/stdc++.h>
#include "secret.h"
using namespace std;
 
int n;
vector<int> a;
vector<vector<int>> lef, rig;
 
void Init(int N, int A[]) {
  n = N;
  a.resize(N);
  for (int i = 0; i < N; ++i) a[i] = A[i];
  lef.resize(N); rig.resize(N);
  queue<pair<int, int>> q;
  q.push({0, n - 1});
  while (!q.empty()) {
    int l = q.front().first, r = q.front().second;
    q.pop();
    int m = (l + r) / 2;
    lef[m].push_back(A[m]);
    for (int i = 1; i <= (m - l); ++i) {
      lef[m].push_back(Secret(A[m - i], lef[m].back()));
    }
    if (m + 1 < N) {
      rig[m].push_back(A[m + 1]);
      for (int i = 2; i <= (r - m); ++i) {
        rig[m].push_back(Secret(rig[m].back(), A[m + i]));
      }
    }
    if (l == r) continue;
    q.push({l, m});
    q.push({m + 1, r});
  }
}
 
int Query(int L, int R) {
  if (L == R) return a[L];
  int l = 0, r = n - 1;
  while (true) {
    int m = (l + r) / 2;
    if (R <= m) {
      r = m;
    } else if (L > m) {
      l = m + 1;
    } else {
      return Secret(lef[m][m - L], rig[m][R - m - 1]);
    }
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 2380 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 103 ms 2452 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 105 ms 2432 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 362 ms 4388 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 367 ms 4380 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 361 ms 4468 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 365 ms 4372 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 372 ms 4336 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 388 ms 4408 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 395 ms 4424 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1