Submission #918654

# Submission time Handle Problem Language Result Execution time Memory
918654 2024-01-30T08:28:44 Z viwlesxq Xylophone (JOI18_xylophone) C++17
47 / 100
44 ms 680 KB
#include <bits/stdc++.h>
using namespace std;
#include "xylophone.h"

void solve(int n) {
    vector<int> a(n + 1);
    int min = 1, max = n;
    int lo = 1, hi = n;
    while (lo + 1 < hi) {
        int mid = (lo + hi) / 2;
        if (query(mid, n) == n - 1) lo = mid;
        else hi = mid;
    }
    min = lo;
    lo = 1, hi = n;
    while (lo + 1 < hi) {
        int mid = (lo + hi) / 2;
        if (query(1, mid) == n - 1) hi = mid;
        else lo = mid;
    }
    max = hi;
    a[min] = 1, a[max] = n;
    int last = min, sum = 0;
    bool increasing = true;
    for (int i = min - 1; i > 0; --i) {
        int diff = query(i, last), add = query(i, i + 1);
        if (sum + add != diff) {
            last = i + 1, sum = 0;
            increasing ^= true;
        }
        a[i] = a[i + 1] + (increasing ? add : -add);
        sum += add;
    }
    last = min, sum = 0;
    increasing = true;
    for (int i = min + 1; i < max; ++i) {
        int diff = query(last, i), add = query(i - 1, i);
        if (sum + add != diff) {
            last = i - 1, sum = 0;
            increasing ^= true;
        }
        a[i] = a[i - 1] + (increasing ? add : -add);
        sum += add;
    }
    last = max, sum = 0;
    increasing = false;
    for (int i = max + 1; i <= n; ++i) {
        int diff = query(last, i), add = query(i - 1, i);
        if (sum + add != diff) {
            last = i - 1, sum = 0;
            increasing ^= true;
        }
        a[i] = a[i - 1] + (increasing ? add : -add);
        sum += add;
    }
    for (int i = 1; i <= n; ++i) {
        answer(i, a[i]);
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 4 ms 344 KB Output is correct
18 Correct 8 ms 344 KB Output is correct
19 Correct 8 ms 444 KB Output is correct
20 Correct 9 ms 440 KB Output is correct
21 Correct 8 ms 436 KB Output is correct
22 Correct 10 ms 444 KB Output is correct
23 Correct 9 ms 440 KB Output is correct
24 Correct 9 ms 444 KB Output is correct
25 Correct 9 ms 440 KB Output is correct
26 Correct 7 ms 448 KB Output is correct
27 Correct 10 ms 440 KB Output is correct
28 Correct 10 ms 680 KB Output is correct
29 Correct 7 ms 436 KB Output is correct
30 Correct 8 ms 440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 4 ms 344 KB Output is correct
18 Correct 8 ms 344 KB Output is correct
19 Correct 8 ms 444 KB Output is correct
20 Correct 9 ms 440 KB Output is correct
21 Correct 8 ms 436 KB Output is correct
22 Correct 10 ms 444 KB Output is correct
23 Correct 9 ms 440 KB Output is correct
24 Correct 9 ms 444 KB Output is correct
25 Correct 9 ms 440 KB Output is correct
26 Correct 7 ms 448 KB Output is correct
27 Correct 10 ms 440 KB Output is correct
28 Correct 10 ms 680 KB Output is correct
29 Correct 7 ms 436 KB Output is correct
30 Correct 8 ms 440 KB Output is correct
31 Correct 17 ms 432 KB Output is correct
32 Correct 27 ms 440 KB Output is correct
33 Correct 41 ms 428 KB Output is correct
34 Incorrect 44 ms 344 KB Wrong Answer [2]
35 Halted 0 ms 0 KB -