Submission #262062

# Submission time Handle Problem Language Result Execution time Memory
262062 2020-08-12T10:21:17 Z patrikpavic2 Minerals (JOI19_minerals) C++17
80 / 100
166 ms 56956 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 = 2 * n;i >= 1;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(kol[red][P[i]].size() == 1 || (kol[red][P[i]][(int)kol[red][P[i]].size() - 2] < i)){
			ans[i] = *lower_bound(kol[red][P[i]].begin(), kol[red][P[i]].end(), i);
			izb[ans[i]] = 1;
		//	printf("nasao\n");
		}
	}
	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(kol[red][P[i]].size() == 1 || (kol[red][P[i]][(int)kol[red][P[i]].size() - 2] < i)){
			ans[i] = kol[red][P[i]].back();
			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); mozda(0);
	for(int i = 0;i <= mks;i++){
		odradi(i);
		mozda(i + 1); 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 31 ms 47608 KB Output is correct
2 Correct 31 ms 47616 KB Output is correct
3 Correct 33 ms 47608 KB Output is correct
4 Correct 31 ms 47616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 47736 KB Output is correct
2 Correct 34 ms 47872 KB Output is correct
3 Correct 39 ms 48252 KB Output is correct
4 Correct 45 ms 48888 KB Output is correct
5 Correct 62 ms 50168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 47608 KB Output is correct
2 Correct 31 ms 47616 KB Output is correct
3 Correct 33 ms 47608 KB Output is correct
4 Correct 31 ms 47616 KB Output is correct
5 Correct 36 ms 47736 KB Output is correct
6 Correct 34 ms 47872 KB Output is correct
7 Correct 39 ms 48252 KB Output is correct
8 Correct 45 ms 48888 KB Output is correct
9 Correct 62 ms 50168 KB Output is correct
10 Correct 33 ms 47736 KB Output is correct
11 Correct 57 ms 49820 KB Output is correct
12 Correct 68 ms 50296 KB Output is correct
13 Correct 51 ms 50296 KB Output is correct
14 Correct 59 ms 50168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 47608 KB Output is correct
2 Correct 31 ms 47616 KB Output is correct
3 Correct 33 ms 47608 KB Output is correct
4 Correct 31 ms 47616 KB Output is correct
5 Correct 36 ms 47736 KB Output is correct
6 Correct 34 ms 47872 KB Output is correct
7 Correct 39 ms 48252 KB Output is correct
8 Correct 45 ms 48888 KB Output is correct
9 Correct 62 ms 50168 KB Output is correct
10 Correct 33 ms 47736 KB Output is correct
11 Correct 57 ms 49820 KB Output is correct
12 Correct 68 ms 50296 KB Output is correct
13 Correct 51 ms 50296 KB Output is correct
14 Correct 59 ms 50168 KB Output is correct
15 Correct 151 ms 56564 KB Output is correct
16 Correct 146 ms 56564 KB Output is correct
17 Correct 100 ms 56564 KB Output is correct
18 Correct 123 ms 56180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 47608 KB Output is correct
2 Correct 31 ms 47616 KB Output is correct
3 Correct 33 ms 47608 KB Output is correct
4 Correct 31 ms 47616 KB Output is correct
5 Correct 36 ms 47736 KB Output is correct
6 Correct 34 ms 47872 KB Output is correct
7 Correct 39 ms 48252 KB Output is correct
8 Correct 45 ms 48888 KB Output is correct
9 Correct 62 ms 50168 KB Output is correct
10 Correct 33 ms 47736 KB Output is correct
11 Correct 57 ms 49820 KB Output is correct
12 Correct 68 ms 50296 KB Output is correct
13 Correct 51 ms 50296 KB Output is correct
14 Correct 59 ms 50168 KB Output is correct
15 Correct 151 ms 56564 KB Output is correct
16 Correct 146 ms 56564 KB Output is correct
17 Correct 100 ms 56564 KB Output is correct
18 Correct 123 ms 56180 KB Output is correct
19 Correct 152 ms 56692 KB Output is correct
20 Correct 154 ms 56716 KB Output is correct
21 Correct 95 ms 56692 KB Output is correct
22 Correct 115 ms 56180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 47608 KB Output is correct
2 Correct 31 ms 47616 KB Output is correct
3 Correct 33 ms 47608 KB Output is correct
4 Correct 31 ms 47616 KB Output is correct
5 Correct 36 ms 47736 KB Output is correct
6 Correct 34 ms 47872 KB Output is correct
7 Correct 39 ms 48252 KB Output is correct
8 Correct 45 ms 48888 KB Output is correct
9 Correct 62 ms 50168 KB Output is correct
10 Correct 33 ms 47736 KB Output is correct
11 Correct 57 ms 49820 KB Output is correct
12 Correct 68 ms 50296 KB Output is correct
13 Correct 51 ms 50296 KB Output is correct
14 Correct 59 ms 50168 KB Output is correct
15 Correct 151 ms 56564 KB Output is correct
16 Correct 146 ms 56564 KB Output is correct
17 Correct 100 ms 56564 KB Output is correct
18 Correct 123 ms 56180 KB Output is correct
19 Correct 152 ms 56692 KB Output is correct
20 Correct 154 ms 56716 KB Output is correct
21 Correct 95 ms 56692 KB Output is correct
22 Correct 115 ms 56180 KB Output is correct
23 Correct 162 ms 56816 KB Output is correct
24 Correct 166 ms 56956 KB Output is correct
25 Correct 93 ms 56820 KB Output is correct
26 Correct 112 ms 56308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 47608 KB Output is correct
2 Correct 31 ms 47616 KB Output is correct
3 Correct 33 ms 47608 KB Output is correct
4 Correct 31 ms 47616 KB Output is correct
5 Correct 36 ms 47736 KB Output is correct
6 Correct 34 ms 47872 KB Output is correct
7 Correct 39 ms 48252 KB Output is correct
8 Correct 45 ms 48888 KB Output is correct
9 Correct 62 ms 50168 KB Output is correct
10 Correct 33 ms 47736 KB Output is correct
11 Correct 57 ms 49820 KB Output is correct
12 Correct 68 ms 50296 KB Output is correct
13 Correct 51 ms 50296 KB Output is correct
14 Correct 59 ms 50168 KB Output is correct
15 Correct 151 ms 56564 KB Output is correct
16 Correct 146 ms 56564 KB Output is correct
17 Correct 100 ms 56564 KB Output is correct
18 Correct 123 ms 56180 KB Output is correct
19 Correct 152 ms 56692 KB Output is correct
20 Correct 154 ms 56716 KB Output is correct
21 Correct 95 ms 56692 KB Output is correct
22 Correct 115 ms 56180 KB Output is correct
23 Correct 162 ms 56816 KB Output is correct
24 Correct 166 ms 56956 KB Output is correct
25 Correct 93 ms 56820 KB Output is correct
26 Correct 112 ms 56308 KB Output is correct
27 Incorrect 152 ms 56308 KB Wrong Answer [2]
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 47608 KB Output is correct
2 Correct 31 ms 47616 KB Output is correct
3 Correct 33 ms 47608 KB Output is correct
4 Correct 31 ms 47616 KB Output is correct
5 Correct 36 ms 47736 KB Output is correct
6 Correct 34 ms 47872 KB Output is correct
7 Correct 39 ms 48252 KB Output is correct
8 Correct 45 ms 48888 KB Output is correct
9 Correct 62 ms 50168 KB Output is correct
10 Correct 33 ms 47736 KB Output is correct
11 Correct 57 ms 49820 KB Output is correct
12 Correct 68 ms 50296 KB Output is correct
13 Correct 51 ms 50296 KB Output is correct
14 Correct 59 ms 50168 KB Output is correct
15 Correct 151 ms 56564 KB Output is correct
16 Correct 146 ms 56564 KB Output is correct
17 Correct 100 ms 56564 KB Output is correct
18 Correct 123 ms 56180 KB Output is correct
19 Correct 152 ms 56692 KB Output is correct
20 Correct 154 ms 56716 KB Output is correct
21 Correct 95 ms 56692 KB Output is correct
22 Correct 115 ms 56180 KB Output is correct
23 Correct 162 ms 56816 KB Output is correct
24 Correct 166 ms 56956 KB Output is correct
25 Correct 93 ms 56820 KB Output is correct
26 Correct 112 ms 56308 KB Output is correct
27 Incorrect 152 ms 56308 KB Wrong Answer [2]
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 47608 KB Output is correct
2 Correct 31 ms 47616 KB Output is correct
3 Correct 33 ms 47608 KB Output is correct
4 Correct 31 ms 47616 KB Output is correct
5 Correct 36 ms 47736 KB Output is correct
6 Correct 34 ms 47872 KB Output is correct
7 Correct 39 ms 48252 KB Output is correct
8 Correct 45 ms 48888 KB Output is correct
9 Correct 62 ms 50168 KB Output is correct
10 Correct 33 ms 47736 KB Output is correct
11 Correct 57 ms 49820 KB Output is correct
12 Correct 68 ms 50296 KB Output is correct
13 Correct 51 ms 50296 KB Output is correct
14 Correct 59 ms 50168 KB Output is correct
15 Correct 151 ms 56564 KB Output is correct
16 Correct 146 ms 56564 KB Output is correct
17 Correct 100 ms 56564 KB Output is correct
18 Correct 123 ms 56180 KB Output is correct
19 Correct 152 ms 56692 KB Output is correct
20 Correct 154 ms 56716 KB Output is correct
21 Correct 95 ms 56692 KB Output is correct
22 Correct 115 ms 56180 KB Output is correct
23 Correct 162 ms 56816 KB Output is correct
24 Correct 166 ms 56956 KB Output is correct
25 Correct 93 ms 56820 KB Output is correct
26 Correct 112 ms 56308 KB Output is correct
27 Incorrect 152 ms 56308 KB Wrong Answer [2]
28 Halted 0 ms 0 KB -