Submission #262059

# Submission time Handle Problem Language Result Execution time Memory
262059 2020-08-12T10:17:48 Z patrikpavic2 Minerals (JOI19_minerals) C++17
80 / 100
169 ms 56948 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], izb[N];
int un[N], lst = 0, mks = 0, n;
vector < int > kol[20][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(!izb[i] && !tp[i] && (un[i] ^ (!!(P[i] & (1 << red)))))
			pitaj(i);
	}
	for(int i = 1;i <= 2 * n;i++)
		if(tp[i] && !ans[i]){
			int odg = !pitaj(i);
			P[i] += odg * (1 << red);
		}
}

inline void mozda(int red){
	for(int i = 1;i <= 2 * n;i++){
		if(!tp[i] || ans[i]) continue;
		while(izb[kol[red][P[i]].back()]) kol[red][P[i]].pop_back();
		//printf("i = %d P[i] = %d kol = %d\n", i, P[i], (int)kol[red][P[i]].size());
		if(lower_bound(kol[red][P[i]].begin(), kol[red][P[i]].end(), i) + 1 == kol[red][P[i]].end()){
			ans[i] = *lower_bound(kol[red][P[i]].begin(), kol[red][P[i]].end(), i);
			izb[ans[i]] = 1;
		//	printf("nasao\n");
		}
	}	
	
}

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);
		if(!tp[i]){
			P[i] = kod[cur++];
			for(int j = 0;j <= mks + 1;j++)
				kol[j][P[i] & ((1 << j) - 1)].PB(i);
		}
	}
	mozda(0); mozda(0);
	for(int i = 0;i <= mks;i++){
		odradi(i);
		mozda(i + 1); mozda(i + 1);
	}
	for(int i = 1;i <= 2 * n;i++){
		//if(tp[i]) printf("%d %d\n", i, ans[i]);
		if(tp[i]) Answer(i, ans[i]);
	}
}
# Verdict Execution time Memory Grader output
1 Correct 32 ms 47616 KB Output is correct
2 Correct 31 ms 47616 KB Output is correct
3 Correct 32 ms 47608 KB Output is correct
4 Correct 31 ms 47608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 47736 KB Output is correct
2 Correct 34 ms 47872 KB Output is correct
3 Correct 37 ms 48248 KB Output is correct
4 Correct 46 ms 48940 KB Output is correct
5 Correct 57 ms 50168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 47616 KB Output is correct
2 Correct 31 ms 47616 KB Output is correct
3 Correct 32 ms 47608 KB Output is correct
4 Correct 31 ms 47608 KB Output is correct
5 Correct 40 ms 47736 KB Output is correct
6 Correct 34 ms 47872 KB Output is correct
7 Correct 37 ms 48248 KB Output is correct
8 Correct 46 ms 48940 KB Output is correct
9 Correct 57 ms 50168 KB Output is correct
10 Correct 33 ms 47744 KB Output is correct
11 Correct 54 ms 49788 KB Output is correct
12 Correct 69 ms 50296 KB Output is correct
13 Correct 61 ms 50296 KB Output is correct
14 Correct 56 ms 50296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 47616 KB Output is correct
2 Correct 31 ms 47616 KB Output is correct
3 Correct 32 ms 47608 KB Output is correct
4 Correct 31 ms 47608 KB Output is correct
5 Correct 40 ms 47736 KB Output is correct
6 Correct 34 ms 47872 KB Output is correct
7 Correct 37 ms 48248 KB Output is correct
8 Correct 46 ms 48940 KB Output is correct
9 Correct 57 ms 50168 KB Output is correct
10 Correct 33 ms 47744 KB Output is correct
11 Correct 54 ms 49788 KB Output is correct
12 Correct 69 ms 50296 KB Output is correct
13 Correct 61 ms 50296 KB Output is correct
14 Correct 56 ms 50296 KB Output is correct
15 Correct 145 ms 56620 KB Output is correct
16 Correct 147 ms 56684 KB Output is correct
17 Correct 128 ms 56564 KB Output is correct
18 Correct 115 ms 56048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 47616 KB Output is correct
2 Correct 31 ms 47616 KB Output is correct
3 Correct 32 ms 47608 KB Output is correct
4 Correct 31 ms 47608 KB Output is correct
5 Correct 40 ms 47736 KB Output is correct
6 Correct 34 ms 47872 KB Output is correct
7 Correct 37 ms 48248 KB Output is correct
8 Correct 46 ms 48940 KB Output is correct
9 Correct 57 ms 50168 KB Output is correct
10 Correct 33 ms 47744 KB Output is correct
11 Correct 54 ms 49788 KB Output is correct
12 Correct 69 ms 50296 KB Output is correct
13 Correct 61 ms 50296 KB Output is correct
14 Correct 56 ms 50296 KB Output is correct
15 Correct 145 ms 56620 KB Output is correct
16 Correct 147 ms 56684 KB Output is correct
17 Correct 128 ms 56564 KB Output is correct
18 Correct 115 ms 56048 KB Output is correct
19 Correct 149 ms 56948 KB Output is correct
20 Correct 169 ms 56880 KB Output is correct
21 Correct 136 ms 56692 KB Output is correct
22 Correct 118 ms 56180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 47616 KB Output is correct
2 Correct 31 ms 47616 KB Output is correct
3 Correct 32 ms 47608 KB Output is correct
4 Correct 31 ms 47608 KB Output is correct
5 Correct 40 ms 47736 KB Output is correct
6 Correct 34 ms 47872 KB Output is correct
7 Correct 37 ms 48248 KB Output is correct
8 Correct 46 ms 48940 KB Output is correct
9 Correct 57 ms 50168 KB Output is correct
10 Correct 33 ms 47744 KB Output is correct
11 Correct 54 ms 49788 KB Output is correct
12 Correct 69 ms 50296 KB Output is correct
13 Correct 61 ms 50296 KB Output is correct
14 Correct 56 ms 50296 KB Output is correct
15 Correct 145 ms 56620 KB Output is correct
16 Correct 147 ms 56684 KB Output is correct
17 Correct 128 ms 56564 KB Output is correct
18 Correct 115 ms 56048 KB Output is correct
19 Correct 149 ms 56948 KB Output is correct
20 Correct 169 ms 56880 KB Output is correct
21 Correct 136 ms 56692 KB Output is correct
22 Correct 118 ms 56180 KB Output is correct
23 Correct 166 ms 56820 KB Output is correct
24 Correct 162 ms 56820 KB Output is correct
25 Correct 140 ms 56820 KB Output is correct
26 Correct 116 ms 56304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 47616 KB Output is correct
2 Correct 31 ms 47616 KB Output is correct
3 Correct 32 ms 47608 KB Output is correct
4 Correct 31 ms 47608 KB Output is correct
5 Correct 40 ms 47736 KB Output is correct
6 Correct 34 ms 47872 KB Output is correct
7 Correct 37 ms 48248 KB Output is correct
8 Correct 46 ms 48940 KB Output is correct
9 Correct 57 ms 50168 KB Output is correct
10 Correct 33 ms 47744 KB Output is correct
11 Correct 54 ms 49788 KB Output is correct
12 Correct 69 ms 50296 KB Output is correct
13 Correct 61 ms 50296 KB Output is correct
14 Correct 56 ms 50296 KB Output is correct
15 Correct 145 ms 56620 KB Output is correct
16 Correct 147 ms 56684 KB Output is correct
17 Correct 128 ms 56564 KB Output is correct
18 Correct 115 ms 56048 KB Output is correct
19 Correct 149 ms 56948 KB Output is correct
20 Correct 169 ms 56880 KB Output is correct
21 Correct 136 ms 56692 KB Output is correct
22 Correct 118 ms 56180 KB Output is correct
23 Correct 166 ms 56820 KB Output is correct
24 Correct 162 ms 56820 KB Output is correct
25 Correct 140 ms 56820 KB Output is correct
26 Correct 116 ms 56304 KB Output is correct
27 Incorrect 140 ms 56068 KB Wrong Answer [2]
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 47616 KB Output is correct
2 Correct 31 ms 47616 KB Output is correct
3 Correct 32 ms 47608 KB Output is correct
4 Correct 31 ms 47608 KB Output is correct
5 Correct 40 ms 47736 KB Output is correct
6 Correct 34 ms 47872 KB Output is correct
7 Correct 37 ms 48248 KB Output is correct
8 Correct 46 ms 48940 KB Output is correct
9 Correct 57 ms 50168 KB Output is correct
10 Correct 33 ms 47744 KB Output is correct
11 Correct 54 ms 49788 KB Output is correct
12 Correct 69 ms 50296 KB Output is correct
13 Correct 61 ms 50296 KB Output is correct
14 Correct 56 ms 50296 KB Output is correct
15 Correct 145 ms 56620 KB Output is correct
16 Correct 147 ms 56684 KB Output is correct
17 Correct 128 ms 56564 KB Output is correct
18 Correct 115 ms 56048 KB Output is correct
19 Correct 149 ms 56948 KB Output is correct
20 Correct 169 ms 56880 KB Output is correct
21 Correct 136 ms 56692 KB Output is correct
22 Correct 118 ms 56180 KB Output is correct
23 Correct 166 ms 56820 KB Output is correct
24 Correct 162 ms 56820 KB Output is correct
25 Correct 140 ms 56820 KB Output is correct
26 Correct 116 ms 56304 KB Output is correct
27 Incorrect 140 ms 56068 KB Wrong Answer [2]
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 47616 KB Output is correct
2 Correct 31 ms 47616 KB Output is correct
3 Correct 32 ms 47608 KB Output is correct
4 Correct 31 ms 47608 KB Output is correct
5 Correct 40 ms 47736 KB Output is correct
6 Correct 34 ms 47872 KB Output is correct
7 Correct 37 ms 48248 KB Output is correct
8 Correct 46 ms 48940 KB Output is correct
9 Correct 57 ms 50168 KB Output is correct
10 Correct 33 ms 47744 KB Output is correct
11 Correct 54 ms 49788 KB Output is correct
12 Correct 69 ms 50296 KB Output is correct
13 Correct 61 ms 50296 KB Output is correct
14 Correct 56 ms 50296 KB Output is correct
15 Correct 145 ms 56620 KB Output is correct
16 Correct 147 ms 56684 KB Output is correct
17 Correct 128 ms 56564 KB Output is correct
18 Correct 115 ms 56048 KB Output is correct
19 Correct 149 ms 56948 KB Output is correct
20 Correct 169 ms 56880 KB Output is correct
21 Correct 136 ms 56692 KB Output is correct
22 Correct 118 ms 56180 KB Output is correct
23 Correct 166 ms 56820 KB Output is correct
24 Correct 162 ms 56820 KB Output is correct
25 Correct 140 ms 56820 KB Output is correct
26 Correct 116 ms 56304 KB Output is correct
27 Incorrect 140 ms 56068 KB Wrong Answer [2]
28 Halted 0 ms 0 KB -