답안 #1092375

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1092375 2024-09-24T00:21:44 Z vjudge1 비밀 (JOI14_secret) C++17
100 / 100
329 ms 12368 KB
#include <bits/stdc++.h>
#include "secret.h"
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC target("popcnt")
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using lld = long double;
using ii = pair<int,int>;
using pll = pair<ll, ll>;
 
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<ii>;
using vpll = vector<pll>;
using vlld = vector<lld>;
 
// #define endl '\n'
#define all(x) x.begin(),x.end()
#define lsb(x) x&(-x)
#define gcd(a,b) __gcd(a,b)
#define sz(x) (int)x.size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fls cout.flush()
 
#define fore(i,l,r) for(auto i=l;i<r;i++)
#define fo(i,n) fore(i,0,n)
#define forex(i,r,l) for(auto i=r; i>=l;i--)
#define ffo(i,n) forex(i,n-1,0)
 
bool cmin(ll &a, ll b) { if(b<a){a=b;return 1;}return 0; }
bool cmax(ll &a, ll b) { if(b>a){a=b;return 1;}return 0; }
void valid(ll in) { cout<<((in)?"YES\n":"NO\n"); }
ll lcm(ll a, ll b) { return (a/gcd(a,b))*b; }
ll gauss(ll n) { return (n*(n+1))/2; }

const int N = 1001;
int n, a[N], pr[4*N][N], sf[4*N][N];

void build(int id, int l, int r) {
    if (l == r) return;
    int m = (l+r)/2;
    pr[id][m+1] = a[m+1];
    fore (i, m+2, r+1) pr[id][i] = Secret(pr[id][i-1], a[i]);
    sf[id][m] = a[m];
    forex (i, m-1, l) sf[id][i] = Secret(a[i], sf[id][i+1]);
    build(id*2, l, m);
    build(id*2+1, m+1, r);
}

void Init (int n, int A[]) {
    ::n = n;
    fo (i, n) a[i] = A[i];
    build(1, 0, n-1);
}

int Query(int i, int j) {
    if (i == j) return a[i];
    int l = 0, r = n-1, id = 1;
    while (1) {
        int m = (l+r)/2;
        if (i<=m && j>m) return Secret(sf[id][i], pr[id][j]);
        if (i<=m) r = m, id = id*2;
        if (i>m) l = m+1, id = id*2+1;
    }
}

Compilation message

secret.cpp:5: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    5 | #pragma GCC optimization ("O3")
      | 
secret.cpp:6: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    6 | #pragma GCC optimization ("unroll-loops")
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 6484 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 87 ms 6540 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 6484 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 316 ms 12116 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 315 ms 12112 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 12092 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 312 ms 12112 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 314 ms 12368 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 329 ms 12196 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 321 ms 12112 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1