Submission #499925

# Submission time Handle Problem Language Result Execution time Memory
499925 2021-12-30T04:35:13 Z mars4 Secret (JOI14_secret) C++17
100 / 100
459 ms 4376 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include "secret.h"

using namespace std;
using namespace __gnu_pbds; 

#define ff              first
#define ss              second
#define ll              int64_t
#define ld              long double
#define nl              cout<<"\n"
#define all(v)          v.begin(),v.end()
#define mset(a,v)       memset((a),(v),sizeof(a))
#define forn(i,a,b)     for(int64_t i=int64_t(a);i<int64_t(b);++i)
#define forb(i,a,b)     for(int64_t i=int64_t(a);i>=int64_t(b);--i)
#define fastio()        ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define mod         1'000'000'007
#define mod2        998'244'353 
#define inf         1'000'000'000'000'007
#define pi          3.14159265358979323846

template<class key,class cmp=std::less<key>>
using ordered_set=tree<key,null_type,cmp,rb_tree_tag,tree_order_statistics_node_update>;

template<class L,class R> ostream& operator<<(ostream& out,pair<L,R> &p)        {return out<<"("<<p.ff<<", "<<p.ss<<")";}
template<class T> ostream& operator<<(ostream& out,vector<T> &v)                {out<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())out<<", ";out<<*it;}return out<<"]";}
template<class T> ostream& operator<<(ostream& out,deque<T> &v)                 {out<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())out<<", ";out<<*it;}return out<<"]";}
template<class T> ostream& operator<<(ostream& out,set<T> &s)                   {out<<"{";for(auto it=s.begin();it!=s.end();++it){if(it!=s.begin())out<<", ";out<<*it;}return out<<"}";}
template<class L,class R> ostream& operator<<(ostream& out,map<L,R> &m)         {out<<"{";for(auto it=m.begin();it!=m.end();++it){if(it!=m.begin())out<<", ";out<<*it;}return out<<"}";}

void dbg_out() {cerr<<"]\n";}
template<typename Head,typename... Tail> 
void dbg_out(Head H,Tail... T) {cerr<<H;if(sizeof...(Tail))cerr<<", ";dbg_out(T...);}
#ifdef LOCAL
	#define dbg(...) cerr<<"["<<#__VA_ARGS__<<"] = [",dbg_out(__VA_ARGS__)
#else
	#define dbg(...)
#endif

//---------------------------------mars4---------------------------------

ll n;
ll mlevel;
vector<vector<ll>> st;
vector<ll> a;

void build(ll l,ll r,ll level,int A[])
{
	if(l==r)
	{
		mlevel=level;
		st[level][l]=A[l];
		return;
	}
	ll mid=(l+r)/2;
	st[level][mid]=A[mid];
	forb(i,mid-1,l)
	{
		st[level][i]=Secret(A[i],st[level][i+1]);
	}
	st[level][mid+1]=A[mid+1];
	forn(i,mid+2,r+1)
	{
		st[level][i]=Secret(st[level][i-1],A[i]);
	}
	build(l,mid,level+1,A);
	build(mid+1,r,level+1,A);
}

void Init(int N,int A[])
{
	n=N;
	forn(i,0,n)
	{
		a.push_back(A[i]);
	}
	st=vector<vector<ll>>(65-__builtin_clzll(N),vector<ll>(N));
	build(0,N-1,0,A);
}

int Query(int L,int R)
{
	ll l=0,r=n-1;
	ll level=0;
	while(l!=r)
	{
		ll mid=(l+r)/2;
		if(L<=mid and R>=mid)
		{
			if(R==mid)
			{
				return st[level][L];
			}
			return Secret(st[level][L],st[level][R]);
		}
		else if(R<mid)
		{
			r=mid;
		}
		else
		{
			l=mid+1;
		}
		level++;
	}
	return a[l];
}
# Verdict Execution time Memory Grader output
1 Correct 121 ms 2416 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 118 ms 2404 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 127 ms 2424 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 459 ms 4372 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 449 ms 4376 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 436 ms 4376 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 444 ms 4352 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 441 ms 4248 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 442 ms 4352 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 456 ms 4324 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1