답안 #1094762

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1094762 2024-09-30T13:16:59 Z asli_bg 비밀 (JOI14_secret) C++11
100 / 100
317 ms 8436 KB
#pragma GCC optimize("O3,unroll-loops")

#include "secret.h"

#include <bits/stdc++.h>
using namespace std;

//#define int long long

#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
 
#define FOR(i,a) for(int i=0;i<(a);i++)
#define FORE(i,a,b) for(int i=(a);i<(b);i++)
#define cont(x) {for(auto el:x) cout<<el<<' ';cout<<endl;}
#define contp(x) {for(auto el:x) cout<<el.fi<<'-'<<el.se<<' ';cout<<endl;}
#define sp <<" "<<
//#define mid (l+r)/2
#define endl '\n'
 
#define DEBUG(X) {cout<<#X<<' '<<(X)<<endl;}
 
#define carp(x,y) ((x%MOD)*(y%MOD))%MOD
#define topla(x,y) ((x%MOD)+(y%MOD))%MOD
 
typedef vector<int> vi;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<bool> vb;

const int MAXN=1e3+5;

vi a;
int n;
int tut[MAXN][MAXN];

void dq(int l,int r){
    int mid=(l+r)/2;

    tut[mid][mid]=a[mid];
    tut[mid+1][mid+1]=a[mid+1];

    for(int i=mid-1;i>=l;i--){
        tut[mid][i]=Secret(a[i],tut[mid][i+1]);
    }
    for(int i=mid+2;i<=r;i++){
        tut[mid+1][i]=Secret(tut[mid+1][i-1],a[i]);
    }

    if(l<mid) dq(l,mid);
    if(mid+1<r) dq(mid+1,r);
}


void Init(int N, int A[]) {
    n=N;
    a.resize(N+1);
    FOR(i,N) a[i+1]=A[i];
    dq(1,N);
}

int Query(int l, int r) {
    int bas=1;
    int son=n;
    l++;r++;
    while(bas!=son){
        int mid=(bas+son)/2;
        if(l<=mid and mid<r) return Secret(tut[mid][l],tut[mid+1][r]);
        else if(mid==r) return tut[mid][l];
        else if(mid<l) bas=mid+1;
        else son=mid;
    }

    return tut[l][l];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 90 ms 4580 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 90 ms 4432 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 88 ms 4440 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 312 ms 8276 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 312 ms 8232 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 311 ms 8276 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 314 ms 8272 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 313 ms 8272 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 317 ms 8436 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 309 ms 8272 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1