답안 #916856

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
916856 2024-01-26T15:30:54 Z LOLOLO Financial Report (JOI21_financial) C++17
100 / 100
523 ms 28620 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define           f     first
#define           s     second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (int)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())

const int N = 3e5 + 100;
int a[N];
bool cmp(int i, int j) {
    if (a[i] != a[j])
        return a[i] < a[j];

    return j < i;
}

int mn[N], p[N];

int get(int a) {
    return p[a] ? get(p[a]) : a;
}

int sz[N], seg[N * 4];

void unite(int a, int b) {
    a = get(a), b = get(b);
    if (a == b)
        return;

    if (sz[a] < sz[b])
        swap(a, b);

    sz[a] += sz[b];
    p[b] = a;
    mn[a] = min(mn[a], mn[b]);
}

void upd(int id, int l, int r, int p, int v) {
    if (l > p || r < p)
        return;

    if (l == r) {
        seg[id] = max(seg[id], v);
        return;
    }

    int m = (l + r) / 2;
    upd(id * 2, l, m, p, v);
    upd(id * 2 + 1, m + 1, r, p, v);
    seg[id] = max(seg[id * 2], seg[id * 2 + 1]);
}

int get(int id, int l, int r, int u, int v) {
    if (l > v || r < u || u > v)
        return 0;

    if (l >= u && r <= v)
        return seg[id];

    int m = (l + r) / 2;
    return max(get(id * 2, l, m, u, v), get(id * 2 + 1, m + 1, r, u, v));
}

