답안 #499926

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
499926 2021-12-30T04:36:04 Z mars4 비밀 (JOI14_secret) C++17
100 / 100
465 ms 4480 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;
vector<vector<ll>> st;

void build(ll l,ll r,ll level,int A[])
{
	if(l==r)
	{
		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;
	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++;
	}
}

Compilation message

secret.cpp: In function 'int Query(int, int)':
secret.cpp:102:1: warning: control reaches end of non-void function [-Wreturn-type]
  102 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 144 ms 2372 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 121 ms 2288 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 135 ms 2396 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 438 ms 4480 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 4284 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 452 ms 4316 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 438 ms 4348 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 465 ms 4452 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 443 ms 4320 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 440 ms 4464 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1