답안 #1085592

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1085592 2024-09-08T13:07:18 Z MrPavlito 비밀 (JOI14_secret) C++17
0 / 100
326 ms 9552 KB
#include "secret.h"
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define sc second
//#define endl "\n"
#define pii pair<int,int>

using namespace std;

const int MAXN = 1e3+5;
const int mod7 = 1e9+7;
const long long inf = 1e18;
int niz[MAXN];
int n;
map<pii, int> mapa;
vector<vector<int>> v(MAXN, vector<int>(MAXN));

int ask(int a, int b)
{
    if(mapa.count(mp(a,b)))return mapa[mp(a,b)];
    int p =  Secret(a,b);
    mapa[{a,b}] = p;
    return p;
}

void build(int l, int r, int lvl)
{
    if(l == r)
    {
        v[lvl][l] = niz[l];
        return;
    }
    int mid = l+r >> 1;
    v[lvl][mid] = niz[mid];
    v[lvl][mid+1] = niz[mid+1];
    for(int i=mid+2;i<=r; i++)v[lvl][i] = ask(v[lvl][i-1], niz[i]);
    for(int i=mid-1;i>=l; i--)v[lvl][i] = ask( niz[i],v[lvl][i+1]);
    //for(int i=mid;i>=l; i--)cout << v[lvl][i] << " ";cout << endl;
    build(l, mid, lvl+1);
    build(mid+1,r, lvl+1);
}


int query(int l, int r, int lvl, int L, int R)
{
    int mid = l+r>>1;
    if(L <= mid && R> mid)return ask(v[lvl][L], v[lvl][R]);
    else if(R == mid)return v[lvl][L];
    else if(L > mid)return query(mid+1, r, lvl+1, L, R);
    else return query(l, mid+1, lvl+1, L, R);
}

void Init(int N, int A[]) {
    n = N;
    for(int i=1; i<=n; i++)niz[i] = A[i-1];
    build(1,n, 0);
}

int Query(int L, int R) {
    if(L == R)return niz[L+1];
  return (query(1, n, 0, L+1, R+1));
}

Compilation message

secret.cpp: In function 'void build(int, int, int)':
secret.cpp:36:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   36 |     int mid = l+r >> 1;
      |               ~^~
secret.cpp: In function 'int query(int, int, int, int, int)':
secret.cpp:49:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   49 |     int mid = l+r>>1;
      |               ~^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 85 ms 6548 KB Wrong Answer: Query(264, 271) - expected : 675707686, actual : 406865628.
2 Incorrect 83 ms 6760 KB Wrong Answer: Query(236, 238) - expected : 173116186, actual : 416517106.
3 Incorrect 82 ms 6740 KB Wrong Answer: Query(130, 131) - expected : 127065177, actual : 982344857.
4 Incorrect 318 ms 8788 KB Wrong Answer: Query(45, 63) - expected : 20048392, actual : 307931147.
5 Incorrect 325 ms 8724 KB Wrong Answer: Query(566, 580) - expected : 56788056, actual : 941135120.
6 Incorrect 310 ms 8864 KB Wrong Answer: Query(250, 258) - expected : 907404, actual : 12475405.
7 Correct 322 ms 9552 KB Output is correct - number of calls to Secret by Init = 7491, maximum number of calls to Secret by Query = 1
8 Correct 318 ms 9484 KB Output is correct - number of calls to Secret by Init = 7491, maximum number of calls to Secret by Query = 1
9 Correct 325 ms 9376 KB Output is correct - number of calls to Secret by Init = 7491, maximum number of calls to Secret by Query = 1
10 Correct 326 ms 9552 KB Output is correct - number of calls to Secret by Init = 7491, maximum number of calls to Secret by Query = 1