답안 #561623

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
561623 2022-05-13T09:00:06 Z fatemetmhr Team Contest (JOI22_team) C++17
100 / 100
358 ms 34392 KB
// Be name khoda //

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb     push_back
#define all(x) x.begin(), x.end()
#define fi     first
#define se     second

const int maxn5 = 2e5 + 10;
const int maxnt = 8e5 + 10;
const ll  inf   = 1e15;

int n;

struct segment_tree_bs{

    ll mx[maxnt];

    int get_first(int l, int r, int lq, int rq, ll val, int v){
        if(rq <= l || r <= lq || mx[v] <= val)
            return n;
        if(r - l == 1)
            return l;
        int mid = (l + r) >> 1;
        int ans = get_first(l, mid, lq, rq, val, v * 2);
        if(ans != n)
            return ans;
        return get_first(mid, r, lq, rq, val, v * 2 + 1);
    }

    ll get_max(int l, int r, int lq, int rq, int v){
        if(rq <= l || r <= lq)
            return -inf;
        if(lq <= l && r <= rq)
            return mx[v];
        int mid = (l + r) >> 1;
        return max(get_max(l, mid, lq, rq, v * 2), get_max(mid, r, lq, rq, v * 2 + 1));
    }

    void update(int l, int r, int id, ll val, int v){
        if(r - l == 1){
            mx[v] = val;
            return;
        }
        int mid = (l + r) >> 1;
        if(id < mid)
            update(l, mid, id, val, v * 2);
        else
            update(mid, r, id, val, v * 2 + 1);
        mx[v] = max(mx[v * 2], mx[v * 2 + 1]);
        return;
    }

} val3_stored;

struct segment_tree_val2_plus_mx_val3{

    ll mxval2[maxnt], mxval3[maxnt], mx[maxnt];
    bool newval[maxnt];

    void build(){
        fill(mxval2, mxval2 + maxnt, -inf);
        fill(mxval3, mxval3 + maxnt, -inf);
        fill(mx, mx + maxnt, -inf);
        memset(newval, false, sizeof newval);
        return;
    }

    void shift(int v){
        if(!newval[v])
            return;
        newval[v] = false;
        mxval3[v * 2] = mxval3[v * 2 + 1] = mxval3[v];
        newval[v * 2] = newval[v * 2 + 1] = true;
        mx[v * 2] = mxval2[v * 2] + mxval3[v];
        mx[v * 2 + 1] = mxval2[v * 2 + 1] + mxval3[v];
        return;
    }

    void update_doone(int l, int r, int id, ll val, int v){
        if(r - l == 1){
            mxval2[v] = val;
            mx[v] = val + mxval3[v];
            return;
        }
        int mid = (l + r) >> 1; shift(v);
        if(id < mid)
            update_doone(l, mid, id, val, v * 2);
        else
            update_doone(mid, r, id, val, v * 2 + 1);
        mxval2[v] = max(mxval2[v * 2], mxval2[v * 2 + 1]);
        mx[v] = max(mx[v * 2], mx[v * 2 + 1]);
    }

    void sset(int l, int r, int lq, int rq, ll val, int v){
        if(rq <= l || r <= lq)
            return;
        if(lq <= l && r <= rq){
            newval[v] = true;
            mxval3[v] = val;
            mx[v] = val + mxval2[v];
            //cout << "here we go again " << l << ' ' << r << ' ' << lq << ' ' << rq << ' ' << v << endl;
            //cout << mx[v] << ' ' << mxval2[v] << ' ' << mxval3[v] << ' ' << newval[v] << endl;
            return;
        }
        int mid = (l + r) >> 1; shift(v);
        sset(l, mid, lq, rq, val, v * 2);
        sset(mid, r, lq, rq, val, v * 2 + 1);
        mx[v] = max(mx[v * 2], mx[v * 2 + 1]);
        return;
    }

    ll get_max(int l, int r, int lq, int rq, int v){
        if(rq <= l || r <= lq)
            return -inf;
        //cout << "oh a check for " << l << ' ' << r << ' ' << lq << ' ' << rq << ' ' << v << endl;
        //cout << mx[v] << ' ' << mxval2[v] << ' ' << mxval3[v] << ' ' << newval[v] << endl;
        if(lq <= l && r <= rq)
            return mx[v];
        int mid = (l + r) >> 1; shift(v);
        return max(get_max(l, mid, lq, rq, v * 2), get_max(mid, r, lq, rq, v * 2 + 1));
    }

} main_seg;

int pos2[maxn5], per1[maxn5], per2[maxn5];
ll bsval2[maxn5], val1[maxn5], val2[maxn5], val3[maxn5];
vector <int> toadd;

