답안 #674801

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
674801 2022-12-26T08:34:43 Z Valera_Grinenko 비밀 (JOI14_secret) C++17
0 / 100
449 ms 8564 KB
#include "secret.h"
#include <vector>
using namespace std;

template<class T> struct onlineDQ {
  static const int SZ = (1 << 10);
  int n;
  T stor[SZ][32-__builtin_clz(SZ)], id = 1;
	vector<T> a;
	T comb (T a, T b) { if(a == -1) return b; if(b == -1) return b; return Secret(a, b); } // associative operation
	void fill(int l, int r, int ind) {
    if(l == r) {
      stor[l][ind] = a[l];
      return;
    }
		int m = (l+r)/2;
    stor[m][ind] = a[m];
    for(int i = m - 1; i >= l; i--) stor[i][ind] = comb(a[i], stor[i + 1][ind]);
    stor[m + 1][ind] = a[m + 1];
    for(int i = m + 2; i < r; i++) stor[i][ind] = comb(stor[i - 1][ind] ,a[i]);
		fill(l,m,ind-1); fill(m,r,ind-1);
	}
	void init() {
		n = 1; while ((1<<n) < (int)a.size()) ++n;
    while(a.size() < (1 << n)) a.push_back(-1);
    fill(0,(1<<n),n-1);
	}
	T query(int l, int r) {
		if (l == r) return a[l];
		int t = 31-__builtin_clz(r^l);
		return comb(stor[l][t],stor[r][t]);
	}
};

onlineDQ<int> odq;

void Init(int N, int A[]) {
  odq.a.resize(N);
  for(int i = 0; i < N; i++) odq.a[i] = A[i];
  odq.init();
}

int Query(int L, int R) {
  return odq.query(L, R);
}

Compilation message

secret.cpp: In instantiation of 'void onlineDQ<T>::init() [with T = int]':
secret.cpp:40:12:   required from here
secret.cpp:25:20: warning: comparison of integer expressions of different signedness: 'std::vector<int, std::allocator<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   25 |     while(a.size() < (1 << n)) a.push_back(-1);
      |           ~~~~~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 133 ms 8396 KB Execution killed with signal 11
2 Runtime error 137 ms 8564 KB Execution killed with signal 11
3 Runtime error 132 ms 8420 KB Execution killed with signal 11
4 Runtime error 434 ms 8564 KB Execution killed with signal 11
5 Runtime error 430 ms 8496 KB Execution killed with signal 11
6 Runtime error 449 ms 8492 KB Execution killed with signal 11
7 Runtime error 435 ms 8512 KB Execution killed with signal 11
8 Runtime error 443 ms 8492 KB Execution killed with signal 11
9 Runtime error 435 ms 8456 KB Execution killed with signal 11
10 Runtime error 438 ms 8452 KB Execution killed with signal 11