Submission #877480

# Submission time Handle Problem Language Result Execution time Memory
877480 2023-11-23T09:19:33 Z Ivkosqn Secret (JOI14_secret) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "secret.h"
#define endl '\n'

using namespace std;

const int maxn = 1024;
int pref[maxn][maxn], suff[maxn][maxn];
int lf[maxn], rg[maxn], a[maxn];
vector<int> mids;

const int maxn = 1024;
int pref[maxn][maxn], suff[maxn][maxn];
int lf[maxn], rg[maxn], a[maxn];
vector<int> mids;

void divide(int l, int r){
    if(l == r){
        suff[l][l] = a[l];
        lf[l] = l;
        rg[l] = l;
        mids.push_back(l);
        return;
    }
    int mid = (l + r) / 2;
    mids.push_back(mid);
    divide(l, mid);
    divide(mid + 1, r);
    lf[mid] = l, rg[mid] = r;
    suff[mid][mid] = a[mid];
    pref[mid][mid + 1] = a[mid + 1];
    for(int i = mid - 1;i >= l;i--)
        suff[mid][i] = Secret(suff[mid][i + 1], a[i]);
    for(int i = mid + 2;i <= r;i++)
        pref[mid][i] = Secret(pref[mid][i - 1], a[i]);
}

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

int Query(int l, int r){
    for(int x : mids){
        if(lf[x] <= l && rg[x] >= r){
            int ans = suff[x][l];
            if(x != r)
                ans = Secret(ans, pref[x][r]);
            return ans;
        }
    }
}

Compilation message

secret.cpp:12:11: error: redefinition of 'const int maxn'
   12 | const int maxn = 1024;
      |           ^~~~
secret.cpp:7:11: note: 'const int maxn' previously defined here
    7 | const int maxn = 1024;
      |           ^~~~
secret.cpp:13:5: error: redefinition of 'int pref [1024][1024]'
   13 | int pref[maxn][maxn], suff[maxn][maxn];
      |     ^~~~
secret.cpp:8:5: note: 'int pref [1024][1024]' previously declared here
    8 | int pref[maxn][maxn], suff[maxn][maxn];
      |     ^~~~
secret.cpp:13:23: error: redefinition of 'int suff [1024][1024]'
   13 | int pref[maxn][maxn], suff[maxn][maxn];
      |                       ^~~~
secret.cpp:8:23: note: 'int suff [1024][1024]' previously declared here
    8 | int pref[maxn][maxn], suff[maxn][maxn];
      |                       ^~~~
secret.cpp:14:5: error: redefinition of 'int lf [1024]'
   14 | int lf[maxn], rg[maxn], a[maxn];
      |     ^~
secret.cpp:9:5: note: 'int lf [1024]' previously declared here
    9 | int lf[maxn], rg[maxn], a[maxn];
      |     ^~
secret.cpp:14:15: error: redefinition of 'int rg [1024]'
   14 | int lf[maxn], rg[maxn], a[maxn];
      |               ^~
secret.cpp:9:15: note: 'int rg [1024]' previously declared here
    9 | int lf[maxn], rg[maxn], a[maxn];
      |               ^~
secret.cpp:14:25: error: redefinition of 'int a [1024]'
   14 | int lf[maxn], rg[maxn], a[maxn];
      |                         ^
secret.cpp:9:25: note: 'int a [1024]' previously declared here
    9 | int lf[maxn], rg[maxn], a[maxn];
      |                         ^
secret.cpp:15:13: error: redefinition of 'std::vector<int> mids'
   15 | vector<int> mids;
      |             ^~~~
secret.cpp:10:13: note: 'std::vector<int> mids' previously declared here
   10 | vector<int> mids;
      |             ^~~~
secret.cpp: In function 'int Query(int, int)':
secret.cpp:53:1: warning: control reaches end of non-void function [-Wreturn-type]
   53 | }
      | ^