Submission #599717

# Submission time Handle Problem Language Result Execution time Memory
599717 2022-07-19T19:24:32 Z stevancv Secret (JOI14_secret) C++14
100 / 100
617 ms 4472 KB
#include <bits/stdc++.h>
#include "secret.h"
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 3e3 + 2;
struct block {
    int m;
    vector<int> a, b;
};
int a[N];
vector<block> all;
void Init(int n, int A[]) {
    for (int i = 0; i < n; i++) a[i] = A[i];
    function<void(int, int)> DQ = [&] (int l, int r) {
        if (l >= r) return;
        block tr;
        int mid = l + r >> 1;
        tr.m = mid;
        tr.a.push_back(a[mid]);
        for (int i = mid - 1; i >= l; i--) {
            tr.a.push_back(Secret(a[i], tr.a.back()));
        }
        tr.b.push_back(a[mid + 1]);
        for (int i = mid + 2; i <= r; i++) {
            tr.b.push_back(Secret(tr.b.back(), a[i]));
        }/*
        cout << mid << en;
        for (int u : tr.a) cout << u << sp;
        cout << en;
        for (int u : tr.b) cout << u << sp;
        cout << en;*/
        all.push_back(tr);
        DQ(l, mid - 1);
        DQ(mid + 2, r);
    };
    DQ(0, n - 1);
}
int Query(int l, int r) {
    if (l == r) return a[l];
    for (auto xyz : all) {
        int m = xyz.m;
        vector<int> a = xyz.a;
        vector<int> b = xyz.b;
        if (l <= m + 1 && m <= r) {
            int x = -1; if (m - l >= 0) x = a[m - l];
            int y = -1; if (r - m - 1 >= 0) y = b[r - m - 1];
            if (x == -1 && y == -1) continue;
            if (x == -1) return y;
            if (y == -1) return x;
            return Secret(x, y);
        }
    }
}

Compilation message

secret.cpp: In lambda function:
secret.cpp:22:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   22 |         int mid = l + r >> 1;
      |                   ~~^~~
secret.cpp: In function 'int Query(int, int)':
secret.cpp:58:1: warning: control reaches end of non-void function [-Wreturn-type]
   58 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 164 ms 2428 KB Output is correct - number of calls to Secret by Init = 3084, maximum number of calls to Secret by Query = 1
2 Correct 162 ms 2316 KB Output is correct - number of calls to Secret by Init = 3092, maximum number of calls to Secret by Query = 1
3 Correct 158 ms 2512 KB Output is correct - number of calls to Secret by Init = 3100, maximum number of calls to Secret by Query = 1
4 Correct 534 ms 4264 KB Output is correct - number of calls to Secret by Init = 6988, maximum number of calls to Secret by Query = 1
5 Correct 534 ms 4324 KB Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1
6 Correct 617 ms 4472 KB Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1
7 Correct 451 ms 4340 KB Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1
8 Correct 442 ms 4376 KB Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1
9 Correct 428 ms 4372 KB Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1
10 Correct 426 ms 4304 KB Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1