답안 #133350

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
133350 2019-07-20T12:29:57 Z egorlifar 비밀 (JOI14_secret) C++17
0 / 100
634 ms 4476 KB
#include "secret.h"
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>

using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left224
#define right right224
#define next next224
#define rank rank224
#define prev prev224
#define y1 y1224
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define files(FILENAME) read(FILENAME), write(FILENAME)
#define pb push_back
#define mp make_pair
const int MAXN = 1003;


int n;
int val[MAXN][10];
int val1[MAXN][10];


void Init(int N, int A[]) {
	n = N;
	for (int i = 1; i <= n; i++) {
		val[i][0] = A[i - 1];
		val1[i][0] = A[i - 1];
	}
	for (int k = 1; k <= 9; k++) {
		for (int i = (1 << k); i <= n; i++) {
			int f = i % (1 << k);
			if (i == 1 || f == 0) {
				val[i][k] = val[i][0];
				continue;
			}
			if ((i % (1 << (k - 1))) == (1 << (k - 1)) - 1 && (i % (1 << (k - 1))) == (i % (1 << k))) {
				val[i][k] = val1[max(1, i - (1 << (k - 1)) + 1)][k - 1];
				continue;
			}
			if (i - f == i - i % (1 << (k - 1))) {
				val[i][k] = val[i][k - 1];
			} else {
				val[i][k] = Secret(val[i - 1][k], val[i][0]);
			}
		}
		for (int i = n; i >= 1; i--) {
			if (i % (1 << k) == 0) {
				val1[i][k] = val[min(n, i + (1 << k) - 1)][k];
				continue;
			}
			if (i == n || (i % (1 << k)) == (1 << k) - 1) {
				val1[i][k] = val1[i][0];
				continue;
			}
			int g = i % (1 << k);
			int ft = (1 << k) - g - 1;
			int g1 = i % (1 << (k - 1));
			int ft1 = (1 << (k - 1)) - g1 - 1;
			int h = i + ft;
			int h1 = i + ft1;
			if (h == h1) {
				val1[i][k] = val1[i][k - 1];
			} else {
				val1[i][k] = Secret(val1[i][0], val1[i + 1][k]);
			}
		}
	}
}


int Query(int L, int R) {
	int l = L;
	int r = R;
	l++;
	r++;
	int f = 0;
	int g;
	bool was = false;
	for (g = 1; g <= 512; g *= 2) {
		int pos = -1;
		for (int i = l; i <= r; i++) {
			if (i % g == 0) {
				pos = i;
				break;
			}
		}
		if (pos != -1 && pos + g > r && pos - 1 - g < l) {
			was = true;
			break;
		}
		f++;
	}
	assert(was);
	//cout << l << ' ' << r << ' ' << g << endl;
	if (l % g == 0) {
		return val1[l][f];
	}
	return Secret(val1[l][f], val[r][f]);
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 158 ms 2424 KB Wrong Answer: Query(255, 409) - expected : 307522235, actual : 289427856.
2 Incorrect 159 ms 2560 KB Wrong Answer: Query(127, 153) - expected : 342921603, actual : 507060427.
3 Incorrect 160 ms 2424 KB Wrong Answer: Query(191, 230) - expected : 765645052, actual : 429206004.
4 Incorrect 585 ms 4368 KB Wrong Answer: Query(511, 746) - expected : 648741079, actual : 104464925.
5 Incorrect 584 ms 4468 KB Wrong Answer: Query(383, 409) - expected : 851502408, actual : 694331716.
6 Incorrect 596 ms 4372 KB Wrong Answer: Query(747, 749) - expected : 244228265, actual : 48515797.
7 Correct 634 ms 4468 KB Output is correct - number of calls to Secret by Init = 7494, maximum number of calls to Secret by Query = 1
8 Correct 629 ms 4428 KB Output is correct - number of calls to Secret by Init = 7494, maximum number of calls to Secret by Query = 1
9 Correct 632 ms 4396 KB Output is correct - number of calls to Secret by Init = 7494, maximum number of calls to Secret by Query = 1
10 Correct 630 ms 4476 KB Output is correct - number of calls to Secret by Init = 7494, maximum number of calls to Secret by Query = 1