답안 #565762

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
565762 2022-05-21T10:21:33 Z MohammadAghil 비밀 (JOI14_secret) C++14
100 / 100
450 ms 8396 KB
      #include <bits/stdc++.h>
#include "secret.h"
//   #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
    using namespace std;
  typedef long long ll;
   typedef pair<int, int> pp;
    #define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
      #define per(i,r,l) for(int i = (r); i >= (l); i--)
        #define rep(i,l,r) for(int i = (l); i < (r); i++)
           #define all(x) x.begin(), x.end()
              #define sz(x) (int)(x).size()
                  #define pb push_back
                      #define ss second
                           #define ff first
                                   void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 1e9 + 7, maxn = 1e3 + 2, sq = 710, lg = 11, inf = ll(1e9) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;}
 
int a[maxn], lgg[maxn], n, vl[maxn][maxn];
pp rmq[maxn][lg];
 
int get_val(int x){
     return __builtin_ctz(x);
}
 
void build_rmq(){
     rep(i,2,maxn) lgg[i] = lgg[i>>1] + 1;
     rep(i,1,n + 1) rmq[i][0] = {get_val(i), i};
     rep(j,1,lg){
          rep(i,1,n+1-(1<<j)+1){
               rmq[i][j] = max(rmq[i][j-1], rmq[i+(1<<(j-1))][j-1]);
          }
     }
}
 
int get_max(int l, int r){
     int k = lgg[r - l + 1];
     return max(rmq[l][k], rmq[r-(1<<k)+1][k]).ss;
}
 
int Query(int L, int R){ L++, R++;
     int mid = get_max(L, R);
     if(mid == R) return vl[mid][L];
     return Secret(vl[mid][L], vl[mid][R]);
}
 
void Init(int N, int A[]){
     n = N;
     rep(i,0,n) a[i + 1] = A[i];
     build_rmq();
     rep(i,1,n+1){
          vl[i][i] = a[i];
          per(j,i-1,1){
               if(rmq[j][0].ff > rmq[i][0].ff) break;
               vl[i][j] = Secret(a[j], vl[i][j+1]);
          }
          vl[i][i+1] = a[i+1];
          rep(j,i+2,n+1){
               if(rmq[j][0].ff > rmq[i][0].ff) break;
               vl[i][j] = Secret(vl[i][j-1], a[j]);
          }
     }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 120 ms 4428 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
2 Correct 124 ms 4432 KB Output is correct - number of calls to Secret by Init = 4097, maximum number of calls to Secret by Query = 1
3 Correct 130 ms 4500 KB Output is correct - number of calls to Secret by Init = 4098, maximum number of calls to Secret by Query = 1
4 Correct 432 ms 8360 KB Output is correct - number of calls to Secret by Init = 7986, maximum number of calls to Secret by Query = 1
5 Correct 428 ms 8328 KB Output is correct - number of calls to Secret by Init = 7998, maximum number of calls to Secret by Query = 1
6 Correct 430 ms 8344 KB Output is correct - number of calls to Secret by Init = 7998, maximum number of calls to Secret by Query = 1
7 Correct 436 ms 8296 KB Output is correct - number of calls to Secret by Init = 7998, maximum number of calls to Secret by Query = 1
8 Correct 431 ms 8344 KB Output is correct - number of calls to Secret by Init = 7998, maximum number of calls to Secret by Query = 1
9 Correct 450 ms 8268 KB Output is correct - number of calls to Secret by Init = 7998, maximum number of calls to Secret by Query = 1
10 Correct 429 ms 8396 KB Output is correct - number of calls to Secret by Init = 7998, maximum number of calls to Secret by Query = 1