Submission #406534

# Submission time Handle Problem Language Result Execution time Memory
406534 2021-05-17T17:26:32 Z bonopo Secret (JOI14_secret) C++14
100 / 100
561 ms 5604 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define el "\n"
#define f first
#define s second

typedef long long ll;
const ll MM=1e3+5, MOD=1e9+7;
int N, a[MM], pfx[12][MM], sfx[12][MM];
map<pair<int,int>, int> mem;

int Secret(int X, int Y);

int doSecret(int X, int Y) {
    if(mem.find({X, Y})!=mem.end()) return mem[{X, Y}];
    return mem[{X, Y}]=Secret(X, Y);
}

void build(int l, int r, int lvl) {
    int m=(l+r)/2;
    for(int i=m; i>=l; --i) {
        if(i==m) sfx[lvl][i]=a[i];
        else sfx[lvl][i]=doSecret(a[i], sfx[lvl][i+1]); }
    for(int i=m+1; i<=r; ++i) {
        if(i==m+1) pfx[lvl][i]=a[i];
        else pfx[lvl][i]=doSecret(pfx[lvl][i-1], a[i]); }
    if(l<r) build(l, m, lvl+1), build(m+1, r, lvl+1);
}

int qry(int l, int r, int ql, int qr, int lvl) {
    int m=(l+r)/2;

    if(ql<=m+1&&qr>=m) {
        int p=(qr==m+0?0:pfx[lvl][qr]);
        int s=(ql==m+1?0:sfx[lvl][ql]);

        if(qr==m+0) return s;
        if(ql==m+1) return p;
        return doSecret(s, p);
    }

    if(ql<=m&&qr<=m) return qry(l, m, ql, qr, lvl+1);
    else return qry(m+1, r, ql, qr, lvl+1);
}

void Init(int n, int A[]) {
    N=n;
    for(int i=0; i<N; ++i) a[i]=A[i];
    build(0, N-1, 0);
}

int Query(int L, int R) {
    return qry(0, N-1, L, R, 0);
}
# Verdict Execution time Memory Grader output
1 Correct 151 ms 3264 KB Output is correct - number of calls to Secret by Init = 3324, maximum number of calls to Secret by Query = 1
2 Correct 178 ms 3300 KB Output is correct - number of calls to Secret by Init = 3332, maximum number of calls to Secret by Query = 1
3 Correct 155 ms 3216 KB Output is correct - number of calls to Secret by Init = 3341, maximum number of calls to Secret by Query = 1
4 Correct 554 ms 5544 KB Output is correct - number of calls to Secret by Init = 7483, maximum number of calls to Secret by Query = 1
5 Correct 532 ms 5568 KB Output is correct - number of calls to Secret by Init = 7491, maximum number of calls to Secret by Query = 1
6 Correct 528 ms 5252 KB Output is correct - number of calls to Secret by Init = 7491, maximum number of calls to Secret by Query = 1
7 Correct 561 ms 5532 KB Output is correct - number of calls to Secret by Init = 7491, maximum number of calls to Secret by Query = 1
8 Correct 545 ms 5604 KB Output is correct - number of calls to Secret by Init = 7491, maximum number of calls to Secret by Query = 1
9 Correct 549 ms 5520 KB Output is correct - number of calls to Secret by Init = 7491, maximum number of calls to Secret by Query = 1
10 Correct 535 ms 5484 KB Output is correct - number of calls to Secret by Init = 7491, maximum number of calls to Secret by Query = 1