답안 #553277

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
553277 2022-04-25T10:38:51 Z cadmiumsky 비밀 (JOI14_secret) C++14
0 / 100
484 ms 4448 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] = -bit;
    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] = {abs(vec[i]), vec[i] / abs(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[]) {
  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);
}

int Query(int L, int R) {
  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:42:76: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   42 |           irmq[bit][i] = min(irmq[bit - 1][i], irmq[bit - 1][i + (1 << bit - 1)]);
      |                                                                        ~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 112 ms 2380 KB Wrong Answer: Query(264, 271) - expected : 675707686, actual : 675306646.
2 Incorrect 129 ms 2368 KB Wrong Answer: Query(236, 238) - expected : 173116186, actual : 416517106.
3 Incorrect 120 ms 2456 KB Wrong Answer: Query(128, 153) - expected : 959658850, actual : 219466354.
4 Incorrect 442 ms 4288 KB Wrong Answer: Query(374, 396) - expected : 402362963, actual : 564777122.
5 Incorrect 426 ms 4372 KB Wrong Answer: Query(626, 678) - expected : 512755800, actual : 356156688.
6 Incorrect 460 ms 4300 KB Wrong Answer: Query(26, 30) - expected : 321366825, actual : 195833138.
7 Correct 458 ms 4448 KB Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1
8 Correct 438 ms 4384 KB Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1
9 Correct 465 ms 4316 KB Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1
10 Correct 484 ms 4344 KB Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1