Submission #1100490

# Submission time Handle Problem Language Result Execution time Memory
1100490 2024-10-14T05:43:45 Z KawakiMeido Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1074 ms 91000 KB
/*Author: KawakiMeido*/
#include <bits/stdc++.h>
#define pb push_back
#define endl "\n"
#define ll long long
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int>
#define piii pair<pii,int>
#define fi first
#define se second

using namespace std;

/*Constants*/
const int N = 1e6+10;
const int INF = 1e9+7;
const long long LLINF = 1e18+3;

/*TestCases*/
int test=1;
void solve();
void TestCases(bool v){
    if (v) cin >> test;
    while(test--) solve();
}

/*Global Variables*/
int n,q;
deque<pii> dq;
int a[N];
vector<piii> query;
pair<pii,int> info[N];
int ans[N];

//SEGGS

int ST[4*N];

void Update(int idx, int l, int r, int x, int val){
    if (x<l || r<x) return;
    if (l==r){
        ST[idx] = max(ST[idx],val);
        return;
    }

    int mid = (l+r)/2;
    Update(idx*2,l,mid,x,val); Update(idx*2+1,mid+1,r,x,val);
    ST[idx] = max(ST[idx*2],ST[idx*2+1]);
}

int Get(int idx, int l, int r, int x, int y){
    if (y<l || r<x) return 0;
    if (x<=l&&r<=y) return ST[idx];
    int mid = (l+r)/2;
    return max(Get(idx*2,l,mid,x,y),Get(idx*2+1,mid+1,r,x,y));
}

/*Solution*/
void solve(){
    cin >> n >> q;
    for (int i=1; i<=n; i++){
        cin >> a[i];
        query.push_back({{i,1},a[i]});
    }
//    for (int i=1; i<=n; i++){
//        cout << a[i] << endl;
//    }
    for (int i=1; i<=q; i++){
        int l,r,w; cin >> l >> r >> w;
        info[i] = {{l,r},w};
        query.push_back({{l,0},i});
    }
    sort(all(query),greater<piii>());
    int idx = 0;
    for (int i=n; i>0; i--){
        while (idx!=(int)query.size() && query[idx].fi.fi == i){
            int ver = query[idx].fi.se;
            int l = query[idx].fi.fi;
//            cout << l << " " << ver << endl;
            if (!ver){
                int id = query[idx].se;
                int r = info[id].fi.se;
                int val = info[id].se;
                int mx = Get(1,1,n,l,r);
                if (mx > val) ans[id] = 0;
                else ans[id] = 1;
            }
            else{
                int val = query[idx].se;
                while (!dq.empty() && dq.back().fi<val){
                    Update(1,1,n,dq.back().se,val+dq.back().fi);
//                    cout << "back: " << dq.back().fi << " " << dq.back().se << endl;
                    dq.pop_back();
                }
//                cout << "val: " << val << " " << l << endl;
                dq.push_back({val,l});
            }
            ++idx;
        }
//        for (int i=1; i<=n; i++){
//            cout << Get(1,1,n,i,i) << " ";
//        }
//        cout << endl;
    }
    for (int i=1; i<=q; i++){
        cout << ans[i] << endl;
    }
}

