답안 #553270

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
553270 2022-04-25T10:05:50 Z cadmiumsky 비밀 (JOI14_secret) C++14
0 / 100
444 ms 4596 KB
#include "secret.h"
#include <bits/stdc++.h>
using namespace std;
const int nmax = 1e3 + 5;

vector<int> v;

namespace RMQ {
  int atr[nmax];
  int rmq[12][nmax];
  void color(int l, int r, int bit = 0) {
    //cerr << l << ' ' << r << ' ' << bit << '\n';
    if(l + 1 >= r) {
      while(l <= r)
        atr[l] = bit, l++;
      return;
    }
    int mid = l + r >> 1;
    atr[mid] = atr[mid + 1] = bit;
    color(l, mid - 1, bit + 1);
    color(mid + 2, r, bit + 1);
    rmq[bit][mid] = v[mid];
    rmq[bit][mid + 1] = v[mid + 1];
    for(int i = mid - 1; i >= l; i--)
      rmq[bit][i] = Secret(v[i], rmq[bit][i + 1]);
    for(int i = mid + 2; i <= r; i++)
      rmq[bit][i] = Secret(rmq[bit][i - 1], v[i]);
    return;
  }
  namespace IRMQ {
    pair<int,int> irmq[12][nmax];
    int lg[nmax];
    void init(int n, int *vec) {
      lg[1] = 0;
      for(int i = 2; i <= n; i++)
        lg[i] = lg[i >> 1] + 1;
      for(int i = 0; i < n; i++)
        irmq[0][i] = {vec[i], i};
      for(int bit = 1; bit < 12; bit++) {
        for(int i = 0; i + (1 << bit) <= n; i++)
          irmq[bit][i] = min(irmq[bit - 1][i], irmq[bit - 1][i + (1 << bit - 1)]);
      }
    }
    pair<int,int> query(int l, int r) {
      int st = lg[r - l + 1];
      return min(irmq[st][l], irmq[st][r - (1 << st) + 1]);
    } 
  }
  int query(int l, int r) {
    if(l == r) 
      return v[l];
    else if(l == r - 1)
      return Secret(v[l], v[r]);
    auto level = IRMQ::query(l, r);
    if(r == level.second)
      return rmq[level.first][l];
    if(l == level.second)
      return rmq[level.first][r];
    return Secret(rmq[level.first][l], rmq[level.first][r]);
  }
}


void Init(int N, int A[]) {
  //cerr << "YES\n";
  v.resize(N);
  for(int i = 0; i < N; i++)
    v[i] = A[i];
  RMQ::color(0, N - 1);
  RMQ::IRMQ::init(N, RMQ::atr);
  //cerr << "NO\n";
}

int Query(int L, int R) {
  //cerr << "YES\n";
  //return 0;
  return RMQ::query(L, R);
}

Compilation message

secret.cpp: In function 'void RMQ::color(int, int, int)':
secret.cpp:18:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   18 |     int mid = l + r >> 1;
      |               ~~^~~
secret.cpp: In function 'void RMQ::IRMQ::init(int, int*)':
secret.cpp:41:76: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   41 |           irmq[bit][i] = min(irmq[bit - 1][i], irmq[bit - 1][i + (1 << bit - 1)]);
      |                                                                        ~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 111 ms 2504 KB Wrong Answer: Query(255, 409) - expected : 307522235, actual : 827471512.
2 Incorrect 113 ms 2532 KB Wrong Answer: Query(127, 153) - expected : 342921603, actual : 708520034.
3 Incorrect 115 ms 2532 KB Wrong Answer: Query(385, 464) - expected : 481761362, actual : 623194488.
4 Incorrect 425 ms 4596 KB Wrong Answer: Query(374, 396) - expected : 402362963, actual : 564777122.
5 Incorrect 420 ms 4408 KB Wrong Answer: Query(750, 875) - expected : 92309526, actual : 105011204.
6 Incorrect 423 ms 4428 KB Wrong Answer: Query(747, 749) - expected : 244228265, actual : 741392144.
7 Correct 433 ms 4432 KB Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1
8 Correct 441 ms 4468 KB Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1
9 Correct 427 ms 4364 KB Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1
10 Correct 444 ms 4468 KB Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1