Submission #918998

# Submission time Handle Problem Language Result Execution time Memory
918998 2024-01-31T02:55:53 Z viwlesxq Xylophone (JOI18_xylophone) C++17
100 / 100
44 ms 1328 KB
#include <bits/stdc++.h>
using namespace std;
#include "xylophone.h"
//#include "grader.cpp"

void solve(int n) {
    vector<int> a(n + 1), d(n + 1);
    for (int i = 1; i < n; ++i) {
        d[i] = query(i, i + 1);
    }
    int min = 1, hi = n;
    while (min + 1 < hi) {
        int mid = (min + hi) / 2;
        if ((mid + 1 < n ? query(mid, n) : d[mid]) == n - 1) min = mid;
        else hi = mid;
    }
    a[min] = 1;
    int last = min, sum = 0;
    bool increasing = true;
    map<int, bool> used;
    used[1] = true;
    for (int i = min - 1; i > 0; --i) {
        int add = d[i];
        if (used[a[i + 1] + add] || a[i + 1] + add > n) {
            increasing = false, sum = 0, last = i + 1;
        } else if (used[a[i + 1] - add] || a[i + 1] - add <= 0) {
            increasing = true, sum = 0, last = i + 1;
        } else {
            int diff = (i + 1 < last ? query(i, last) : d[i]);
            if (sum + add != diff) {
                last = i + 1, sum = 0;
                increasing ^= true;
            }
        }
        a[i] = a[i + 1] + (increasing ? add : -add);
        used[a[i]] = true;
        sum += add;
    }
    last = min, sum = 0;
    increasing = true;
    for (int i = min + 1; i <= n; ++i) {
        int add = d[i - 1];
        if (used[a[i - 1] + add] || a[i - 1] + add > n) {
            increasing = false, sum = 0, last = i - 1;
        } else if (used[a[i - 1] - add] || a[i - 1] - add <= 0) {
            increasing = true, sum = 0, last = i - 1;
        } else {
            int diff = (last + 1 < i ? query(last, i) : d[last]);
            if (sum + add != diff) {
                last = i - 1, sum = 0;
                increasing ^= true;
            }
        }
        a[i] = a[i - 1] + (increasing ? add : -add);
        used[a[i]] = true;
        sum += add;
    }
    for (int i = 1; i <= n; ++i) {
        answer(i, a[i]);
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 544 KB Output is correct
3 Correct 0 ms 432 KB Output is correct
4 Correct 1 ms 432 KB Output is correct
5 Correct 1 ms 432 KB Output is correct
6 Correct 1 ms 436 KB Output is correct
7 Correct 1 ms 436 KB Output is correct
8 Correct 1 ms 436 KB Output is correct
9 Correct 1 ms 436 KB Output is correct
10 Correct 1 ms 432 KB Output is correct
11 Correct 1 ms 440 KB Output is correct
12 Correct 1 ms 436 KB Output is correct
13 Correct 2 ms 432 KB Output is correct
14 Correct 1 ms 432 KB Output is correct
15 Correct 1 ms 436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 544 KB Output is correct
3 Correct 0 ms 432 KB Output is correct
4 Correct 1 ms 432 KB Output is correct
5 Correct 1 ms 432 KB Output is correct
6 Correct 1 ms 436 KB Output is correct
7 Correct 1 ms 436 KB Output is correct
8 Correct 1 ms 436 KB Output is correct
9 Correct 1 ms 436 KB Output is correct
10 Correct 1 ms 432 KB Output is correct
11 Correct 1 ms 440 KB Output is correct
12 Correct 1 ms 436 KB Output is correct
13 Correct 2 ms 432 KB Output is correct
14 Correct 1 ms 432 KB Output is correct
15 Correct 1 ms 436 KB Output is correct
16 Correct 1 ms 696 KB Output is correct
17 Correct 4 ms 440 KB Output is correct
18 Correct 5 ms 700 KB Output is correct
19 Correct 5 ms 448 KB Output is correct
20 Correct 6 ms 700 KB Output is correct
21 Correct 5 ms 440 KB Output is correct
22 Correct 6 ms 700 KB Output is correct
23 Correct 5 ms 444 KB Output is correct
24 Correct 5 ms 448 KB Output is correct
25 Correct 4 ms 444 KB Output is correct
26 Correct 6 ms 444 KB Output is correct
27 Correct 7 ms 952 KB Output is correct
28 Correct 7 ms 700 KB Output is correct
29 Correct 8 ms 700 KB Output is correct
30 Correct 5 ms 700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 544 KB Output is correct
3 Correct 0 ms 432 KB Output is correct
4 Correct 1 ms 432 KB Output is correct
5 Correct 1 ms 432 KB Output is correct
6 Correct 1 ms 436 KB Output is correct
7 Correct 1 ms 436 KB Output is correct
8 Correct 1 ms 436 KB Output is correct
9 Correct 1 ms 436 KB Output is correct
10 Correct 1 ms 432 KB Output is correct
11 Correct 1 ms 440 KB Output is correct
12 Correct 1 ms 436 KB Output is correct
13 Correct 2 ms 432 KB Output is correct
14 Correct 1 ms 432 KB Output is correct
15 Correct 1 ms 436 KB Output is correct
16 Correct 1 ms 696 KB Output is correct
17 Correct 4 ms 440 KB Output is correct
18 Correct 5 ms 700 KB Output is correct
19 Correct 5 ms 448 KB Output is correct
20 Correct 6 ms 700 KB Output is correct
21 Correct 5 ms 440 KB Output is correct
22 Correct 6 ms 700 KB Output is correct
23 Correct 5 ms 444 KB Output is correct
24 Correct 5 ms 448 KB Output is correct
25 Correct 4 ms 444 KB Output is correct
26 Correct 6 ms 444 KB Output is correct
27 Correct 7 ms 952 KB Output is correct
28 Correct 7 ms 700 KB Output is correct
29 Correct 8 ms 700 KB Output is correct
30 Correct 5 ms 700 KB Output is correct
31 Correct 21 ms 448 KB Output is correct
32 Correct 20 ms 708 KB Output is correct
33 Correct 23 ms 976 KB Output is correct
34 Correct 27 ms 988 KB Output is correct
35 Correct 31 ms 884 KB Output is correct
36 Correct 19 ms 728 KB Output is correct
37 Correct 21 ms 720 KB Output is correct
38 Correct 28 ms 708 KB Output is correct
39 Correct 31 ms 736 KB Output is correct
40 Correct 29 ms 1000 KB Output is correct
41 Correct 28 ms 796 KB Output is correct
42 Correct 22 ms 712 KB Output is correct
43 Correct 24 ms 704 KB Output is correct
44 Correct 27 ms 708 KB Output is correct
45 Correct 44 ms 708 KB Output is correct
46 Correct 29 ms 964 KB Output is correct
47 Correct 28 ms 720 KB Output is correct
48 Correct 34 ms 964 KB Output is correct
49 Correct 37 ms 1328 KB Output is correct
50 Correct 35 ms 1216 KB Output is correct
51 Correct 29 ms 1056 KB Output is correct
52 Correct 28 ms 1032 KB Output is correct
53 Correct 36 ms 844 KB Output is correct
54 Correct 31 ms 960 KB Output is correct
55 Correct 27 ms 720 KB Output is correct
56 Correct 27 ms 960 KB Output is correct
57 Correct 35 ms 708 KB Output is correct
58 Correct 41 ms 964 KB Output is correct
59 Correct 32 ms 1240 KB Output is correct
60 Correct 37 ms 1216 KB Output is correct