# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
882319 |
2023-12-03T04:17:19 Z |
noompty |
Secret (JOI14_secret) |
C++17 |
|
393 ms |
8528 KB |
#include <iostream>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <cmath>
#include <array>
#include <random>
#include <string>
#include <cassert>
#include <climits>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include "secret.h"
using namespace std;
#define ll long long
#define f first
#define s second
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template<typename A> void __print(const A &x);
template<typename A, typename B> void __print(const pair<A, B> &p);
template<typename... A> void __print(const tuple<A...> &t);
template<typename T> void __print(stack<T> s);
template<typename T> void __print(queue<T> q);
template<typename T, typename... U> void __print(priority_queue<T, U...> q);
template<typename A> void __print(const A &x) {
bool first = true;
cerr << '{';
for (const auto &i : x) {
cerr << (first ? "" : ","), __print(i);
first = false;
}
cerr << '}';
}
template<typename A, typename B> void __print(const pair<A, B> &p) {
cerr << '(';
__print(p.f);
cerr << ',';
__print(p.s);
cerr << ')';
}
template<typename... A> void __print(const tuple<A...> &t) {
bool first = true;
cerr << '(';
apply([&first] (const auto &...args) { ((cerr << (first ? "" : ","), __print(args), first = false), ...); }, t);
cerr << ')';
}
template<typename T> void __print(stack<T> s) {
vector<T> debugVector;
while (!s.empty()) {
T t = s.top();
debugVector.push_back(t);
s.pop();
}
reverse(debugVector.begin(), debugVector.end());
__print(debugVector);
}
template<typename T> void __print(queue<T> q) {
vector<T> debugVector;
while (!q.empty()) {
T t = q.front();
debugVector.push_back(t);
q.pop();
}
__print(debugVector);
}
template<typename T, typename... U> void __print(priority_queue<T, U...> q) {
vector<T> debugVector;
while (!q.empty()) {
T t = q.top();
debugVector.push_back(t);
q.pop();
}
__print(debugVector);
}
void _print() { cerr << "]\n"; }
template <typename Head, typename... Tail> void _print(const Head &H, const Tail &...T) {
__print(H);
if (sizeof...(T)) cerr << ", ";
_print(T...);
}
#ifdef DEBUG
#define D(...) cerr << "Line: " << __LINE__ << " [" << #__VA_ARGS__ << "] = ["; _print(__VA_ARGS__)
#else
#define D(...)
#endif
int n, a[1005], pref[1005][1005];
void precompute(int l, int r) {
int m = (l + r) / 2;
pref[m][m] = a[m];
pref[m + 1][m + 1] = a[m + 1];
for (int i = m + 2; i <= r; i++) {
pref[m + 1][i] = Secret(pref[m + 1][i - 1], a[i]);
}
for (int i = m - 1; i >= l; i--) {
pref[m][i] = Secret(a[i], pref[m][i + 1]);
}
if (l < m) precompute(l, m);
if (m + 1 < r) precompute(m + 1, r);
}
void Init(int N, int A[]) {
n = N;
for (int i = 0; i < N; i++) {
a[i] = A[i];
}
precompute(0, n - 1);
}
int Query(int L, int R) {
int lft = 0, rht = n - 1;
while (lft != rht) {
int m = (lft + rht) / 2;
if (m >= L && m < R) {
return Secret(pref[m][L], pref[m + 1][R]);
} else if (m == R) return pref[m][L];
else if (m < L) lft = m + 1;
else rht = m;
}
return pref[lft][lft];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
6880 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
109 ms |
6836 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
109 ms |
6740 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
393 ms |
8276 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
380 ms |
8268 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
379 ms |
8528 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
384 ms |
8272 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
392 ms |
8356 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
380 ms |
8272 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
388 ms |
8356 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |