답안 #483072

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
483072 2021-10-27T15:56:16 Z Yazan_Alattar 비밀 (JOI14_secret) C++14
100 / 100
439 ms 9000 KB
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <utility>
#include <cmath>
#include <numeric>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 2007;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#include "secret.h"
int n, sum[M][M], a[M];

void solve(int l, int r)
{
    if(l >= r) return;
    int mid = (l + r) / 2;
    sum[mid][mid] = a[mid];
    sum[mid + 1][mid + 1] = a[mid + 1];
    for(int i = mid - 1; i >= l; --i) sum[i][mid] = Secret(a[i], sum[i + 1][mid]);
    for(int i = mid + 2; i <= r; ++i) sum[mid + 1][i] = Secret(sum[mid + 1][i - 1], a[i]);
    solve(l, mid);
    solve(mid + 1, r);
    return;
}

int get(int st, int en, int l, int r)
{
    int mid = (l + r) / 2;
    if(en > mid && st <= mid) return Secret(sum[st][mid], sum[mid + 1][en]);
    if(en <= mid) return get(st, en, l, mid);
    return get(st, en, mid + 1, r);
}

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

int Query(int l, int r)
{
    ++l; ++r;
    if(l == r) return a[l];
    return get(l, r, 1, n);
}

// Don't forget special cases. (n = 1?)
// Look for the constraints. (Runtime array? overflow?)
# 결과 실행 시간 메모리 Grader output
1 Correct 121 ms 4548 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 124 ms 4632 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 121 ms 4508 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 434 ms 8832 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 426 ms 9000 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 432 ms 8852 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 430 ms 8880 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 439 ms 8996 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 433 ms 8876 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 433 ms 8936 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1