#include <bits/stdc++.h>
#include "secret.h"
using namespace std;
#ifdef LOCAL
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {
cerr<<vars<<" = ";
string delim="";
(...,(cerr<<delim<<values,delim=", "));
cerr<<"\n";
}
#else
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {}
#endif
#define pb push_back
#define sz(x) (int)(x.size())
#define MAX_VALUE 1000000000
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> inline void maxa(T& a,T b){a=max(a,b);}
template<typename T> inline void mina(T& a,T b){a=min(a,b);}
const int mxN=1e3+5;
int a[mxN],pieceofshit[mxN][12],n;
void build(int v,int l,int r){
if(l>=r)
return;
int mid=(l+r)>>1;
build(v+1,l,mid);
build(v+1,mid+1,r);
pieceofshit[mid][v]=a[mid];
pieceofshit[mid+1][v]=a[mid+1];
for(int i=mid-1;i>=l;i--){
assert(pieceofshit[i+1][v]<=1e9);
pieceofshit[i][v]=Secret(a[i],pieceofshit[i+1][v]);
}
for(int i=mid+2;i<=r;i++){
assert(pieceofshit[i-1][v]<=1e9);
pieceofshit[i][v]=Secret(pieceofshit[i-1][v],a[i]);
}
deb(l,r,mid);
for(int i=l;i<=r;i++)
cerr<<pieceofshit[i][v]<<" \n"[i==r];
}
int query(int v,int l,int r,int lq,int rq){
int mid=(l+r)>>1;
if(lq>mid+1)
return query(v+1,mid+1,r,lq,rq);
if(rq<mid)
return query(v+1,l,mid,lq,rq);
if(lq<=mid && rq>mid){
assert(pieceofshit[lq][v]<=1e9);
assert(pieceofshit[rq][v]<=1e9);
return Secret(pieceofshit[lq][v],pieceofshit[rq][v]);
}
if(lq==mid+1)
return pieceofshit[rq][v];
if(rq==mid)
return pieceofshit[lq][v];
assert(false);
}
int Query(int L, int R){
if(L==R)
return a[L];
return query(0,0,n-1,L,R);
}
void Init(int N, int A[]){
for(int i=0;i<N;i++)
a[i]=A[i];
build(0,0,N-1);
n=N;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
159 ms |
2348 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
168 ms |
2500 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
164 ms |
2452 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
563 ms |
4540 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
547 ms |
4420 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
547 ms |
4416 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
555 ms |
4548 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
560 ms |
4312 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
564 ms |
4496 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
557 ms |
4472 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |