답안 #1099079

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1099079 2024-10-10T13:25:43 Z Zero_OP 비밀 (JOI14_secret) C++14
100 / 100
323 ms 4680 KB
#include <bits/stdc++.h>
#ifndef LOCAL
#include <secret.h>
#endif

using namespace std;

const int MAX = 1e3 + 5;

int n, a[MAX], left_suffix[12][MAX], right_prefix[12][MAX];
bool vis[MAX];

#ifdef LOCAL
int Secret(int X, int Y){
    return min(X + ((Y >> 1) << 1), 1000000000);
}
#endif

void dnc(int l, int r, int layer){
    if(l > r) return;
    int mid = l + r >> 1;
    if(vis[mid]) return;
    vis[mid] = true;

    left_suffix[layer][mid] = a[mid];
    for(int i = mid - 1; i >= l; --i){
        left_suffix[layer][i] = Secret(a[i], left_suffix[layer][i + 1]);
    }

    if(mid < r) {
        right_prefix[layer][mid + 1] = a[mid + 1];
        for(int i = mid + 2; i <= r; ++i){
            right_prefix[layer][i] = Secret(right_prefix[layer][i - 1], a[i]);
        }
    }

    dnc(l, mid, layer + 1);
    dnc(mid + 1, r, layer + 1);
}

int solve(int lq, int rq, int l, int r, int level){
    int mid = l + r >> 1;
    if(lq <= mid && mid <= rq){
        if(mid == rq) return left_suffix[level][lq];
        return Secret(left_suffix[level][lq], right_prefix[level][rq]);
    }

    if(rq < mid) return solve(lq, rq, l, mid, level + 1);
    else return solve(lq, rq, mid + 1, r, level + 1);
}

void Init(int N, int A[]){
    n = N;
    copy(A, A + n, a);
    dnc(0, n - 1, 0);
}

int Query(int L, int R){
    return solve(L, R, 0, n - 1, 0);
}

#ifdef LOCAL
int main(){
    int A[] = {1, 4, 7, 2, 5, 8, 3, 6};
    Init(8, A);
    cout << Query(0, 3) << '\n';
    cout << Query(1, 7) << '\n';
    cout << Query(5, 5) << '\n';
    cout << Query(2, 4) << '\n';
    return 0;
}
#endif

Compilation message

secret.cpp: In function 'void dnc(int, int, int)':
secret.cpp:21:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   21 |     int mid = l + r >> 1;
      |               ~~^~~
secret.cpp: In function 'int solve(int, int, int, int, int)':
secret.cpp:42:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   42 |     int mid = l + r >> 1;
      |               ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 90 ms 2644 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 88 ms 2660 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 88 ms 2604 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 321 ms 4340 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 313 ms 4436 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 315 ms 4436 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 311 ms 4472 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 314 ms 4680 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 306 ms 4432 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 323 ms 4540 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1