Submission #412732

#TimeUsernameProblemLanguageResultExecution timeMemory
412732jhnah917Secret (JOI14_secret)C++14
100 / 100
552 ms8516 KiB
/******************************
Author: jhnah917(Justice_Hui)
g++ -std=c++17 -DLOCAL
******************************/

#ifndef LOCAL
#include "secret.h"
#endif
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL // avoid compile error
int Secret(int a, int b){ return 0; }
#endif

int N, A[1010], B[1010][1010];

void Seg_Init(int s, int e){
    if(s == e) return;
    int m = s + e >> 1;
    B[m][m] = A[m];
    for(int i=m-1; i>=s; i--) B[i][m] = Secret(A[i], B[i+1][m]);
    B[m+1][m+1] = A[m+1];
    for(int i=m+2; i<=e; i++) B[m+1][i] = Secret(B[m+1][i-1], A[i]);
    Seg_Init(s, m);
    Seg_Init(m+1, e);
}

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

int Seg_Query(int s, int e, int l, int r){
    int m = s + e >> 1;
    if(l <= m && m < r) return Secret(B[l][m], B[m+1][r]);
    if(r <= m) return Seg_Query(s, m, l, r);
    else return Seg_Query(m+1, e, l, r);
}

int Query(int l, int r){
    l++; r++;
    if(l == r) return A[l];
    return Seg_Query(1, N, l, r);
}

Compilation message (stderr)

secret.cpp: In function 'void Seg_Init(int, int)':
secret.cpp:20:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   20 |     int m = s + e >> 1;
      |             ~~^~~
secret.cpp: In function 'int Seg_Query(int, int, int, int)':
secret.cpp:37:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   37 |     int m = s + e >> 1;
      |             ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...