bool cmp1(int i, int j){return val1[i] < val1[j];}
bool cmp2(int i, int j){return val2[i] < val2[j] || (val2[i] == val2[j] && val3[i] < val3[j]);}

inline void add(int v){
    //cout << "succ add " << v << ' ' << pos2[v] << endl;
    main_seg.update_doone(0, n, pos2[v], val2[v], 1);
    if(val3_stored.get_max(0, n, 0, pos2[v], 1) <= val3[v]){
        int last = val3_stored.get_first(0, n, pos2[v], n, val3[v] - 1, 1);
        main_seg.sset(0, n, pos2[v] + 1, last, val3[v], 1);
        //ll havee = main_seg.get_max(0, n, n - 1, n, 1);
        //cout << "a check of vav " << havee << endl;
        main_seg.sset(0, n, pos2[v], pos2[v] + 1, -inf, 1);
        //cout << "ok " << last << endl;
    }
    val3_stored.update(0, n, pos2[v], val3[v], 1);
    //ll havehave = main_seg.get_max(0, n, n - 1, n, 1);
    //cout << "WTFFF " << havehave << endl;
    return;
}

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

    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> val1[i] >> val2[i] >> val3[i];
        per1[i] = per2[i] = i;
    }

    sort(per1, per1 + n, cmp1); // bar hasbe val1
    sort(per2, per2 + n, cmp2); // bar hasbe val2

    for(int i = 0; i < n; i++){
        pos2[per2[i]] = i;
        bsval2[i] = val2[per2[i]];
    }

    main_seg.build(); // hame ro bezar -inf
    // val3_stored.build(0, n, 1); // hame ro bezar 0

    ll ans = -1;

    for(int i = 0; i < n; i++){
        int v = per1[i];
        //cout << "see "  << v << ' ' << pos2[v] << endl;
        while(toadd.size() && val1[toadd.back()] < val1[v]){
            add(toadd.back());
            toadd.pop_back();
        }
        int pt1 = upper_bound(bsval2, bsval2 + n, val2[v]) - bsval2;
        int pt2 = val3_stored.get_first(0, n, 0, n, val3[v], 1); // avalin kasi ke az akidan val3 bishtar darad, agar nabood n midahad

        int pt = max(pt1, pt2);

        ans = max(ans, main_seg.get_max(0, n, pt, n, 1) + val1[v]);
        //cout << "having " << pt1 << ' ' << pt2 << ' ' << ans << endl;
        toadd.pb(v);
    }

    cout << ans << endl;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 19924 KB Output is correct