/*Driver Code*/
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    TestCases(0);

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6484 KB Output is correct
2 Correct 1 ms 6484 KB Output is correct
3 Correct 2 ms 6484 KB Output is correct
4 Correct 2 ms 6484 KB Output is correct
5 Correct 2 ms 6484 KB Output is correct
6 Correct 2 ms 6484 KB Output is correct
7 Correct 2 ms 6628 KB Output is correct
8 Correct 2 ms 6740 KB Output is correct
9 Correct 2 ms 6484 KB Output is correct
10 Correct 2 ms 6484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6484 KB Output is correct
2 Correct 1 ms 6484 KB Output is correct
3 Correct 2 ms 6484 KB Output is correct
4 Correct 2 ms 6484 KB Output is correct
5 Correct 2 ms 6484 KB Output is correct
6 Correct 2 ms 6484 KB Output is correct
7 Correct 2 ms 6628 KB Output is correct
8 Correct 2 ms 6740 KB Output is correct
9 Correct 2 ms 6484 KB Output is correct
10 Correct 2 ms 6484 KB Output is correct
11 Correct 3 ms 6740 KB Output is correct
12 Correct 3 ms 6740 KB Output is correct
13 Correct 4 ms 6740 KB Output is correct
14 Correct 6 ms 6936 KB Output is correct
15 Correct 5 ms 6948 KB Output is correct
16 Correct 5 ms 6936 KB Output is correct
17 Correct 3 ms 6828 KB Output is correct
18 Correct 4 ms 6936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 991 ms 87800 KB Output is correct
2 Correct 977 ms 88808 KB Output is correct
3 Correct 981 ms 88908 KB Output is correct
4 Correct 993 ms 88816 KB Output is correct
5 Correct 840 ms 88748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 14268 KB Output is correct
2 Correct 77 ms 14268 KB Output is correct
3 Correct 70 ms 14012 KB Output is correct
4 Correct 77 ms 13952 KB Output is correct
5 Correct 71 ms 14012 KB Output is correct
6 Correct 63 ms 13928 KB Output is correct
7 Correct 62 ms 13764 KB Output is correct
8 Correct 66 ms 13932 KB Output is correct
9 Correct 33 ms 11312 KB Output is correct
10 Correct 63 ms 13760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6484 KB Output is correct
2 Correct 1 ms 6484 KB Output is correct
3 Correct 2 ms 6484 KB Output is correct
4 Correct 2 ms 6484 KB Output is correct
5 Correct 2 ms 6484 KB Output is correct
6 Correct 2 ms 6484 KB Output is correct
7 Correct 2 ms 6628 KB Output is correct
8 Correct 2 ms 6740 KB Output is correct
9 Correct 2 ms 6484 KB Output is correct
10 Correct 2 ms 6484 KB Output is correct
11 Correct 3 ms 6740 KB Output is correct
12 Correct 3 ms 6740 KB Output is correct
13 Correct 4 ms 6740 KB Output is correct
14 Correct 6 ms 6936 KB Output is correct
15 Correct 5 ms 6948 KB Output is correct
16 Correct 5 ms 6936 KB Output is correct
17 Correct 3 ms 6828 KB Output is correct
18 Correct 4 ms 6936 KB Output is correct
19 Correct 179 ms 23988 KB Output is correct
20 Correct 175 ms 23908 KB Output is correct
21 Correct 161 ms 23740 KB Output is correct
22 Correct 163 ms 23732 KB Output is correct
23 Correct 172 ms 23784 KB Output is correct
24 Correct 133 ms 22964 KB Output is correct
25 Correct 131 ms 22972 KB Output is correct
26 Correct 144 ms 23224 KB Output is correct
27 Correct 151 ms 23220 KB Output is correct
28 Correct 152 ms 23220 KB Output is correct
29 Correct 152 ms 23476 KB Output is correct
30 Correct 143 ms 23240 KB Output is correct
31 Correct 144 ms 23372 KB Output is correct
32 Correct 192 ms 23476 KB Output is correct
33 Correct 143 ms 23324 KB Output is correct
34 Correct 122 ms 22968 KB Output is correct
35 Correct 126 ms 23132 KB Output is correct
36 Correct 123 ms 22776 KB Output is correct
37 Correct 129 ms 22852 KB Output is correct
38 Correct 150 ms 23024 KB Output is correct
39 Correct 131 ms 22200 KB Output is correct
40 Correct 107 ms 18684 KB Output is correct
41 Correct 127 ms 21676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6484 KB Output is correct
2 Correct 1 ms 6484 KB Output is correct
3 Correct 2 ms 6484 KB Output is correct
4 Correct 2 ms 6484 KB Output is correct
5 Correct 2 ms 6484 KB Output is correct
6 Correct 2 ms 6484 KB Output is correct
7 Correct 2 ms 6628 KB Output is correct
8 Correct 2 ms 6740 KB Output is correct
9 Correct 2 ms 6484 KB Output is correct
10 Correct 2 ms 6484 KB Output is correct
11 Correct 3 ms 6740 KB Output is correct
12 Correct 3 ms 6740 KB Output is correct
13 Correct 4 ms 6740 KB Output is correct
14 Correct 6 ms 6936 KB Output is correct
15 Correct 5 ms 6948 KB Output is correct
16 Correct 5 ms 6936 KB Output is correct
17 Correct 3 ms 6828 KB Output is correct
18 Correct 4 ms 6936 KB Output is correct
19 Correct 991 ms 87800 KB Output is correct
20 Correct 977 ms 88808 KB Output is correct
21 Correct 981 ms 88908 KB Output is correct
22 Correct 993 ms 88816 KB Output is correct
23 Correct 840 ms 88748 KB Output is correct
24 Correct 78 ms 14268 KB Output is correct
25 Correct 77 ms 14268 KB Output is correct
26 Correct 70 ms 14012 KB Output is correct
27 Correct 77 ms 13952 KB Output is correct
28 Correct 71 ms 14012 KB Output is correct
29 Correct 63 ms 13928 KB Output is correct
30 Correct 62 ms 13764 KB Output is correct
31 Correct 66 ms 13932 KB Output is correct
32 Correct 33 ms 11312 KB Output is correct
33 Correct 63 ms 13760 KB Output is correct
34 Correct 179 ms 23988 KB Output is correct
35 Correct 175 ms 23908 KB Output is correct
36 Correct 161 ms 23740 KB Output is correct
37 Correct 163 ms 23732 KB Output is correct
38 Correct 172 ms 23784 KB Output is correct
39 Correct 133 ms 22964 KB Output is correct
40 Correct 131 ms 22972 KB Output is correct
41 Correct 144 ms 23224 KB Output is correct
42 Correct 151 ms 23220 KB Output is correct
43 Correct 152 ms 23220 KB Output is correct
44 Correct 152 ms 23476 KB Output is correct
45 Correct 143 ms 23240 KB Output is correct
46 Correct 144 ms 23372 KB Output is correct
47 Correct 192 ms 23476 KB Output is correct
48 Correct 143 ms 23324 KB Output is correct
49 Correct 122 ms 22968 KB Output is correct
50 Correct 126 ms 23132 KB Output is correct
51 Correct 123 ms 22776 KB Output is correct
52 Correct 129 ms 22852 KB Output is correct
53 Correct 150 ms 23024 KB Output is correct
54 Correct 131 ms 22200 KB Output is correct
55 Correct 107 ms 18684 KB Output is correct
56 Correct 127 ms 21676 KB Output is correct
57 Correct 1063 ms 89512 KB Output is correct
58 Correct 977 ms 89544 KB Output is correct
59 Correct 1002 ms 89576 KB Output is correct
60 Correct 983 ms 89412 KB Output is correct
61 Correct 1074 ms 89468 KB Output is correct
62 Correct 989 ms 89508 KB Output is correct
63 Correct 691 ms 87456 KB Output is correct
64 Correct 695 ms 87644 KB Output is correct
65 Correct 800 ms 89360 KB Output is correct
66 Correct 830 ms 89416 KB Output is correct
67 Correct 889 ms 89252 KB Output is correct
68 Correct 827 ms 89596 KB Output is correct
69 Correct 826 ms 89424 KB Output is correct
70 Correct 853 ms 89496 KB Output is correct
71 Correct 853 ms 89384 KB Output is correct
72 Correct 766 ms 89508 KB Output is correct
73 Correct 819 ms 90232 KB Output is correct
74 Correct 703 ms 91000 KB Output is correct
75 Correct 715 ms 90016 KB Output is correct
76 Correct 741 ms 90016 KB Output is correct
77 Correct 719 ms 90056 KB Output is correct
78 Correct 791 ms 83364 KB Output is correct
79 Correct 506 ms 68352 KB Output is correct
80 Correct 764 ms 82216 KB Output is correct