답안 #588759

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
588759 2022-07-04T03:12:11 Z jack715 Rabbit Carrot (LMIO19_triusis) C++14
100 / 100
177 ms 18452 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pp pop_back
#define mp make_pair
#define bb back
#define ff first
#define ss second
#define int long long

using namespace std;

int n, m;
vector<int> nums, segtree, srt;

void update(int indx, int st, int end, int v, int val) {
    if (st == end) {
        segtree[indx] = val;
        return;
    }
    int mid = (st + end) / 2;
    if (v <= mid) 
        update(indx*2, st, mid, v, val);
    else 
        update(indx*2+1, mid+1, end, v, val);
    segtree[indx] = min(segtree[indx*2], segtree[indx*2+1]);
}

int query(int indx, int st, int end, int v) {
    // cout << indx << ' ' << st << ' ' << end << '\n';
    // cout << srt[st] << ' ' << srt[end] << '\n';
    if (srt[end] < v) return 1e9;
    if (srt[st] >= v) return segtree[indx];
    int mid = (st + end) / 2;
    return min(query(indx*2, st, mid, v), query(indx*2+1, mid+1, end, v));
}

signed main(){
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // freopen("tmp.in,", "r", stdin);
    // freopen("tmp.out", "w", stdout);

    cin >> n >> m;
    nums.resize(n+1), segtree.resize(n*4+10, 1e9);
    nums[0] = 0;
    vector<int> indx(n+1);
    vector<pair<int, int> > tmp;
    for (int i = 1; i <= n; i++) 
        cin >> nums[i];
    for (int i = 0; i <= n; i++)
        tmp.pb({nums[i]+(n-i)*m, i});
    sort(tmp.begin(), tmp.end());
    for (int i = 0; i <= n; i++) {
        srt.pb(tmp[i].ff);
        indx[tmp[i].ss] = i;
    }
    update(1, 0, n, indx[0], n);
    for (int i = 1; i <= n; i++) {
        int now = query(1, 0, n, nums[i]+(n-i)*m);
        // cout << now << ' ' << indx[i] << ", ";
        update(1, 0, n, indx[i], now-1);
    }
    // cout << '\n';

    int ans = query(1, 0, n, 0);
    cout << ans << '\n';
    return 0;
}

/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?)
    * do smth instead of nothing and stay organized
    * WRITE STUFF DOWN
    * DON'T GET STUCK ON ONE APPROACH
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 296 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 300 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 296 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 300 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 2 ms 596 KB Output is correct
21 Correct 2 ms 724 KB Output is correct
22 Correct 4 ms 724 KB Output is correct
23 Correct 3 ms 724 KB Output is correct
24 Correct 3 ms 724 KB Output is correct
25 Correct 3 ms 724 KB Output is correct
26 Correct 3 ms 724 KB Output is correct
27 Correct 3 ms 724 KB Output is correct
28 Correct 3 ms 724 KB Output is correct
29 Correct 2 ms 852 KB Output is correct
30 Correct 3 ms 724 KB Output is correct
31 Correct 3 ms 692 KB Output is correct
32 Correct 3 ms 724 KB Output is correct
33 Correct 3 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 2 ms 724 KB Output is correct
6 Correct 4 ms 724 KB Output is correct
7 Correct 3 ms 724 KB Output is correct
8 Correct 3 ms 724 KB Output is correct
9 Correct 3 ms 724 KB Output is correct
10 Correct 3 ms 724 KB Output is correct
11 Correct 3 ms 724 KB Output is correct
12 Correct 3 ms 724 KB Output is correct
13 Correct 2 ms 852 KB Output is correct
14 Correct 3 ms 724 KB Output is correct
15 Correct 3 ms 692 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 3 ms 724 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 296 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 300 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 4 ms 724 KB Output is correct
35 Correct 4 ms 724 KB Output is correct
36 Correct 4 ms 724 KB Output is correct
37 Correct 3 ms 724 KB Output is correct
38 Correct 4 ms 724 KB Output is correct
39 Correct 4 ms 800 KB Output is correct
40 Correct 4 ms 724 KB Output is correct
41 Correct 5 ms 724 KB Output is correct
42 Correct 4 ms 696 KB Output is correct
43 Correct 3 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 724 KB Output is correct
2 Correct 4 ms 724 KB Output is correct
3 Correct 4 ms 724 KB Output is correct
4 Correct 3 ms 724 KB Output is correct
5 Correct 4 ms 724 KB Output is correct
6 Correct 4 ms 800 KB Output is correct
7 Correct 4 ms 724 KB Output is correct
8 Correct 5 ms 724 KB Output is correct
9 Correct 4 ms 696 KB Output is correct
10 Correct 3 ms 724 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 3 ms 724 KB Output is correct
18 Correct 3 ms 724 KB Output is correct
19 Correct 3 ms 724 KB Output is correct
20 Correct 3 ms 724 KB Output is correct
21 Correct 3 ms 724 KB Output is correct
22 Correct 3 ms 724 KB Output is correct
23 Correct 2 ms 852 KB Output is correct
24 Correct 3 ms 724 KB Output is correct
25 Correct 3 ms 692 KB Output is correct
26 Correct 3 ms 724 KB Output is correct
27 Correct 3 ms 724 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 296 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 300 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 91 ms 16796 KB Output is correct
45 Correct 175 ms 18452 KB Output is correct
46 Correct 177 ms 18372 KB Output is correct
47 Correct 175 ms 18368 KB Output is correct
48 Correct 102 ms 17336 KB Output is correct
49 Correct 104 ms 17600 KB Output is correct
50 Correct 134 ms 18312 KB Output is correct
51 Correct 136 ms 18364 KB Output is correct
52 Correct 112 ms 17336 KB Output is correct
53 Correct 130 ms 17588 KB Output is correct
54 Correct 104 ms 17472 KB Output is correct
55 Correct 103 ms 17460 KB Output is correct