# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
85569 |
2018-11-21T00:03:03 Z |
KCSC |
Secret (JOI14_secret) |
C++14 |
|
656 ms |
6288 KB |
#include <bits/stdc++.h>
using namespace std;
int Secret(int x, int y);
void Init(int n, int arr[]);
int Query(int le, int ri);
/*
int Secret(int x, int y) {
return x xor y xor 13; }
*/
map<pair<int, int>, int> mmp;
int secret(int x, int y) {
if (mmp.find(make_pair(x, y)) == mmp.end()) {
mmp[make_pair(x, y)] = Secret(x, y); }
return mmp[make_pair(x, y)]; }
const int DIM = 1005;
vector<int> lef[DIM * 4], rig[DIM * 4];
void build(int nd, int le, int ri, int arr[]) {
if (le == ri) {
lef[nd].resize(1, arr[le]); rig[nd].resize(1, arr[ri]); }
else {
int md = (le + ri) / 2;
build(nd * 2, le, md, arr);
build(nd * 2 + 1, md + 1, ri, arr);
lef[nd].resize(ri - le + 1); lef[nd][md - le] = arr[md];
rig[nd].resize(ri - le + 1); rig[nd][md + 1 - le] = arr[md + 1];
for (int i = md - le - 1; i >= 0; --i) {
lef[nd][i] = secret(arr[i + le], lef[nd][i + 1]); }
for (int i = md - le + 2; i <= ri - le; ++i) {
rig[nd][i] = secret(rig[nd][i - 1], arr[i + le]); } } }
int query(int nd, int le, int ri, int st, int en) {
if (le == ri) {
return lef[nd][0]; }
else {
int md = (le + ri) / 2;
if (en <= md) {
return query(nd * 2, le, md, st, en); }
if (md < st) {
return query(nd * 2 + 1, md + 1, ri, st, en); }
return secret(lef[nd][st - le], rig[nd][en - le]); } }
int _n;
void Init(int n, int arr[]) {
build(1, 0, n - 1, arr); _n = n; }
int Query(int le, int ri) {
return query(1, 0, _n - 1, le, ri); }
/*
int arr[10];
int main(void) {
#ifdef HOME
freopen("secret.in", "r", stdin);
freopen("secret.out", "w", stdout);
#endif
int n; cin >> n;
for (int i = 0; i < n; ++i) {
cin >> arr[i]; }
Init(n, arr);
int m; cin >> m;
while (m--) {
int le, ri; cin >> le >> ri;
int val = arr[le];
for (int i = le + 1; i <= ri; ++i) {
val = Secret(val, arr[i]); }
cout << Query(le, ri) << " " << val << "\n"; }
return 0; }
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
187 ms |
3544 KB |
Output is correct - number of calls to Secret by Init = 3324, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
185 ms |
3652 KB |
Output is correct - number of calls to Secret by Init = 3332, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
185 ms |
3652 KB |
Output is correct - number of calls to Secret by Init = 3341, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
642 ms |
5932 KB |
Output is correct - number of calls to Secret by Init = 7483, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
632 ms |
5964 KB |
Output is correct - number of calls to Secret by Init = 7491, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
639 ms |
6120 KB |
Output is correct - number of calls to Secret by Init = 7491, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
656 ms |
6168 KB |
Output is correct - number of calls to Secret by Init = 7491, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
639 ms |
6168 KB |
Output is correct - number of calls to Secret by Init = 7491, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
650 ms |
6288 KB |
Output is correct - number of calls to Secret by Init = 7491, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
641 ms |
6288 KB |
Output is correct - number of calls to Secret by Init = 7491, maximum number of calls to Secret by Query = 1 |