답안 #542683

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
542683 2022-03-27T13:32:43 Z __Variatto 비밀 (JOI14_secret) C++17
100 / 100
501 ms 4472 KB
#include <bits/stdc++.h>
#include "secret.h"
using namespace std;
#define pb push_back
#define fi first
#define se second
#define ll long long
const ll MAX=1e3+10, L=10;
ll n, daq[MAX][L+2], q, a, b, t[MAX], pot, skad[MAX][L+2];
/*ll Secret(ll a, ll b){
    return a*b;
}
*/int znajdz(int pocz, int kon, int l, int r, int nr){
    int sr=(pocz+kon)/2;
    if(sr>=l && sr<=r) return nr;
    if(sr<l) return znajdz(sr+1, kon, l, r, nr+1);
    else return znajdz(pocz, sr, l, r, nr+1);
}
int Query(int l, int r){
    if(l==r) return t[l];
    ll x=znajdz(0, n-1, l, r, 1);
    if(r==skad[r][x]) return daq[l][x];
    //cout<<x<<" "<<skad[r][x]<<" "<<skad[l][x]<<"\n";
    return Secret(daq[l][x], daq[r][x]);
}
void rek(int pocz, int kon, int nr){
    if(pocz==kon){
        daq[pocz][nr]=t[pocz];
        return;
    }
    ll sr=(pocz+kon)/2;
    daq[sr][nr]=t[sr], skad[sr][nr]=sr;
    //cout<<sr<<" "<<nr<<"\n";
    if(sr+1<=kon)
        daq[sr+1][nr]=t[sr+1], skad[sr+1][nr]=sr;
    for(ll i=sr-1; i>=pocz; i--) daq[i][nr]=Secret(t[i], daq[i+1][nr]), skad[i][nr]=sr;
    for(ll i=sr+2; i<=kon; i++) daq[i][nr]=Secret(daq[i-1][nr], t[i]), skad[i][nr]=sr;
    rek(pocz, sr, nr+1);
    rek(sr+1, kon, nr+1);
}
void Init(int N, int A[]){
    n=N;
    for(ll i=0; i<n; i++)
        t[i]=A[i];
    rek(0, n-1, 1);
}
/*int main(){
    //ios_base::sync_with_stdio(false);
    //cin.tie(0), cout.tie(0);
    int n1;
    cin>>n1;
    int A1[n1];
    for(ll i=0; i<n1; i++) cin>>A1[i];
    Init(n1, A1);
    ll q1;
    cin>>q1;
    while(q1--){
        ll a, b;
        cin>>a>>b;
        cout<<Query(a, b)<<"\n";
    }
}
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 134 ms 2368 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 143 ms 2452 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 132 ms 2456 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 472 ms 4356 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 482 ms 4464 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 473 ms 4388 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 481 ms 4472 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 469 ms 4416 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 499 ms 4356 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 501 ms 4372 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1