Submission #951139

# Submission time Handle Problem Language Result Execution time Memory
951139 2024-03-21T08:16:19 Z quanlt206 Xylophone (JOI18_xylophone) C++17
11 / 100
44 ms 684 KB
#include "xylophone.h"
#include<bits/stdc++.h>
#define X first
#define Y second
#define all(x) begin(x), end(x)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, b, a) for(int i = (b); i >= (a); i--)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define mxx max_element
#define mnn min_element
#define SQR(x) (1LL * (x) * (x))
#define MASK(i) (1LL << (i))
#define Point Vector
#define left Left
#define right Right
#define div Div

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef pair<db, db> pdb;
typedef pair<ld, ld> pld;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef pair<ll, int> pli;
typedef pair<ll, pii> plii;

template<class A, class B>
    bool maximize(A& x, B y) {
        if (x < y) return x = y, true; else return false;
    }
template<class A, class B>
    bool minimize(A& x, B y) {
        if (x > y) return x = y, true; else return false;
    }
/* END OF TEMPLATE */

const int N = 5007;

int n, b[N], a[N];

int qr[N];

void solve_1(int l, int r, int val) {
    if (l >= r) return ;
    // a[r] == 0 : Min, 1 : Max
    if (val == 0) {
        qr[r] = 0;
        FORD(i, r - 1, l) qr[i] = query(i, r);
        FORD(i, r - 1, l)
            if (qr[i] > qr[i + 1]) a[i] = a[r] + qr[i];
        int i = r;
        while (i >= l) {
            int j = i;
            while (a[j - 1] == 0 && j > l) j--;
            solve_1(j, i, 1);
            i = j - 1;
        }
    }
    else {
        qr[r] = 0;
        FORD(i, r - 1, l) qr[i] = query(i, r);
        FORD(i, r - 1, l)
            if (qr[i] > qr[i + 1]) a[i] = a[r] - qr[i];
        int i = r;
        while (i >= l) {
            int j = i;
            while (a[j - 1] == 0 && j > l) j--;
            solve_1(j, i, 0);
            i = j - 1;
        }
    }
}

void solve_2(int l, int r, int val) {
    // a[l] == Min ? Max
    if (l >= r) return ;
    if (val == 0) {
        qr[l] = 0;
        FOR(i, l + 1, r) qr[i] = query(l, i);
        FOR(i, l + 1, r)
            if (qr[i] > qr[i - 1]) a[i] = a[l] + qr[i];
        int i = l;
        while (i <= r) {
            int j = i;
            while (a[j + 1] == 0 && j < r) j++;
            solve_2(i, j, 1);
            i = j + 1;
        }
    }
    else {
        qr[l] = 0;
        FOR(i, l + 1, r) qr[i] = query(l, i);
        FOR(i, l + 1, r)
            if (qr[i] > qr[i - 1]) a[i] = a[l] - qr[i];
        int i = l;
        while (i <= r) {
            int j = i;
            while (a[j + 1] == 0 && j < r) j++;
            solve_2(i, j, 0);
            i = j + 1;
        }
    }
}

void solve(int m) {
    n = m;
    FOR(i, 1, n) a[i] = 0;
    int pos_1 = 0;
    int d = 1, c = n, g;
    while (d <= c) {
        g = (d + c) >> 1;
        if (query(g, n) == n - 1) pos_1 = g, d = g + 1; else c = g - 1;
    }
    FOR(i, 1, n) {
        if (i != pos_1) qr[i] = query(min(i, pos_1), max(i, pos_1));
        if (qr[i] == n - 1) break;
    }
    a[pos_1] = 1;
    qr[pos_1] = 0;
    FORD(i, pos_1 - 1, 1)
        if (qr[i] > qr[i + 1]) a[i] = qr[i] + 1;
    FOR(i, pos_1 + 1, n)
        if (qr[i] > qr[i - 1]) a[i] = qr[i] + 1;
    int i = pos_1;
    vector<pii> left, right;
    while (i > 0) {
        int j = i;
        while (j > 1 && a[j - 1] == 0) j--;
        left.push_back({j, i});
        i = j - 1;
    }
    i = pos_1;
    while (i <= n) {
        int j = i;
        while (j < n && a[j + 1] == 0) j++;
        right.push_back({i, j});
        i = j + 1;
    }
    for (auto x : left) solve_1(x.X, x.Y, 1);
    for (auto x : right) solve_2(x.X, x.Y, 1);
    FOR(i, 1, n) answer(i, a[i]);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 20 ms 440 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 2 ms 344 KB Output is correct
8 Correct 2 ms 344 KB Output is correct
9 Correct 1 ms 444 KB Output is correct
10 Correct 23 ms 444 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 344 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 2 ms 344 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 20 ms 440 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 2 ms 344 KB Output is correct
8 Correct 2 ms 344 KB Output is correct
9 Correct 1 ms 444 KB Output is correct
10 Correct 23 ms 444 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 344 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 2 ms 344 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
16 Correct 6 ms 596 KB Output is correct
17 Correct 11 ms 448 KB Output is correct
18 Correct 17 ms 440 KB Output is correct
19 Correct 28 ms 448 KB Output is correct
20 Correct 22 ms 444 KB Output is correct
21 Correct 24 ms 444 KB Output is correct
22 Correct 18 ms 684 KB Output is correct
23 Correct 5 ms 452 KB Output is correct
24 Incorrect 44 ms 448 KB Wrong Answer [2]
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 20 ms 440 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 2 ms 344 KB Output is correct
8 Correct 2 ms 344 KB Output is correct
9 Correct 1 ms 444 KB Output is correct
10 Correct 23 ms 444 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 344 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 2 ms 344 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
16 Correct 6 ms 596 KB Output is correct
17 Correct 11 ms 448 KB Output is correct
18 Correct 17 ms 440 KB Output is correct
19 Correct 28 ms 448 KB Output is correct
20 Correct 22 ms 444 KB Output is correct
21 Correct 24 ms 444 KB Output is correct
22 Correct 18 ms 684 KB Output is correct
23 Correct 5 ms 452 KB Output is correct
24 Incorrect 44 ms 448 KB Wrong Answer [2]
25 Halted 0 ms 0 KB -