# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1108165 |
2024-11-03T06:36:30 Z |
abczz |
Minerals (JOI19_minerals) |
C++17 |
|
57 ms |
34804 KB |
#include "minerals.h"
#include <iostream>
#include <vector>
#include <random>
#include <algorithm>
#define ll long long
using namespace std;
vector <ll> X, Y;
bool B[100000];
vector <ll> st[1000000];
ll sz, z;
random_device rd;
ll query(ll u) {
B[u] ^= 1;
return Query(u);
}
ll M(ll l, ll r) {
if (l == r) return l;
return min(r-1, l+(r-l+1)*4/7-1);
}
mt19937 mt(rd());
void solve(ll id, ll l, ll r) {
if (l == r) {
Answer(X[l], st[id][0]);
return;
}
ll mid = M(l, r), a = 0, b = 0;
shuffle(st[id].begin(), st[id].end(), mt);
for (auto u : st[id]) {
if (a == mid-l+1) {
st[id*2+1].push_back(u);
continue;
}
else if (b == r-mid) {
st[id*2].push_back(u);
continue;
}
z = query(u);
if (sz == z) st[id*2].push_back(u), ++a;
else st[id*2+1].push_back(u), ++b;
sz = z;
}
ll xm;
if (l == mid) {
Answer(X[l], st[id*2][0]);
}
else {
xm = M(l, mid);
for (int i=l; i<=xm; ++i) if (!B[X[i]]) sz = query(X[i]);
for (int i=xm+1; i<=mid; ++i) if (B[X[i]]) sz = query(X[i]);
solve(id*2, l, mid);
}
if (mid+1 == r) {
Answer(X[r], st[id*2+1][0]);
}
else {
xm = M(mid+1, r);
sort(st[id*2+1].begin(), st[id*2+1].end(), [](auto a, auto b) {
return B[a] > B[b];
});
for (int i=mid+1; i<=r; ++i) {
swap(X[i], st[id*2+1][i-mid-1]);
}
for (int i=mid+1; i<=xm; ++i) if (!B[X[i]]) sz = query(X[i]);
for (int i=xm+1; i<=r; ++i) if (B[X[i]]) sz = query(X[i]);
solve(id*2+1, mid+1, r);
}
}
void Solve(int N) {
sz = 0;
for (int i=1; i<=2*N; ++i) {
z = query(i);
if (sz != z) X.push_back(i);
else Y.push_back(i);
sz = z;
}
shuffle(X.begin(), X.end(), mt);
shuffle(Y.begin(), Y.end(), mt);
for (auto u : Y) st[1].push_back(u);
for (int i=M(0, N-1)+1; i<N; ++i) sz = query(X[i]);
solve(1, 0, N-1);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
25168 KB |
Output is correct |
2 |
Correct |
5 ms |
25168 KB |
Output is correct |
3 |
Correct |
6 ms |
25168 KB |
Output is correct |
4 |
Correct |
5 ms |
25168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
25168 KB |
Output is correct |
2 |
Correct |
7 ms |
25424 KB |
Output is correct |
3 |
Correct |
9 ms |
25936 KB |
Output is correct |
4 |
Correct |
12 ms |
26704 KB |
Output is correct |
5 |
Correct |
27 ms |
28240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
25168 KB |
Output is correct |
2 |
Correct |
5 ms |
25168 KB |
Output is correct |
3 |
Correct |
6 ms |
25168 KB |
Output is correct |
4 |
Correct |
5 ms |
25168 KB |
Output is correct |
5 |
Correct |
6 ms |
25168 KB |
Output is correct |
6 |
Correct |
7 ms |
25424 KB |
Output is correct |
7 |
Correct |
9 ms |
25936 KB |
Output is correct |
8 |
Correct |
12 ms |
26704 KB |
Output is correct |
9 |
Correct |
27 ms |
28240 KB |
Output is correct |
10 |
Correct |
5 ms |
25168 KB |
Output is correct |
11 |
Correct |
14 ms |
27216 KB |
Output is correct |
12 |
Correct |
23 ms |
28240 KB |
Output is correct |
13 |
Correct |
18 ms |
28308 KB |
Output is correct |
14 |
Correct |
24 ms |
28240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
25168 KB |
Output is correct |
2 |
Correct |
5 ms |
25168 KB |
Output is correct |
3 |
Correct |
6 ms |
25168 KB |
Output is correct |
4 |
Correct |
5 ms |
25168 KB |
Output is correct |
5 |
Correct |
6 ms |
25168 KB |
Output is correct |
6 |
Correct |
7 ms |
25424 KB |
Output is correct |
7 |
Correct |
9 ms |
25936 KB |
Output is correct |
8 |
Correct |
12 ms |
26704 KB |
Output is correct |
9 |
Correct |
27 ms |
28240 KB |
Output is correct |
10 |
Correct |
5 ms |
25168 KB |
Output is correct |
11 |
Correct |
14 ms |
27216 KB |
Output is correct |
12 |
Correct |
23 ms |
28240 KB |
Output is correct |
13 |
Correct |
18 ms |
28308 KB |
Output is correct |
14 |
Correct |
24 ms |
28240 KB |
Output is correct |
15 |
Correct |
43 ms |
33480 KB |
Output is correct |
16 |
Correct |
46 ms |
33480 KB |
Output is correct |
17 |
Correct |
41 ms |
33600 KB |
Output is correct |
18 |
Correct |
48 ms |
33480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
25168 KB |
Output is correct |
2 |
Correct |
5 ms |
25168 KB |
Output is correct |
3 |
Correct |
6 ms |
25168 KB |
Output is correct |
4 |
Correct |
5 ms |
25168 KB |
Output is correct |
5 |
Correct |
6 ms |
25168 KB |
Output is correct |
6 |
Correct |
7 ms |
25424 KB |
Output is correct |
7 |
Correct |
9 ms |
25936 KB |
Output is correct |
8 |
Correct |
12 ms |
26704 KB |
Output is correct |
9 |
Correct |
27 ms |
28240 KB |
Output is correct |
10 |
Correct |
5 ms |
25168 KB |
Output is correct |
11 |
Correct |
14 ms |
27216 KB |
Output is correct |
12 |
Correct |
23 ms |
28240 KB |
Output is correct |
13 |
Correct |
18 ms |
28308 KB |
Output is correct |
14 |
Correct |
24 ms |
28240 KB |
Output is correct |
15 |
Correct |
43 ms |
33480 KB |
Output is correct |
16 |
Correct |
46 ms |
33480 KB |
Output is correct |
17 |
Correct |
41 ms |
33600 KB |
Output is correct |
18 |
Correct |
48 ms |
33480 KB |
Output is correct |
19 |
Correct |
46 ms |
33736 KB |
Output is correct |
20 |
Correct |
49 ms |
33656 KB |
Output is correct |
21 |
Correct |
57 ms |
33596 KB |
Output is correct |
22 |
Correct |
46 ms |
33652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
25168 KB |
Output is correct |
2 |
Correct |
5 ms |
25168 KB |
Output is correct |
3 |
Correct |
6 ms |
25168 KB |
Output is correct |
4 |
Correct |
5 ms |
25168 KB |
Output is correct |
5 |
Correct |
6 ms |
25168 KB |
Output is correct |
6 |
Correct |
7 ms |
25424 KB |
Output is correct |
7 |
Correct |
9 ms |
25936 KB |
Output is correct |
8 |
Correct |
12 ms |
26704 KB |
Output is correct |
9 |
Correct |
27 ms |
28240 KB |
Output is correct |
10 |
Correct |
5 ms |
25168 KB |
Output is correct |
11 |
Correct |
14 ms |
27216 KB |
Output is correct |
12 |
Correct |
23 ms |
28240 KB |
Output is correct |
13 |
Correct |
18 ms |
28308 KB |
Output is correct |
14 |
Correct |
24 ms |
28240 KB |
Output is correct |
15 |
Correct |
43 ms |
33480 KB |
Output is correct |
16 |
Correct |
46 ms |
33480 KB |
Output is correct |
17 |
Correct |
41 ms |
33600 KB |
Output is correct |
18 |
Correct |
48 ms |
33480 KB |
Output is correct |
19 |
Correct |
46 ms |
33736 KB |
Output is correct |
20 |
Correct |
49 ms |
33656 KB |
Output is correct |
21 |
Correct |
57 ms |
33596 KB |
Output is correct |
22 |
Correct |
46 ms |
33652 KB |
Output is correct |
23 |
Correct |
48 ms |
33992 KB |
Output is correct |
24 |
Correct |
47 ms |
33992 KB |
Output is correct |
25 |
Correct |
42 ms |
33860 KB |
Output is correct |
26 |
Correct |
48 ms |
33956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
25168 KB |
Output is correct |
2 |
Correct |
5 ms |
25168 KB |
Output is correct |
3 |
Correct |
6 ms |
25168 KB |
Output is correct |
4 |
Correct |
5 ms |
25168 KB |
Output is correct |
5 |
Correct |
6 ms |
25168 KB |
Output is correct |
6 |
Correct |
7 ms |
25424 KB |
Output is correct |
7 |
Correct |
9 ms |
25936 KB |
Output is correct |
8 |
Correct |
12 ms |
26704 KB |
Output is correct |
9 |
Correct |
27 ms |
28240 KB |
Output is correct |
10 |
Correct |
5 ms |
25168 KB |
Output is correct |
11 |
Correct |
14 ms |
27216 KB |
Output is correct |
12 |
Correct |
23 ms |
28240 KB |
Output is correct |
13 |
Correct |
18 ms |
28308 KB |
Output is correct |
14 |
Correct |
24 ms |
28240 KB |
Output is correct |
15 |
Correct |
43 ms |
33480 KB |
Output is correct |
16 |
Correct |
46 ms |
33480 KB |
Output is correct |
17 |
Correct |
41 ms |
33600 KB |
Output is correct |
18 |
Correct |
48 ms |
33480 KB |
Output is correct |
19 |
Correct |
46 ms |
33736 KB |
Output is correct |
20 |
Correct |
49 ms |
33656 KB |
Output is correct |
21 |
Correct |
57 ms |
33596 KB |
Output is correct |
22 |
Correct |
46 ms |
33652 KB |
Output is correct |
23 |
Correct |
48 ms |
33992 KB |
Output is correct |
24 |
Correct |
47 ms |
33992 KB |
Output is correct |
25 |
Correct |
42 ms |
33860 KB |
Output is correct |
26 |
Correct |
48 ms |
33956 KB |
Output is correct |
27 |
Correct |
45 ms |
34264 KB |
Output is correct |
28 |
Correct |
50 ms |
34248 KB |
Output is correct |
29 |
Correct |
53 ms |
34316 KB |
Output is correct |
30 |
Correct |
45 ms |
34248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
25168 KB |
Output is correct |
2 |
Correct |
5 ms |
25168 KB |
Output is correct |
3 |
Correct |
6 ms |
25168 KB |
Output is correct |
4 |
Correct |
5 ms |
25168 KB |
Output is correct |
5 |
Correct |
6 ms |
25168 KB |
Output is correct |
6 |
Correct |
7 ms |
25424 KB |
Output is correct |
7 |
Correct |
9 ms |
25936 KB |
Output is correct |
8 |
Correct |
12 ms |
26704 KB |
Output is correct |
9 |
Correct |
27 ms |
28240 KB |
Output is correct |
10 |
Correct |
5 ms |
25168 KB |
Output is correct |
11 |
Correct |
14 ms |
27216 KB |
Output is correct |
12 |
Correct |
23 ms |
28240 KB |
Output is correct |
13 |
Correct |
18 ms |
28308 KB |
Output is correct |
14 |
Correct |
24 ms |
28240 KB |
Output is correct |
15 |
Correct |
43 ms |
33480 KB |
Output is correct |
16 |
Correct |
46 ms |
33480 KB |
Output is correct |
17 |
Correct |
41 ms |
33600 KB |
Output is correct |
18 |
Correct |
48 ms |
33480 KB |
Output is correct |
19 |
Correct |
46 ms |
33736 KB |
Output is correct |
20 |
Correct |
49 ms |
33656 KB |
Output is correct |
21 |
Correct |
57 ms |
33596 KB |
Output is correct |
22 |
Correct |
46 ms |
33652 KB |
Output is correct |
23 |
Correct |
48 ms |
33992 KB |
Output is correct |
24 |
Correct |
47 ms |
33992 KB |
Output is correct |
25 |
Correct |
42 ms |
33860 KB |
Output is correct |
26 |
Correct |
48 ms |
33956 KB |
Output is correct |
27 |
Correct |
45 ms |
34264 KB |
Output is correct |
28 |
Correct |
50 ms |
34248 KB |
Output is correct |
29 |
Correct |
53 ms |
34316 KB |
Output is correct |
30 |
Correct |
45 ms |
34248 KB |
Output is correct |
31 |
Correct |
50 ms |
34504 KB |
Output is correct |
32 |
Correct |
47 ms |
34696 KB |
Output is correct |
33 |
Correct |
50 ms |
34620 KB |
Output is correct |
34 |
Correct |
46 ms |
34640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
25168 KB |
Output is correct |
2 |
Correct |
5 ms |
25168 KB |
Output is correct |
3 |
Correct |
6 ms |
25168 KB |
Output is correct |
4 |
Correct |
5 ms |
25168 KB |
Output is correct |
5 |
Correct |
6 ms |
25168 KB |
Output is correct |
6 |
Correct |
7 ms |
25424 KB |
Output is correct |
7 |
Correct |
9 ms |
25936 KB |
Output is correct |
8 |
Correct |
12 ms |
26704 KB |
Output is correct |
9 |
Correct |
27 ms |
28240 KB |
Output is correct |
10 |
Correct |
5 ms |
25168 KB |
Output is correct |
11 |
Correct |
14 ms |
27216 KB |
Output is correct |
12 |
Correct |
23 ms |
28240 KB |
Output is correct |
13 |
Correct |
18 ms |
28308 KB |
Output is correct |
14 |
Correct |
24 ms |
28240 KB |
Output is correct |
15 |
Correct |
43 ms |
33480 KB |
Output is correct |
16 |
Correct |
46 ms |
33480 KB |
Output is correct |
17 |
Correct |
41 ms |
33600 KB |
Output is correct |
18 |
Correct |
48 ms |
33480 KB |
Output is correct |
19 |
Correct |
46 ms |
33736 KB |
Output is correct |
20 |
Correct |
49 ms |
33656 KB |
Output is correct |
21 |
Correct |
57 ms |
33596 KB |
Output is correct |
22 |
Correct |
46 ms |
33652 KB |
Output is correct |
23 |
Correct |
48 ms |
33992 KB |
Output is correct |
24 |
Correct |
47 ms |
33992 KB |
Output is correct |
25 |
Correct |
42 ms |
33860 KB |
Output is correct |
26 |
Correct |
48 ms |
33956 KB |
Output is correct |
27 |
Correct |
45 ms |
34264 KB |
Output is correct |
28 |
Correct |
50 ms |
34248 KB |
Output is correct |
29 |
Correct |
53 ms |
34316 KB |
Output is correct |
30 |
Correct |
45 ms |
34248 KB |
Output is correct |
31 |
Correct |
50 ms |
34504 KB |
Output is correct |
32 |
Correct |
47 ms |
34696 KB |
Output is correct |
33 |
Correct |
50 ms |
34620 KB |
Output is correct |
34 |
Correct |
46 ms |
34640 KB |
Output is correct |
35 |
Correct |
52 ms |
34804 KB |
Output is correct |
36 |
Correct |
52 ms |
34760 KB |
Output is correct |
37 |
Correct |
53 ms |
34788 KB |
Output is correct |
38 |
Correct |
48 ms |
34760 KB |
Output is correct |