#include "secret.h"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
using namespace std;
int si=1,h=1;
int dp[20][2000];
int input[2000];
void fillup(int st,int l, int r)
{
int mid, i;
if(st>=9) return ;
mid=(r+l-1)/2;
for(i=mid;i>=l;i--)
{
if(i==mid) {dp[st][i]=input[i];continue;}
dp[st][i]=Secret(dp[st][i],dp[st][i+1]);
}
mid=(r+l+1)/2;
for(i=mid;i<=r;i++)
{
if(i==mid) {dp[st][i]=input[i];continue;}
dp[st][i]=Secret(dp[st][i-1],dp[st][i]);
}
fillup(st+1, l, (l+r)/2);
fillup(st+1, (l+r)/2+1, r);
}
void Init(int N, int A[])
{
int i,j;
while(si<N) {si*=2;h++;}
for(i=N;i>=1;i--)
{
input[i]=A[i-1];
}
for(i=1;i<=h+1;i++)
{
for(j=1;j<=N*2;j++)
{
dp[i][j]=-1;
}
}
fillup(1,1,si);
}
int query(int x,int st,int l, int r, int s, int e)
{
int mid;
mid=(l+r)/2;
if(l+r<s*2) return query(x*2+1,st+1,(l+r)/2+1, r, s, e);
else if(l+r>e*2) return query(x*2,st+1, l, (l+r)/2, s, e);
else
{
return Secret(dp[st][s],dp[st][e]);
}
}
int Query(int L, int R)
{
L++;
R++;
if(L+1==R) return Secret(input[L],input[R]);
else if(L==R) return input[L];
return query(1,1,1,si,L, R);
}
Compilation message
secret.cpp: In function 'int query(int, int, int, int, int, int)':
secret.cpp:47:9: warning: variable 'mid' set but not used [-Wunused-but-set-variable]
int mid;
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
161 ms |
2572 KB |
Wrong Answer [1] |
2 |
Incorrect |
159 ms |
2740 KB |
Wrong Answer [1] |
3 |
Incorrect |
172 ms |
3088 KB |
Wrong Answer [1] |
4 |
Incorrect |
597 ms |
5148 KB |
Wrong Answer [1] |
5 |
Incorrect |
632 ms |
5188 KB |
Wrong Answer [1] |
6 |
Incorrect |
658 ms |
5328 KB |
Wrong Answer [1] |
7 |
Incorrect |
658 ms |
5484 KB |
Wrong Answer [1] |
8 |
Incorrect |
650 ms |
5568 KB |
Wrong Answer [1] |
9 |
Incorrect |
581 ms |
5568 KB |
Wrong Answer [1] |
10 |
Incorrect |
573 ms |
5708 KB |
Wrong Answer [1] |