Submission #961410

#TimeUsernameProblemLanguageResultExecution timeMemory
961410aufanSecret (JOI14_secret)C++17
100 / 100
373 ms9400 KiB
#include "secret.h" #include <bits/stdc++.h> using namespace std; int n; vector<int> a(1111); vector<vector<int>> val(1111, vector<int>(1111, -1)); void Init(int N, int A[]) { n = N; for (int i = 0; i < n; i++){ a[i] = A[i]; val[i][i] = a[i]; } function<void(int, int)> dnc = [&](int lf, int rg) { if (rg - lf + 1 <= 2) return; int md = (lf + rg) / 2; for (int i = md - 1; i >= lf; i--) { if (val[i][md] == -1) { val[i][md] = Secret(a[i], val[i + 1][md]); } } for (int i = md + 2; i <= rg; i++) { if (val[md + 1][i] == -1) { val[md + 1][i] = Secret(val[md + 1][i - 1], a[i]); } } dnc(lf, md); dnc(md + 1, rg); }; dnc(0, n - 1); } int Query(int l, int r) { int cnt = 10; function<int(int, int)> dnc = [&](int lf, int rg) { if (val[l][r] != -1) return val[l][r]; int md = (lf + rg) / 2; if (l > md) { return dnc(md + 1, rg); } else if (r < md + 1) { return dnc(lf, md); } else { return Secret(val[l][md], val[md + 1][r]); } }; return dnc(0, n - 1); }

Compilation message (stderr)

secret.cpp: In function 'int Query(int, int)':
secret.cpp:40:7: warning: unused variable 'cnt' [-Wunused-variable]
   40 |   int cnt = 10;
      |       ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...