2 Correct 8 ms 19924 KB Output is correct
3 Correct 8 ms 19936 KB Output is correct
4 Correct 9 ms 19824 KB Output is correct
5 Correct 10 ms 19828 KB Output is correct
6 Correct 9 ms 19932 KB Output is correct
7 Correct 10 ms 19888 KB Output is correct
8 Correct 11 ms 19932 KB Output is correct
9 Correct 12 ms 19924 KB Output is correct
10 Correct 9 ms 19924 KB Output is correct
11 Correct 8 ms 19852 KB Output is correct
12 Correct 8 ms 19924 KB Output is correct
13 Correct 9 ms 19924 KB Output is correct
14 Correct 10 ms 19924 KB Output is correct
15 Correct 9 ms 19868 KB Output is correct
16 Correct 9 ms 19924 KB Output is correct
17 Correct 9 ms 19924 KB Output is correct
18 Correct 9 ms 19924 KB Output is correct
19 Correct 9 ms 19924 KB Output is correct
20 Correct 9 ms 19924 KB Output is correct
21 Correct 10 ms 19848 KB Output is correct
22 Correct 9 ms 19924 KB Output is correct
23 Correct 8 ms 19924 KB Output is correct
24 Correct 10 ms 19924 KB Output is correct
25 Correct 9 ms 19960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 19924 KB Output is correct
2 Correct 8 ms 19924 KB Output is correct
3 Correct 8 ms 19936 KB Output is correct
4 Correct 9 ms 19824 KB Output is correct
5 Correct 10 ms 19828 KB Output is correct
6 Correct 9 ms 19932 KB Output is correct
7 Correct 10 ms 19888 KB Output is correct
8 Correct 11 ms 19932 KB Output is correct
9 Correct 12 ms 19924 KB Output is correct
10 Correct 9 ms 19924 KB Output is correct
11 Correct 8 ms 19852 KB Output is correct
12 Correct 8 ms 19924 KB Output is correct
13 Correct 9 ms 19924 KB Output is correct
14 Correct 10 ms 19924 KB Output is correct
15 Correct 9 ms 19868 KB Output is correct
16 Correct 9 ms 19924 KB Output is correct
17 Correct 9 ms 19924 KB Output is correct
18 Correct 9 ms 19924 KB Output is correct
19 Correct 9 ms 19924 KB Output is correct
20 Correct 9 ms 19924 KB Output is correct
21 Correct 10 ms 19848 KB Output is correct
22 Correct 9 ms 19924 KB Output is correct
23 Correct 8 ms 19924 KB Output is correct
24 Correct 10 ms 19924 KB Output is correct
25 Correct 9 ms 19960 KB Output is correct
26 Correct 12 ms 20052 KB Output is correct
27 Correct 13 ms 20228 KB Output is correct
28 Correct 15 ms 20180 KB Output is correct
29 Correct 14 ms 20232 KB Output is correct
30 Correct 15 ms 20032 KB Output is correct
31 Correct 16 ms 20176 KB Output is correct
32 Correct 14 ms 20108 KB Output is correct
33 Correct 13 ms 20180 KB Output is correct
34 Correct 13 ms 20180 KB Output is correct
35 Correct 11 ms 19924 KB Output is correct
36 Correct 10 ms 19916 KB Output is correct
37 Correct 12 ms 20180 KB Output is correct
38 Correct 13 ms 20168 KB Output is correct
39 Correct 13 ms 20040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 19868 KB Output is correct
2 Correct 9 ms 19924 KB Output is correct
3 Correct 12 ms 19860 KB Output is correct
4 Correct 9 ms 19924 KB Output is correct
5 Correct 9 ms 19924 KB Output is correct
6 Correct 8 ms 19924 KB Output is correct
7 Correct 9 ms 19844 KB Output is correct
8 Correct 13 ms 19880 KB Output is correct
9 Correct 11 ms 19924 KB Output is correct
10 Correct 9 ms 19924 KB Output is correct
11 Correct 195 ms 30696 KB Output is correct
12 Correct 126 ms 26912 KB Output is correct
13 Correct 155 ms 28320 KB Output is correct
14 Correct 169 ms 31092 KB Output is correct
15 Correct 92 ms 29448 KB Output is correct
16 Correct 47 ms 28136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 19868 KB Output is correct
2 Correct 9 ms 19924 KB Output is correct
3 Correct 12 ms 19860 KB Output is correct
4 Correct 9 ms 19924 KB Output is correct
5 Correct 9 ms 19924 KB Output is correct
6 Correct 8 ms 19924 KB Output is correct
7 Correct 9 ms 19844 KB Output is correct
8 Correct 13 ms 19880 KB Output is correct
9 Correct 11 ms 19924 KB Output is correct
10 Correct 9 ms 19924 KB Output is correct
11 Correct 195 ms 30696 KB Output is correct
12 Correct 126 ms 26912 KB Output is correct
13 Correct 155 ms 28320 KB Output is correct
14 Correct 169 ms 31092 KB Output is correct
15 Correct 92 ms 29448 KB Output is correct
16 Correct 47 ms 28136 KB Output is correct
17 Correct 10 ms 19924 KB Output is correct
18 Correct 9 ms 19924 KB Output is correct
19 Correct 10 ms 19856 KB Output is correct
20 Correct 10 ms 19912 KB Output is correct
21 Correct 10 ms 20076 KB Output is correct
22 Correct 233 ms 31332 KB Output is correct
23 Correct 229 ms 31184 KB Output is correct
24 Correct 147 ms 27340 KB Output is correct
25 Correct 215 ms 31564 KB Output is correct
26 Correct 103 ms 30060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 19868 KB Output is correct
2 Correct 9 ms 19924 KB Output is correct
3 Correct 12 ms 19860 KB Output is correct
4 Correct 9 ms 19924 KB Output is correct
5 Correct 9 ms 19924 KB Output is correct
6 Correct 8 ms 19924 KB Output is correct
7 Correct 9 ms 19844 KB Output is correct
8 Correct 13 ms 19880 KB Output is correct
9 Correct 11 ms 19924 KB Output is correct
10 Correct 9 ms 19924 KB Output is correct
11 Correct 195 ms 30696 KB Output is correct
12 Correct 126 ms 26912 KB Output is correct
13 Correct 155 ms 28320 KB Output is correct
14 Correct 169 ms 31092 KB Output is correct
15 Correct 92 ms 29448 KB Output is correct
16 Correct 47 ms 28136 KB Output is correct
17 Correct 10 ms 19924 KB Output is correct
18 Correct 9 ms 19924 KB Output is correct
19 Correct 10 ms 19856 KB Output is correct
20 Correct 10 ms 19912 KB Output is correct
21 Correct 10 ms 20076 KB Output is correct
22 Correct 233 ms 31332 KB Output is correct
23 Correct 229 ms 31184 KB Output is correct
24 Correct 147 ms 27340 KB Output is correct
25 Correct 215 ms 31564 KB Output is correct
26 Correct 103 ms 30060 KB Output is correct
27 Correct 9 ms 19924 KB Output is correct
28 Correct 12 ms 19964 KB Output is correct
29 Correct 9 ms 19916 KB Output is correct
30 Correct 9 ms 19924 KB Output is correct
31 Correct 13 ms 20160 KB Output is correct
32 Correct 10 ms 19924 KB Output is correct
33 Correct 10 ms 19980 KB Output is correct
34 Correct 286 ms 31476 KB Output is correct
35 Correct 259 ms 30856 KB Output is correct
36 Correct 284 ms 31552 KB Output is correct
37 Correct 263 ms 32060 KB Output is correct
38 Correct 115 ms 30000 KB Output is correct
39 Correct 41 ms 25052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 19868 KB Output is correct
2 Correct 9 ms 19924 KB Output is correct
3 Correct 12 ms 19860 KB Output is correct
4 Correct 9 ms 19924 KB Output is correct
5 Correct 9 ms 19924 KB Output is correct
6 Correct 8 ms 19924 KB Output is correct
7 Correct 9 ms 19844 KB Output is correct
8 Correct 13 ms 19880 KB Output is correct
9 Correct 11 ms 19924 KB Output is correct
10 Correct 9 ms 19924 KB Output is correct
11 Correct 195 ms 30696 KB Output is correct
12 Correct 126 ms 26912 KB Output is correct
13 Correct 155 ms 28320 KB Output is correct
14 Correct 169 ms 31092 KB Output is correct
15 Correct 92 ms 29448 KB Output is correct
16 Correct 47 ms 28136 KB Output is correct
17 Correct 10 ms 19924 KB Output is correct
18 Correct 9 ms 19924 KB Output is correct
19 Correct 10 ms 19856 KB Output is correct
20 Correct 10 ms 19912 KB Output is correct
21 Correct 10 ms 20076 KB Output is correct
22 Correct 233 ms 31332 KB Output is correct
23 Correct 229 ms 31184 KB Output is correct
24 Correct 147 ms 27340 KB Output is correct
25 Correct 215 ms 31564 KB Output is correct
26 Correct 103 ms 30060 KB Output is correct
27 Correct 9 ms 19924 KB Output is correct
28 Correct 12 ms 19964 KB Output is correct
29 Correct 9 ms 19916 KB Output is correct
30 Correct 9 ms 19924 KB Output is correct
31 Correct 13 ms 20160 KB Output is correct
32 Correct 10 ms 19924 KB Output is correct
33 Correct 10 ms 19980 KB Output is correct
34 Correct 286 ms 31476 KB Output is correct
35 Correct 259 ms 30856 KB Output is correct
36 Correct 284 ms 31552 KB Output is correct
37 Correct 263 ms 32060 KB Output is correct
38 Correct 115 ms 30000 KB Output is correct
39 Correct 41 ms 25052 KB Output is correct
40 Correct 12 ms 20052 KB Output is correct
41 Correct 15 ms 20180 KB Output is correct
42 Correct 13 ms 20172 KB Output is correct
43 Correct 12 ms 20176 KB Output is correct
44 Correct 325 ms 32480 KB Output is correct
45 Correct 303 ms 32316 KB Output is correct
46 Correct 328 ms 31856 KB Output is correct
47 Correct 336 ms 32460 KB Output is correct
48 Correct 122 ms 31120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 19924 KB Output is correct
2 Correct 8 ms 19924 KB Output is correct
3 Correct 8 ms 19936 KB Output is correct
4 Correct 9 ms 19824 KB Output is correct
5 Correct 10 ms 19828 KB Output is correct
6 Correct 9 ms 19932 KB Output is correct
7 Correct 10 ms 19888 KB Output is correct
8 Correct 11 ms 19932 KB Output is correct
9 Correct 12 ms 19924 KB Output is correct
10 Correct 9 ms 19924 KB Output is correct
11 Correct 8 ms 19852 KB Output is correct
12 Correct 8 ms 19924 KB Output is correct
13 Correct 9 ms 19924 KB Output is correct
14 Correct 10 ms 19924 KB Output is correct
15 Correct 9 ms 19868 KB Output is correct
16 Correct 9 ms 19924 KB Output is correct
17 Correct 9 ms 19924 KB Output is correct
18 Correct 9 ms 19924 KB Output is correct
19 Correct 9 ms 19924 KB Output is correct
20 Correct 9 ms 19924 KB Output is correct
21 Correct 10 ms 19848 KB Output is correct
22 Correct 9 ms 19924 KB Output is correct
23 Correct 8 ms 19924 KB Output is correct
24 Correct 10 ms 19924 KB Output is correct
25 Correct 9 ms 19960 KB Output is correct
26 Correct 12 ms 20052 KB Output is correct
27 Correct 13 ms 20228 KB Output is correct
28 Correct 15 ms 20180 KB Output is correct
29 Correct 14 ms 20232 KB Output is correct
30 Correct 15 ms 20032 KB Output is correct
31 Correct 16 ms 20176 KB Output is correct
32 Correct 14 ms 20108 KB Output is correct
33 Correct 13 ms 20180 KB Output is correct
34 Correct 13 ms 20180 KB Output is correct
35 Correct 11 ms 19924 KB Output is correct
36 Correct 10 ms 19916 KB Output is correct
37 Correct 12 ms 20180 KB Output is correct
38 Correct 13 ms 20168 KB Output is correct
39 Correct 13 ms 20040 KB Output is correct
40 Correct 9 ms 19868 KB Output is correct
41 Correct 9 ms 19924 KB Output is correct
42 Correct 12 ms 19860 KB Output is correct
43 Correct 9 ms 19924 KB Output is correct
44 Correct 9 ms 19924 KB Output is correct
45 Correct 8 ms 19924 KB Output is correct
46 Correct 9 ms 19844 KB Output is correct
47 Correct 13 ms 19880 KB Output is correct
48 Correct 11 ms 19924 KB Output is correct
49 Correct 9 ms 19924 KB Output is correct
50 Correct 195 ms 30696 KB Output is correct
51 Correct 126 ms 26912 KB Output is correct
52 Correct 155 ms 28320 KB Output is correct
53 Correct 169 ms 31092 KB Output is correct
54 Correct 92 ms 29448 KB Output is correct
55 Correct 47 ms 28136 KB Output is correct
56 Correct 10 ms 19924 KB Output is correct
57 Correct 9 ms 19924 KB Output is correct
58 Correct 10 ms 19856 KB Output is correct
59 Correct 10 ms 19912 KB Output is correct
60 Correct 10 ms 20076 KB Output is correct
61 Correct 233 ms 31332 KB Output is correct
62 Correct 229 ms 31184 KB Output is correct
63 Correct 147 ms 27340 KB Output is correct
64 Correct 215 ms 31564 KB Output is correct
65 Correct 103 ms 30060 KB Output is correct
66 Correct 9 ms 19924 KB Output is correct
67 Correct 12 ms 19964 KB Output is correct
68 Correct 9 ms 19916 KB Output is correct
69 Correct 9 ms 19924 KB Output is correct
70 Correct 13 ms 20160 KB Output is correct
71 Correct 10 ms 19924 KB Output is correct
72 Correct 10 ms 19980 KB Output is correct
73 Correct 286 ms 31476 KB Output is correct
74 Correct 259 ms 30856 KB Output is correct
75 Correct 284 ms 31552 KB Output is correct
76 Correct 263 ms 32060 KB Output is correct
77 Correct 115 ms 30000 KB Output is correct
78 Correct 41 ms 25052 KB Output is correct
79 Correct 12 ms 20052 KB Output is correct
80 Correct 15 ms 20180 KB Output is correct
81 Correct 13 ms 20172 KB Output is correct
82 Correct 12 ms 20176 KB Output is correct
83 Correct 325 ms 32480 KB Output is correct
84 Correct 303 ms 32316 KB Output is correct
85 Correct 328 ms 31856 KB Output is correct
86 Correct 336 ms 32460 KB Output is correct
87 Correct 122 ms 31120 KB Output is correct
88 Correct 337 ms 33000 KB Output is correct
89 Correct 318 ms 32556 KB Output is correct
90 Correct 330 ms 34392 KB Output is correct
91 Correct 323 ms 31948 KB Output is correct
92 Correct 321 ms 31992 KB Output is correct
93 Correct 345 ms 33136 KB Output is correct
94 Correct 358 ms 33132 KB Output is correct
95 Correct 137 ms 32912 KB Output is correct
96 Correct 207 ms 34036 KB Output is correct
97 Correct 72 ms 30052 KB Output is correct
98 Correct 165 ms 33008 KB Output is correct
99 Correct 201 ms 32816 KB Output is correct