Submission #379265

# Submission time Handle Problem Language Result Execution time Memory
379265 2021-03-17T18:22:58 Z qwerty234 Xylophone (JOI18_xylophone) C++14
100 / 100
83 ms 524 KB
#include <bits/stdc++.h>
#include "xylophone.h"
#define ll long long
#define fi first
#define se second
#define pb push_back

using namespace std;

const int MAXN = 5e5 + 10, inf = 2e9;

void solve(int n) {
  vector <int> b; b.assign(n, 0);
  vector <bool> vis(n + 1, false);
  int l = 0, r = n - 1, posn = n - 1;
  while (l <= r) {
    int m = (l + r) / 2;
    int tmp = query(1, m + 1);
    if (tmp < n - 1) {
      l = m + 1;
    } else {
      posn = min(posn, m);
      r = m - 1;
    }
  }
  b[posn] = n; vis[n] = true;
	if (posn != n - 1) {
		int tmp = query(posn + 1, posn + 2);
		b[posn + 1] = n - tmp;
	}
	if (posn != 0) {
		int tmp = query(posn, posn + 1);
		b[posn - 1] = n - tmp;
	}
  for (int i = posn + 2; i < n; i++) {
    int x, y, tmp = query(i, i + 1);
    x = b[i - 1] + tmp; y = b[i - 1] - tmp;
    if (x > n || vis[x]) {
      b[i] = y;
    } else if (y < 1 || vis[y]) {
      b[i] = x;
    } else {
      int tmp = query(i - 1, i + 1);
			if (b[i - 2] < b[i - 1]) {
				if (tmp == x - b[i - 2]) {
					b[i] = x;
				} else {
					b[i] = y;
				}
			} else {
				if (tmp == b[i - 2] - y) {
					b[i] = y;
				} else {
					b[i] = x;
				}
			}
    }
    vis[b[i]] = true;
  }

  for (int i = posn - 2; i >= 0; i--) {
    int x, y, tmp = query(i + 1, i + 2);
    x = b[i + 1] + tmp; y = b[i + 1] - tmp;
    if (x > n || vis[x]) {
      b[i] = y;
    } else if (y < 1 || vis[y]) {
      b[i] = x;
    } else {
			int tmp = query(i + 1, i + 3);
			if (b[i + 2] < b[i + 1]) {
				if (tmp == x - b[i + 2]) {
					b[i] = x;
				} else {
					b[i] = y;
				}
			} else {
				if (tmp == b[i + 2] - y) {
					b[i] = y;
				} else {
					b[i] = x;
				}
			}
    }
    vis[b[i]] = true;
  }

  for (int i = 0; i < n; i++) {
    answer(i + 1, b[i]);
    // cout << b[i] << " ";
  }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 380 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 380 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 3 ms 364 KB Output is correct
17 Correct 7 ms 364 KB Output is correct
18 Correct 10 ms 364 KB Output is correct
19 Correct 16 ms 364 KB Output is correct
20 Correct 17 ms 364 KB Output is correct
21 Correct 17 ms 364 KB Output is correct
22 Correct 12 ms 364 KB Output is correct
23 Correct 13 ms 364 KB Output is correct
24 Correct 14 ms 364 KB Output is correct
25 Correct 12 ms 364 KB Output is correct
26 Correct 18 ms 492 KB Output is correct
27 Correct 17 ms 364 KB Output is correct
28 Correct 15 ms 364 KB Output is correct
29 Correct 15 ms 364 KB Output is correct
30 Correct 16 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 380 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 3 ms 364 KB Output is correct
17 Correct 7 ms 364 KB Output is correct
18 Correct 10 ms 364 KB Output is correct
19 Correct 16 ms 364 KB Output is correct
20 Correct 17 ms 364 KB Output is correct
21 Correct 17 ms 364 KB Output is correct
22 Correct 12 ms 364 KB Output is correct
23 Correct 13 ms 364 KB Output is correct
24 Correct 14 ms 364 KB Output is correct
25 Correct 12 ms 364 KB Output is correct
26 Correct 18 ms 492 KB Output is correct
27 Correct 17 ms 364 KB Output is correct
28 Correct 15 ms 364 KB Output is correct
29 Correct 15 ms 364 KB Output is correct
30 Correct 16 ms 364 KB Output is correct
31 Correct 25 ms 384 KB Output is correct
32 Correct 40 ms 364 KB Output is correct
33 Correct 49 ms 364 KB Output is correct
34 Correct 56 ms 364 KB Output is correct
35 Correct 62 ms 492 KB Output is correct
36 Correct 61 ms 364 KB Output is correct
37 Correct 37 ms 396 KB Output is correct
38 Correct 50 ms 364 KB Output is correct
39 Correct 57 ms 364 KB Output is correct
40 Correct 81 ms 364 KB Output is correct
41 Correct 64 ms 492 KB Output is correct
42 Correct 62 ms 364 KB Output is correct
43 Correct 29 ms 492 KB Output is correct
44 Correct 62 ms 364 KB Output is correct
45 Correct 83 ms 364 KB Output is correct
46 Correct 63 ms 492 KB Output is correct
47 Correct 63 ms 492 KB Output is correct
48 Correct 60 ms 364 KB Output is correct
49 Correct 76 ms 364 KB Output is correct
50 Correct 65 ms 364 KB Output is correct
51 Correct 63 ms 492 KB Output is correct
52 Correct 55 ms 364 KB Output is correct
53 Correct 77 ms 364 KB Output is correct
54 Correct 68 ms 492 KB Output is correct
55 Correct 80 ms 364 KB Output is correct
56 Correct 78 ms 364 KB Output is correct
57 Correct 52 ms 492 KB Output is correct
58 Correct 75 ms 492 KB Output is correct
59 Correct 35 ms 524 KB Output is correct
60 Correct 78 ms 492 KB Output is correct