Submission #239875

# Submission time Handle Problem Language Result Execution time Memory
239875 2020-06-17T12:35:05 Z Knps4422 Secret (JOI14_secret) C++14
100 / 100
552 ms 5948 KB
//#pragma optimization_level 3
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#include"secret.h"
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordset;
*/
 
#define fr first
#define sc second
#define vec vector
#define pb push_back
#define pii pair<int, int>
#define forn(x,y) for(ll x = 1 ; x <= y ; ++x)
#define all(x) (x).begin(),(x).end()
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);

 
using namespace std;
 
typedef long long ll;
typedef unsigned int uint;
typedef pair<ll,ll> pll;
const int nmax = 100005;
const ll linf = 1e17;
const ll mod = 1e9+7;
const int inf = 1e9+7;
const ll lim = 1e4;

int n, a[nmax];

map < pii , int > cl;
map < pii , int > rg;


int Ask(int a, int b){
	if( cl[make_pair(a,b)] != 0){
		return cl[make_pair(a,b)];
	}
	else 
		return cl[make_pair(a,b)] = Secret(a,b);
}

int Ask_range(int l , int r){
	if(l == r)return a[l];
	assert(rg[make_pair(l,r)] != 0);
	return rg[make_pair(l,r)];
}

void make_range(int l , int r){
	if(l >= r){
		return;
	}
	int mid = (l+r)>>1;
	int as = a[mid];
	int bs = a[mid+1];
	for(int i = mid - 1 ; i >= l ; i--){
		as = Ask(a[i],as);
		rg[make_pair(i,mid)] = as;
	}
	for(int i = mid + 2 ; i <= r ; i++){
		bs = Ask(bs,a[i]);
		rg[make_pair(mid+1,i)] = bs;
	}
	make_range(l,mid);
	make_range(mid+1,r);
}

void Init(int N , int A[]){
	n = N;
	forn(i,n){
		a[i] = A[i-1];
	}
	make_range(1,n);
}

int qr(int l, int r , int lt , int rt){
	int mid = (lt+rt)>>1;
	if(r <= mid){
		return qr(l,r,lt,mid);
	}
	if(l >= mid + 1){
		return qr(l,r,mid+1,rt);
	}
	return Ask(Ask_range(l,mid),Ask_range(mid+1,r));
}

int Query(int L , int R){
	L++, R++;
	if( L == R ){
		return a[L];
	}
	if( L == R - 1){
		return Ask(a[L],a[R]);
	}
	return qr(L,R,1,n);
}
# Verdict Execution time Memory Grader output
1 Correct 163 ms 3448 KB Output is correct - number of calls to Secret by Init = 3324, maximum number of calls to Secret by Query = 1
2 Correct 167 ms 3448 KB Output is correct - number of calls to Secret by Init = 3332, maximum number of calls to Secret by Query = 1
3 Correct 161 ms 3448 KB Output is correct - number of calls to Secret by Init = 3341, maximum number of calls to Secret by Query = 1
4 Correct 543 ms 5904 KB Output is correct - number of calls to Secret by Init = 7483, maximum number of calls to Secret by Query = 1
5 Correct 544 ms 5856 KB Output is correct - number of calls to Secret by Init = 7491, maximum number of calls to Secret by Query = 1
6 Correct 540 ms 5676 KB Output is correct - number of calls to Secret by Init = 7491, maximum number of calls to Secret by Query = 1
7 Correct 542 ms 5880 KB Output is correct - number of calls to Secret by Init = 7491, maximum number of calls to Secret by Query = 1
8 Correct 536 ms 5948 KB Output is correct - number of calls to Secret by Init = 7491, maximum number of calls to Secret by Query = 1
9 Correct 535 ms 5880 KB Output is correct - number of calls to Secret by Init = 7491, maximum number of calls to Secret by Query = 1
10 Correct 552 ms 5792 KB Output is correct - number of calls to Secret by Init = 7491, maximum number of calls to Secret by Query = 1