Submission #41567

# Submission time Handle Problem Language Result Execution time Memory
41567 2018-02-19T07:39:44 Z funcsr Secret (JOI14_secret) C++14
100 / 100
618 ms 12628 KB
#include "secret.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
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)
typedef pair<int, int> P;
int seg[MAX_N*2-1];
map<P, int> mp;
int ask(int x, int y) {
  if (mp.find(P(x, y)) != mp.end()) return mp[P(x, y)];
  return mp[P(x, y)] = Secret(x, y);
}
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);
}
# Verdict Execution time Memory Grader output
1 Correct 169 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 186 ms 6544 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 173 ms 6568 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 618 ms 12400 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 600 ms 12472 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 591 ms 12472 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 609 ms 12488 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 597 ms 12628 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 610 ms 12628 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 12628 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1