Submission #85565

# Submission time Handle Problem Language Result Execution time Memory
85565 2018-11-20T23:40:33 Z KCSC Secret (JOI14_secret) C++14
6 / 100
662 ms 6184 KB
#include <bits/stdc++.h>
using namespace std;

int Secret(int x, int y);
void Init(int n, int arr[]);
int Query(int le, int ri);
/*
int Secret(int x, int y) {
	return x xor y xor 13; }
*/
int secret(int x, int y) {
	static map<pair<int, int>, int> mmp;
	if (mmp.find(make_pair(x, y)) != mmp.end()) {
		return mmp[make_pair(x, y)]; }
	else
		return (mmp[make_pair(x, y)] = Secret(x, y)); }

const int DIM = 1005;
vector<int> lef[DIM * 4], rig[DIM * 4];

void build(int nd, int le, int ri, int arr[]) {
	if (le != ri) {
		int md = (le + ri) / 2;
		build(nd * 2, le, md, arr);	
		build(nd * 2 + 1, md + 1, ri, arr); }
	lef[nd].resize(ri - le + 1); lef[nd][0] = arr[le];
	rig[nd].resize(ri - le + 1); rig[nd][ri - le] = arr[ri];	 
	if (le != ri and nd != 1) {
		int md = (le + ri) / 2;
		for (int i = 1; i <= ri - le; ++i) {
			lef[nd][i] = secret(lef[nd][i - 1], arr[le + i]); }
		for (int i = ri - le - 1; i >= 0; --i) {
			rig[nd][i] = secret(arr[le + i], rig[nd][i + 1]); } } }  
		

int query(int nd, int le, int ri, int st, int en) {
	if (le == ri) {
		return lef[nd][0]; }
	else {
		int md = (le + ri) / 2;
		if (en <= md) {
			return query(nd * 2, le, md, st, en); }
		if (md <  st) {
			return query(nd * 2 + 1, md + 1, ri, st, en); }
		return secret(rig[nd * 2][st - le], lef[nd * 2 + 1][en - (md + 1)]); } } 

int _n;
void Init(int n, int arr[]) {
	build(1, 0, n - 1, arr); _n = n; }

int Query(int le, int ri) {
	return query(1, 0, _n - 1, le, ri); }
/*
int arr[10];

int main(void) {
#ifdef HOME
	freopen("secret.in", "r", stdin);
	freopen("secret.out", "w", stdout);
#endif
	int n; cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> arr[i]; }
	Init(n, arr);
	int m; cin >> m;
	while (m--) {
		int le, ri; cin >> le >> ri;
		int val = arr[le];
		for (int i = le + 1; i <= ri; ++i) {
			val = Secret(val, arr[i]); }
		cout << Query(le, ri) << " " << val << "\n"; }
	return 0; }	
*/

Compilation message

secret.cpp: In function 'void build(int, int, int, int*)':
secret.cpp:29:7: warning: unused variable 'md' [-Wunused-variable]
   int md = (le + ri) / 2;
       ^~
# Verdict Execution time Memory Grader output
1 Correct 189 ms 3704 KB Output is correct - number of calls to Secret by Init = 3832, maximum number of calls to Secret by Query = 1
2 Correct 187 ms 3708 KB Output is correct - number of calls to Secret by Init = 3840, maximum number of calls to Secret by Query = 1
3 Correct 187 ms 3708 KB Output is correct - number of calls to Secret by Init = 3850, maximum number of calls to Secret by Query = 1
4 Incorrect 627 ms 5920 KB Output isn't correct - number of calls to Secret by Init = 8479, maximum number of calls to Secret by Query = 1
5 Incorrect 639 ms 5936 KB Output isn't correct - number of calls to Secret by Init = 8488, maximum number of calls to Secret by Query = 1
6 Incorrect 662 ms 5984 KB Output isn't correct - number of calls to Secret by Init = 8488, maximum number of calls to Secret by Query = 1
7 Incorrect 644 ms 6084 KB Output isn't correct - number of calls to Secret by Init = 8488, maximum number of calls to Secret by Query = 1
8 Incorrect 634 ms 6084 KB Output isn't correct - number of calls to Secret by Init = 8488, maximum number of calls to Secret by Query = 1
9 Incorrect 630 ms 6084 KB Output isn't correct - number of calls to Secret by Init = 8488, maximum number of calls to Secret by Query = 1
10 Incorrect 628 ms 6184 KB Output isn't correct - number of calls to Secret by Init = 8488, maximum number of calls to Secret by Query = 1