답안 #588767

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
588767 2022-07-04T04:17:25 Z jack715 Rabbit Carrot (LMIO19_triusis) C++14
100 / 100
130 ms 17860 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 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 0 ms 320 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 324 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 0 ms 320 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 324 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 320 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 2 ms 724 KB Output is correct
22 Correct 3 ms 724 KB Output is correct
23 Correct 3 ms 724 KB Output is correct
24 Correct 2 ms 724 KB Output is correct
25 Correct 2 ms 724 KB Output is correct
26 Correct 3 ms 724 KB Output is correct
27 Correct 2 ms 724 KB Output is correct
28 Correct 2 ms 712 KB Output is correct
29 Correct 2 ms 724 KB Output is correct
30 Correct 2 ms 724 KB Output is correct
31 Correct 2 ms 724 KB Output is correct
32 Correct 2 ms 724 KB Output is correct
33 Correct 3 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 320 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 2 ms 724 KB Output is correct
6 Correct 3 ms 724 KB Output is correct
7 Correct 3 ms 724 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 3 ms 724 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 2 ms 712 KB Output is correct
13 Correct 2 ms 724 KB Output is correct
14 Correct 2 ms 724 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 2 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 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 320 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 320 KB Output is correct
27 Correct 0 ms 320 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 324 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 2 ms 724 KB Output is correct
35 Correct 3 ms 712 KB Output is correct
36 Correct 3 ms 724 KB Output is correct
37 Correct 3 ms 724 KB Output is correct
38 Correct 2 ms 724 KB Output is correct
39 Correct 3 ms 724 KB Output is correct
40 Correct 2 ms 724 KB Output is correct
41 Correct 3 ms 724 KB Output is correct
42 Correct 2 ms 712 KB Output is correct
43 Correct 2 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 724 KB Output is correct
2 Correct 3 ms 712 KB Output is correct
3 Correct 3 ms 724 KB Output is correct
4 Correct 3 ms 724 KB Output is correct
5 Correct 2 ms 724 KB Output is correct
6 Correct 3 ms 724 KB Output is correct
7 Correct 2 ms 724 KB Output is correct
8 Correct 3 ms 724 KB Output is correct
9 Correct 2 ms 712 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 3 ms 724 KB Output is correct
18 Correct 2 ms 724 KB Output is correct
19 Correct 2 ms 724 KB Output is correct
20 Correct 3 ms 724 KB Output is correct
21 Correct 2 ms 724 KB Output is correct
22 Correct 2 ms 712 KB Output is correct
23 Correct 2 ms 724 KB Output is correct
24 Correct 2 ms 724 KB Output is correct
25 Correct 2 ms 724 KB Output is correct
26 Correct 2 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 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 320 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 320 KB Output is correct
37 Correct 0 ms 320 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 324 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 70 ms 16840 KB Output is correct
45 Correct 130 ms 17848 KB Output is correct
46 Correct 130 ms 17856 KB Output is correct
47 Correct 128 ms 17860 KB Output is correct
48 Correct 70 ms 17304 KB Output is correct
49 Correct 74 ms 17508 KB Output is correct
50 Correct 84 ms 17856 KB Output is correct
51 Correct 85 ms 17796 KB Output is correct
52 Correct 88 ms 17252 KB Output is correct
53 Correct 87 ms 17700 KB Output is correct
54 Correct 73 ms 17500 KB Output is correct
55 Correct 74 ms 17500 KB Output is correct