ll solve() {
    int n, d;
    cin >> n >> d;

    for (int i = 1; i <= n; i++) {
        sz[i] = 1;
        mn[i] = i;
    }

    vector <int> v;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        v.pb(i);
    }

    sort(all(v), cmp);
    set <int> st;

    int ans = 1;
    for (auto x : v) {
        auto it = st.lower_bound(x);
        if (it != st.end()) {
            if (abs(*it - x) <= d) {
                unite(*it, x);
            }
        }

        if (it != st.begin()) {
            auto t = prev(it);
            if (abs(*t - x) <= d) {
                unite(*t, x);
            }
        }

        int v = mn[get(x)];
        int cur = get(1, 1, n, v, x - 1) + 1;
        ans = max(ans, cur);
        upd(1, 1, n, x, cur);
        st.insert(x);
    }

    return ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t = 1;
    //cin >> t;

    while (t--) {
        //solve();
        cout << solve() << '\n';
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4440 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4440 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 5 ms 4956 KB Output is correct
42 Correct 5 ms 4956 KB Output is correct
43 Correct 5 ms 4952 KB Output is correct
44 Correct 5 ms 4700 KB Output is correct
45 Correct 5 ms 4956 KB Output is correct
46 Correct 6 ms 4952 KB Output is correct
47 Correct 5 ms 4952 KB Output is correct
48 Correct 7 ms 4952 KB Output is correct
49 Correct 5 ms 4956 KB Output is correct
50 Correct 5 ms 4956 KB Output is correct
51 Correct 5 ms 4816 KB Output is correct
52 Correct 5 ms 4952 KB Output is correct
53 Correct 4 ms 4956 KB Output is correct
54 Correct 6 ms 4828 KB Output is correct
55 Correct 7 ms 4952 KB Output is correct
56 Correct 5 ms 4952 KB Output is correct
57 Correct 5 ms 4892 KB Output is correct
58 Correct 4 ms 4956 KB Output is correct
59 Correct 4 ms 4956 KB Output is correct
60 Correct 4 ms 4956 KB Output is correct
61 Correct 5 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 181 ms 26048 KB Output is correct
2 Correct 246 ms 27332 KB Output is correct
3 Correct 355 ms 27588 KB Output is correct
4 Correct 507 ms 27592 KB Output is correct
5 Correct 330 ms 27680 KB Output is correct
6 Correct 405 ms 27672 KB Output is correct
7 Correct 220 ms 27680 KB Output is correct
8 Correct 172 ms 27756 KB Output is correct
9 Correct 180 ms 27828 KB Output is correct
10 Correct 181 ms 27720 KB Output is correct
11 Correct 242 ms 27832 KB Output is correct
12 Correct 276 ms 27840 KB Output is correct
13 Correct 288 ms 27592 KB Output is correct
14 Correct 280 ms 27676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 200 ms 25800 KB Output is correct
2 Correct 333 ms 27572 KB Output is correct
3 Correct 419 ms 27704 KB Output is correct
4 Correct 362 ms 27592 KB Output is correct
5 Correct 314 ms 27832 KB Output is correct
6 Correct 397 ms 27712 KB Output is correct
7 Correct 185 ms 27596 KB Output is correct
8 Correct 159 ms 27872 KB Output is correct
9 Correct 186 ms 27668 KB Output is correct
10 Correct 245 ms 27748 KB Output is correct
11 Correct 342 ms 27664 KB Output is correct
12 Correct 346 ms 27592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4440 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 5 ms 4956 KB Output is correct
42 Correct 5 ms 4956 KB Output is correct
43 Correct 5 ms 4952 KB Output is correct
44 Correct 5 ms 4700 KB Output is correct
45 Correct 5 ms 4956 KB Output is correct
46 Correct 6 ms 4952 KB Output is correct
47 Correct 5 ms 4952 KB Output is correct
48 Correct 7 ms 4952 KB Output is correct
49 Correct 5 ms 4956 KB Output is correct
50 Correct 5 ms 4956 KB Output is correct
51 Correct 5 ms 4816 KB Output is correct
52 Correct 5 ms 4952 KB Output is correct
53 Correct 4 ms 4956 KB Output is correct
54 Correct 6 ms 4828 KB Output is correct
55 Correct 7 ms 4952 KB Output is correct
56 Correct 5 ms 4952 KB Output is correct
57 Correct 5 ms 4892 KB Output is correct
58 Correct 4 ms 4956 KB Output is correct
59 Correct 4 ms 4956 KB Output is correct
60 Correct 4 ms 4956 KB Output is correct
61 Correct 5 ms 4956 KB Output is correct
62 Correct 181 ms 26048 KB Output is correct
63 Correct 246 ms 27332 KB Output is correct
64 Correct 355 ms 27588 KB Output is correct
65 Correct 507 ms 27592 KB Output is correct
66 Correct 330 ms 27680 KB Output is correct
67 Correct 405 ms 27672 KB Output is correct
68 Correct 220 ms 27680 KB Output is correct
69 Correct 172 ms 27756 KB Output is correct
70 Correct 180 ms 27828 KB Output is correct
71 Correct 181 ms 27720 KB Output is correct
72 Correct 242 ms 27832 KB Output is correct
73 Correct 276 ms 27840 KB Output is correct
74 Correct 288 ms 27592 KB Output is correct
75 Correct 280 ms 27676 KB Output is correct
76 Correct 200 ms 25800 KB Output is correct
77 Correct 333 ms 27572 KB Output is correct
78 Correct 419 ms 27704 KB Output is correct
79 Correct 362 ms 27592 KB Output is correct
80 Correct 314 ms 27832 KB Output is correct
81 Correct 397 ms 27712 KB Output is correct
82 Correct 185 ms 27596 KB Output is correct
83 Correct 159 ms 27872 KB Output is correct
84 Correct 186 ms 27668 KB Output is correct
85 Correct 245 ms 27748 KB Output is correct
86 Correct 342 ms 27664 KB Output is correct
87 Correct 346 ms 27592 KB Output is correct
88 Correct 365 ms 27948 KB Output is correct
89 Correct 421 ms 27596 KB Output is correct
90 Correct 412 ms 27688 KB Output is correct
91 Correct 452 ms 27780 KB Output is correct
92 Correct 269 ms 27720 KB Output is correct
93 Correct 377 ms 27948 KB Output is correct
94 Correct 442 ms 27592 KB Output is correct
95 Correct 365 ms 27580 KB Output is correct
96 Correct 355 ms 27652 KB Output is correct
97 Correct 430 ms 27716 KB Output is correct
98 Correct 398 ms 27708 KB Output is correct
99 Correct 523 ms 27588 KB Output is correct
100 Correct 434 ms 27748 KB Output is correct
101 Correct 180 ms 27712 KB Output is correct
102 Correct 199 ms 27588 KB Output is correct
103 Correct 217 ms 27616 KB Output is correct
104 Correct 238 ms 27592 KB Output is correct
105 Correct 318 ms 27844 KB Output is correct
106 Correct 253 ms 27812 KB Output is correct
107 Correct 325 ms 27588 KB Output is correct
108 Correct 462 ms 28620 KB Output is correct
109 Correct 275 ms 27844 KB Output is correct
110 Correct 326 ms 27696 KB Output is correct
111 Correct 397 ms 27904 KB Output is correct
112 Correct 251 ms 27696 KB Output is correct
113 Correct 310 ms 27764 KB Output is correct
114 Correct 368 ms 27824 KB Output is correct
115 Correct 212 ms 27588 KB Output is correct
116 Correct 205 ms 27884 KB Output is correct
117 Correct 257 ms 27664 KB Output is correct
118 Correct 259 ms 27788 KB Output is correct
119 Correct 258 ms 27692 KB Output is correct
120 Correct 236 ms 27780 KB Output is correct