답안 #536272

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
536272 2022-03-12T16:55:03 Z michao 비밀 (JOI14_secret) C++14
100 / 100
557 ms 4508 KB
#include <bits/stdc++.h>
#include "secret.h"
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int MAX=1e3+5;
const int STALA=30;
int pref[MAX][STALA];
int suf[MAX][STALA];
int n;
int a[MAX];
void rec1(int l,int r,int dep){
	if (l>r)return;
	int mid=(l+r)>>1;
	pref[mid][dep]=a[mid];
	suf[mid+1][dep]=a[mid+1];
	for (int i=mid-1;i>=l;i--){
		pref[i][dep]=Secret(a[i],pref[i+1][dep]);
	}
	
	for (int i=mid+2;i<=r;i++){
		suf[i][dep]=Secret(suf[i-1][dep],a[i]);
	}	
	if (l<r){
		rec1(l,mid,dep+1);
		rec1(mid+1,r,dep+1);
	}
}

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

int rec2(int l,int r,int L,int R,int dep){
	int mid=(l+r)>>1;
	if (L>mid)return rec2(mid+1,r,L,R,dep+1);
	if (R<=mid)return rec2(l,mid,L,R,dep+1);
	return Secret(pref[L][dep],suf[R][dep]);
}	

int Query(int L,int R){
	if (L==R)return a[L];
	return rec2(0,n-1,L,R,0);
}

# 결과 실행 시간 메모리 Grader output
1 Correct 143 ms 2496 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 146 ms 2504 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 181 ms 2492 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 536 ms 4428 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 528 ms 4500 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 525 ms 4428 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 557 ms 4428 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 546 ms 4400 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 547 ms 4500 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 555 ms 4508 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1