답안 #852725

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
852725 2023-09-22T15:33:09 Z sleepntsheep 비밀 (JOI14_secret) C++17
컴파일 오류
0 ms 0 KB
include <vector>
#include "secret.h"
#include <assert.h>
#define N 1050

int n, *a;
std::vector<int> pre[N<<1], suf[N<<1];

void build(int v, int l, int r)
{
    if (l == r)
    {
        pre[v] = suf[v] = {a[l]};
        return;
    }
    int m=(l+r)/2, vl=v+1, vr=v+(m-l+1)*2;
    pre[v].resize(r-l+1);
    suf[v].resize(r-l+1);
    suf[v][r-l] = a[r];
    for (int i = r-l-1, j = r-1; j >= l; --j, --i)
        suf[v][i] = Secret(a[j], suf[v][i+1]);
    pre[v][0] = a[l];
    for (int i = 1, j = l + 1; j <= r; ++j, ++i)
        pre[v][i] = Secret(pre[v][i-1], a[j]);
    build(vl, l, m);
    build(vr, m+1, r);
}

int qry(int v, int l, int r, int x, int y)
{
    int m = (l+r)/2, vl=v+1, vr=v+(m-l+1)*2;

    if (l == x) return pre[v][y-x];
    if (r == y) return suf[v][suf[v].size()-1-(y-x)];

    if (l <= x && y <= m) return qry(vl, l, m, x, y);
    if (m + 1 <= x && y <= r) return qry(vr, m+1, r, x, y);

    return Secret(qry(vl, l, m, x, m), qry(vr, m+1, r, m+1, y));
}

void Init(int n_, int *a_)
{
    n = n_, a = a_;
    build(0, 0, n-1);
}

int Query(int l, int r)
{
    return qry(0, 0, n-1, l, r);
}

Compilation message

secret.cpp:1:1: error: 'include' does not name a type
    1 | include <vector>
      | ^~~~~~~
secret.cpp:7:6: error: 'vector' in namespace 'std' does not name a template type
    7 | std::vector<int> pre[N<<1], suf[N<<1];
      |      ^~~~~~
secret.cpp:4:1: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'?
    3 | #include <assert.h>
  +++ |+#include <vector>
    4 | #define N 1050
secret.cpp: In function 'void build(int, int, int)':
secret.cpp:13:9: error: 'pre' was not declared in this scope
   13 |         pre[v] = suf[v] = {a[l]};
      |         ^~~
secret.cpp:13:18: error: 'suf' was not declared in this scope
   13 |         pre[v] = suf[v] = {a[l]};
      |                  ^~~
secret.cpp:17:5: error: 'pre' was not declared in this scope
   17 |     pre[v].resize(r-l+1);
      |     ^~~
secret.cpp:18:5: error: 'suf' was not declared in this scope
   18 |     suf[v].resize(r-l+1);
      |     ^~~
secret.cpp: In function 'int qry(int, int, int, int, int)':
secret.cpp:33:24: error: 'pre' was not declared in this scope
   33 |     if (l == x) return pre[v][y-x];
      |                        ^~~
secret.cpp:34:24: error: 'suf' was not declared in this scope
   34 |     if (r == y) return suf[v][suf[v].size()-1-(y-x)];
      |                        ^~~