답안 #1110773

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1110773 2024-11-10T12:09:59 Z Alihan_8 비밀 (JOI14_secret) C++17
100 / 100
319 ms 8368 KB
#include "secret.h"

#include <bits/stdc++.h>

using namespace std;

int qry(int a, int b){
	return Secret(a, b);
}

vector <vector<int>> dp;

int n;

void Init(int N, int A[]) {
	n = N;
	
	dp.resize(n);
	for ( auto &u: dp ) u.resize(n);
	
	auto dnc = [&](auto dnc, int l, int r) -> void{
		int m = (l + r) / 2;
		
		dp[m][m] = A[m], dp[m + 1][m + 1] = A[m + 1];
		
		for ( int i = m - 1; i >= l; i-- ){
			dp[m][i] = qry(A[i], dp[m][i + 1]);
		}
		
		for ( int i = m + 2; i <= r; i++ ){
			dp[m + 1][i] = qry(dp[m + 1][i - 1], A[i]);
		}
		
		if ( m > l ) dnc(dnc, l, m);
		
		if ( m + 1 < r ) dnc(dnc, m + 1, r);
	};
	
	dnc(dnc, 0, n - 1);
}

int Query(int L, int R) {
	if ( L == R ) return dp[L][R];
	
	int a = 0, b = n - 1;
	
	while ( true ){
		int m = (a + b) / 2;
		
		if ( L <= m && R > m ) return qry(dp[m][L], dp[m + 1][R]);
		else if ( R == m ) return dp[m][L];
		else if ( m < L ) a = m + 1;
		else b = m;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 3852 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 84 ms 3660 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 84 ms 3656 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 315 ms 8264 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 308 ms 8264 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 317 ms 8364 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 306 ms 8368 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 319 ms 8364 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 307 ms 8264 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 312 ms 8264 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1