Submission #262037

# Submission time Handle Problem Language Result Execution time Memory
262037 2020-08-12T10:01:13 Z patrikpavic2 Minerals (JOI19_minerals) C++17
70 / 100
43 ms 2940 KB
#include "minerals.h"
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstdlib>

#define X first
#define Y second
#define PB push_back

using namespace std;

typedef long long ll;
typedef pair < int, int > pii;

const int N = 1e5 + 500;

int kod[N], tp[N], P[N], ans[N];
int un[N], lst = 0, mks = 0, n;

int pitaj(int x){
	int nw = Query(x);
	int ret = abs(lst - nw);
	lst = nw; un[x] = !un[x];
	return ret;
}

void pripremi(int l, int r, int raz){
	if(l == r) return;
	mks = max(mks, raz);
	for(int i = l;i <= (l + r) / 2;i++)
		kod[i] += (1 << raz);
	pripremi(l, (l + r) / 2, raz + 1);
	pripremi((l + r) / 2 + 1, r, raz + 1);
}

void odradi(int red){
	for(int i = 1;i <= 2 * n;i++){
		if(!tp[i] && (un[i] ^ (!!(P[i] & (1 << red)))))
			pitaj(i);
	}
	for(int i = 1;i <= 2 * n;i++)
		if(tp[i]){
			int odg = !pitaj(i);
			P[i] += odg * (1 << red);
		}
}

bool cmp(int x, int y){
	return P[x] < P[y];
}

void Solve(int nn) {
	n = nn; 
	pripremi(0, n - 1, 0);
	int cur = 0;
	for(int i = 1;i <= 2 * n;i++){
		tp[i] = pitaj(i); ans[i - 1] = i;
		if(!tp[i])
			P[i] = kod[cur++];
	}
	for(int i = 0;i <= mks;i++)
		odradi(i);
	sort(ans, ans + 2 * n, cmp);
	for(int i = 0;i < n;i++){
		Answer(ans[2 * i], ans[2 * i + 1]);
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 3 ms 640 KB Output is correct
4 Correct 6 ms 896 KB Output is correct
5 Correct 13 ms 1280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 6 ms 896 KB Output is correct
9 Correct 13 ms 1280 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 12 ms 1024 KB Output is correct
12 Correct 15 ms 1280 KB Output is correct
13 Correct 11 ms 1408 KB Output is correct
14 Correct 11 ms 1280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 6 ms 896 KB Output is correct
9 Correct 13 ms 1280 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 12 ms 1024 KB Output is correct
12 Correct 15 ms 1280 KB Output is correct
13 Correct 11 ms 1408 KB Output is correct
14 Correct 11 ms 1280 KB Output is correct
15 Correct 43 ms 2808 KB Output is correct
16 Correct 43 ms 2808 KB Output is correct
17 Correct 30 ms 2940 KB Output is correct
18 Correct 31 ms 2680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 6 ms 896 KB Output is correct
9 Correct 13 ms 1280 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 12 ms 1024 KB Output is correct
12 Correct 15 ms 1280 KB Output is correct
13 Correct 11 ms 1408 KB Output is correct
14 Correct 11 ms 1280 KB Output is correct
15 Correct 43 ms 2808 KB Output is correct
16 Correct 43 ms 2808 KB Output is correct
17 Correct 30 ms 2940 KB Output is correct
18 Correct 31 ms 2680 KB Output is correct
19 Incorrect 35 ms 2560 KB Wrong Answer [2]
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 6 ms 896 KB Output is correct
9 Correct 13 ms 1280 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 12 ms 1024 KB Output is correct
12 Correct 15 ms 1280 KB Output is correct
13 Correct 11 ms 1408 KB Output is correct
14 Correct 11 ms 1280 KB Output is correct
15 Correct 43 ms 2808 KB Output is correct
16 Correct 43 ms 2808 KB Output is correct
17 Correct 30 ms 2940 KB Output is correct
18 Correct 31 ms 2680 KB Output is correct
19 Incorrect 35 ms 2560 KB Wrong Answer [2]
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 6 ms 896 KB Output is correct
9 Correct 13 ms 1280 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 12 ms 1024 KB Output is correct
12 Correct 15 ms 1280 KB Output is correct
13 Correct 11 ms 1408 KB Output is correct
14 Correct 11 ms 1280 KB Output is correct
15 Correct 43 ms 2808 KB Output is correct
16 Correct 43 ms 2808 KB Output is correct
17 Correct 30 ms 2940 KB Output is correct
18 Correct 31 ms 2680 KB Output is correct
19 Incorrect 35 ms 2560 KB Wrong Answer [2]
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 6 ms 896 KB Output is correct
9 Correct 13 ms 1280 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 12 ms 1024 KB Output is correct
12 Correct 15 ms 1280 KB Output is correct
13 Correct 11 ms 1408 KB Output is correct
14 Correct 11 ms 1280 KB Output is correct
15 Correct 43 ms 2808 KB Output is correct
16 Correct 43 ms 2808 KB Output is correct
17 Correct 30 ms 2940 KB Output is correct
18 Correct 31 ms 2680 KB Output is correct
19 Incorrect 35 ms 2560 KB Wrong Answer [2]
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 6 ms 896 KB Output is correct
9 Correct 13 ms 1280 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 12 ms 1024 KB Output is correct
12 Correct 15 ms 1280 KB Output is correct
13 Correct 11 ms 1408 KB Output is correct
14 Correct 11 ms 1280 KB Output is correct
15 Correct 43 ms 2808 KB Output is correct
16 Correct 43 ms 2808 KB Output is correct
17 Correct 30 ms 2940 KB Output is correct
18 Correct 31 ms 2680 KB Output is correct
19 Incorrect 35 ms 2560 KB Wrong Answer [2]
20 Halted 0 ms 0 KB -