Submission #1108065

# Submission time Handle Problem Language Result Execution time Memory
1108065 2024-11-02T16:14:49 Z abczz Minerals (JOI19_minerals) C++17
90 / 100
58 ms 21760 KB
#include "minerals.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#define ll long long 

using namespace std;

vector <ll> X, Y;
bool B[100000];
vector <ll> st[400000];
ll sz, z;
random_device rd;
ll query(ll u) {
  B[u] ^= 1;
  return Query(u);
}
mt19937 mt(rd());
void solve(ll id, ll l, ll r) {
  if (l == r) {
    Answer(X[l], st[id][0]);
    return;
  }
  ll mid = (l+r)/2, 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;
  }
  if (l == mid) {
    Answer(X[l], st[id*2][0]);
  }
  else {
    ll xm = (l+mid)/2;
    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]);
    return;
  }
  ll xm = (mid+1+r)/2;
  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;
  ll tot = N;
  vector <ll> V;
  for (int i=1; i<=2*N; ++i) {
    V.push_back(i);
  }
  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=(N-1)/2+1; i<N; ++i) sz = query(X[i]);
  solve(1, 0, tot-1);
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10832 KB Output is correct
2 Correct 3 ms 10832 KB Output is correct
3 Correct 3 ms 10832 KB Output is correct
4 Correct 4 ms 10832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10832 KB Output is correct
2 Correct 4 ms 11088 KB Output is correct
3 Correct 6 ms 11600 KB Output is correct
4 Correct 9 ms 12368 KB Output is correct
5 Correct 16 ms 14024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10832 KB Output is correct
2 Correct 3 ms 10832 KB Output is correct
3 Correct 3 ms 10832 KB Output is correct
4 Correct 4 ms 10832 KB Output is correct
5 Correct 3 ms 10832 KB Output is correct
6 Correct 4 ms 11088 KB Output is correct
7 Correct 6 ms 11600 KB Output is correct
8 Correct 9 ms 12368 KB Output is correct
9 Correct 16 ms 14024 KB Output is correct
10 Correct 3 ms 10832 KB Output is correct
11 Correct 11 ms 13208 KB Output is correct
12 Correct 18 ms 13772 KB Output is correct
13 Correct 17 ms 13772 KB Output is correct
14 Correct 17 ms 13724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10832 KB Output is correct
2 Correct 3 ms 10832 KB Output is correct
3 Correct 3 ms 10832 KB Output is correct
4 Correct 4 ms 10832 KB Output is correct
5 Correct 3 ms 10832 KB Output is correct
6 Correct 4 ms 11088 KB Output is correct
7 Correct 6 ms 11600 KB Output is correct
8 Correct 9 ms 12368 KB Output is correct
9 Correct 16 ms 14024 KB Output is correct
10 Correct 3 ms 10832 KB Output is correct
11 Correct 11 ms 13208 KB Output is correct
12 Correct 18 ms 13772 KB Output is correct
13 Correct 17 ms 13772 KB Output is correct
14 Correct 17 ms 13724 KB Output is correct
15 Correct 47 ms 20924 KB Output is correct
16 Correct 52 ms 20924 KB Output is correct
17 Correct 48 ms 21180 KB Output is correct
18 Correct 47 ms 20668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10832 KB Output is correct
2 Correct 3 ms 10832 KB Output is correct
3 Correct 3 ms 10832 KB Output is correct
4 Correct 4 ms 10832 KB Output is correct
5 Correct 3 ms 10832 KB Output is correct
6 Correct 4 ms 11088 KB Output is correct
7 Correct 6 ms 11600 KB Output is correct
8 Correct 9 ms 12368 KB Output is correct
9 Correct 16 ms 14024 KB Output is correct
10 Correct 3 ms 10832 KB Output is correct
11 Correct 11 ms 13208 KB Output is correct
12 Correct 18 ms 13772 KB Output is correct
13 Correct 17 ms 13772 KB Output is correct
14 Correct 17 ms 13724 KB Output is correct
15 Correct 47 ms 20924 KB Output is correct
16 Correct 52 ms 20924 KB Output is correct
17 Correct 48 ms 21180 KB Output is correct
18 Correct 47 ms 20668 KB Output is correct
19 Correct 44 ms 21032 KB Output is correct
20 Correct 43 ms 20896 KB Output is correct
21 Correct 44 ms 21320 KB Output is correct
22 Correct 47 ms 21180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10832 KB Output is correct
2 Correct 3 ms 10832 KB Output is correct
3 Correct 3 ms 10832 KB Output is correct
4 Correct 4 ms 10832 KB Output is correct
5 Correct 3 ms 10832 KB Output is correct
6 Correct 4 ms 11088 KB Output is correct
7 Correct 6 ms 11600 KB Output is correct
8 Correct 9 ms 12368 KB Output is correct
9 Correct 16 ms 14024 KB Output is correct
10 Correct 3 ms 10832 KB Output is correct
11 Correct 11 ms 13208 KB Output is correct
12 Correct 18 ms 13772 KB Output is correct
13 Correct 17 ms 13772 KB Output is correct
14 Correct 17 ms 13724 KB Output is correct
15 Correct 47 ms 20924 KB Output is correct
16 Correct 52 ms 20924 KB Output is correct
17 Correct 48 ms 21180 KB Output is correct
18 Correct 47 ms 20668 KB Output is correct
19 Correct 44 ms 21032 KB Output is correct
20 Correct 43 ms 20896 KB Output is correct
21 Correct 44 ms 21320 KB Output is correct
22 Correct 47 ms 21180 KB Output is correct
23 Correct 46 ms 21180 KB Output is correct
24 Correct 44 ms 21296 KB Output is correct
25 Correct 58 ms 21392 KB Output is correct
26 Correct 45 ms 21360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10832 KB Output is correct
2 Correct 3 ms 10832 KB Output is correct
3 Correct 3 ms 10832 KB Output is correct
4 Correct 4 ms 10832 KB Output is correct
5 Correct 3 ms 10832 KB Output is correct
6 Correct 4 ms 11088 KB Output is correct
7 Correct 6 ms 11600 KB Output is correct
8 Correct 9 ms 12368 KB Output is correct
9 Correct 16 ms 14024 KB Output is correct
10 Correct 3 ms 10832 KB Output is correct
11 Correct 11 ms 13208 KB Output is correct
12 Correct 18 ms 13772 KB Output is correct
13 Correct 17 ms 13772 KB Output is correct
14 Correct 17 ms 13724 KB Output is correct
15 Correct 47 ms 20924 KB Output is correct
16 Correct 52 ms 20924 KB Output is correct
17 Correct 48 ms 21180 KB Output is correct
18 Correct 47 ms 20668 KB Output is correct
19 Correct 44 ms 21032 KB Output is correct
20 Correct 43 ms 20896 KB Output is correct
21 Correct 44 ms 21320 KB Output is correct
22 Correct 47 ms 21180 KB Output is correct
23 Correct 46 ms 21180 KB Output is correct
24 Correct 44 ms 21296 KB Output is correct
25 Correct 58 ms 21392 KB Output is correct
26 Correct 45 ms 21360 KB Output is correct
27 Correct 46 ms 21448 KB Output is correct
28 Correct 50 ms 21560 KB Output is correct
29 Correct 58 ms 21564 KB Output is correct
30 Correct 43 ms 21436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10832 KB Output is correct
2 Correct 3 ms 10832 KB Output is correct
3 Correct 3 ms 10832 KB Output is correct
4 Correct 4 ms 10832 KB Output is correct
5 Correct 3 ms 10832 KB Output is correct
6 Correct 4 ms 11088 KB Output is correct
7 Correct 6 ms 11600 KB Output is correct
8 Correct 9 ms 12368 KB Output is correct
9 Correct 16 ms 14024 KB Output is correct
10 Correct 3 ms 10832 KB Output is correct
11 Correct 11 ms 13208 KB Output is correct
12 Correct 18 ms 13772 KB Output is correct
13 Correct 17 ms 13772 KB Output is correct
14 Correct 17 ms 13724 KB Output is correct
15 Correct 47 ms 20924 KB Output is correct
16 Correct 52 ms 20924 KB Output is correct
17 Correct 48 ms 21180 KB Output is correct
18 Correct 47 ms 20668 KB Output is correct
19 Correct 44 ms 21032 KB Output is correct
20 Correct 43 ms 20896 KB Output is correct
21 Correct 44 ms 21320 KB Output is correct
22 Correct 47 ms 21180 KB Output is correct
23 Correct 46 ms 21180 KB Output is correct
24 Correct 44 ms 21296 KB Output is correct
25 Correct 58 ms 21392 KB Output is correct
26 Correct 45 ms 21360 KB Output is correct
27 Correct 46 ms 21448 KB Output is correct
28 Correct 50 ms 21560 KB Output is correct
29 Correct 58 ms 21564 KB Output is correct
30 Correct 43 ms 21436 KB Output is correct
31 Correct 44 ms 21436 KB Output is correct
32 Correct 45 ms 21760 KB Output is correct
33 Correct 44 ms 21724 KB Output is correct
34 Correct 49 ms 21484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10832 KB Output is correct
2 Correct 3 ms 10832 KB Output is correct
3 Correct 3 ms 10832 KB Output is correct
4 Correct 4 ms 10832 KB Output is correct
5 Correct 3 ms 10832 KB Output is correct
6 Correct 4 ms 11088 KB Output is correct
7 Correct 6 ms 11600 KB Output is correct
8 Correct 9 ms 12368 KB Output is correct
9 Correct 16 ms 14024 KB Output is correct
10 Correct 3 ms 10832 KB Output is correct
11 Correct 11 ms 13208 KB Output is correct
12 Correct 18 ms 13772 KB Output is correct
13 Correct 17 ms 13772 KB Output is correct
14 Correct 17 ms 13724 KB Output is correct
15 Correct 47 ms 20924 KB Output is correct
16 Correct 52 ms 20924 KB Output is correct
17 Correct 48 ms 21180 KB Output is correct
18 Correct 47 ms 20668 KB Output is correct
19 Correct 44 ms 21032 KB Output is correct
20 Correct 43 ms 20896 KB Output is correct
21 Correct 44 ms 21320 KB Output is correct
22 Correct 47 ms 21180 KB Output is correct
23 Correct 46 ms 21180 KB Output is correct
24 Correct 44 ms 21296 KB Output is correct
25 Correct 58 ms 21392 KB Output is correct
26 Correct 45 ms 21360 KB Output is correct
27 Correct 46 ms 21448 KB Output is correct
28 Correct 50 ms 21560 KB Output is correct
29 Correct 58 ms 21564 KB Output is correct
30 Correct 43 ms 21436 KB Output is correct
31 Correct 44 ms 21436 KB Output is correct
32 Correct 45 ms 21760 KB Output is correct
33 Correct 44 ms 21724 KB Output is correct
34 Correct 49 ms 21484 KB Output is correct
35 Incorrect 47 ms 21704 KB Wrong Answer [2]
36 Halted 0 ms 0 KB -