Submission #398989

# Submission time Handle Problem Language Result Execution time Memory
398989 2021-05-05T00:55:55 Z definitelynotmee Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++
100 / 100
1689 ms 71660 KB
#include <bits/stdc++.h>
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll INFL = (1LL<<62)-1;
const int INF = (1<<30)-1;
const int MAXN = 1000001;

struct resp{
    int l, r, v;
};
struct queries{
    int l, r, limit, v;
};

int tree[4*MAXN];

void update(int id, int l, int r, int q, int val){
    if(l > q || r < q)
        return;
    if(l == q && r == q){
        tree[id] = max(tree[id],val);
        return;
    }
    int e = id*2+1;
    int d = id*2+2;
    int m = (l+r)>>1;
    update(e,l,m,q,val);
    update(d,m+1,r,q,val);
    tree[id] = max(tree[e],tree[d]);
}

int query(int id, int l, int r, int ql, int qr){
    if(l > qr || r < ql)
        return 0;
    if(ql<=l && r <= qr){

        return tree[id];
    }
    int e = id*2+1;
    int d = id*2+2;
    int m = (l+r)>>1;
    return max(query(e,l,m,ql,qr), query(d,m+1,r,ql,qr));
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n, m;
    cin >> n >> m;
    vector<int> v(n);
    vector<queries> q(m);
    for(int i = 0; i < n; i++) 
        cin >> v[i];
    for(int i = 0; i < m; i++)
        cin >> q[i].l >> q[i].r >> q[i].limit, q[i].l--, q[i].r--;

    vector<int> orderq(m);

    iota(orderq.begin(), orderq.end(), 0); 
    sort(orderq.begin(),orderq.end(), [&](int a, int b){
        return q[a].r < q[b].r;
    });

    vector<int> j(n,-1); // primeiro indice maior ou igual a v[i] à esquerda

    for(int i = 1; i < n; i++){
        j[i] = i-1;
        while(j[i] >= 0 && v[j[i]] <= v[i])
            j[i] = j[j[i]];

    }

    int ptr = 0;
    for(int i = 0; i < m; i++){
        queries &cur = q[orderq[i]];
        while(ptr <= cur.r){
            if(j[ptr]!=-1)
                update(0,0,n-1,j[ptr],v[ptr]+v[j[ptr]]);
            ptr++;
        }
        cur.v = (query(0,0,n-1, cur.l, cur.r) <= cur.limit);
    }
    for(queries i : q)
        cout << i.v << '\n';
    return 0;

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 4 ms 588 KB Output is correct
13 Correct 4 ms 504 KB Output is correct
14 Correct 6 ms 588 KB Output is correct
15 Correct 6 ms 588 KB Output is correct
16 Correct 5 ms 588 KB Output is correct
17 Correct 4 ms 460 KB Output is correct
18 Correct 4 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1655 ms 37888 KB Output is correct
2 Correct 1630 ms 37888 KB Output is correct
3 Correct 1657 ms 37840 KB Output is correct
4 Correct 1666 ms 37968 KB Output is correct
5 Correct 1269 ms 29700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 119 ms 5188 KB Output is correct
2 Correct 119 ms 5208 KB Output is correct
3 Correct 93 ms 4200 KB Output is correct
4 Correct 93 ms 4196 KB Output is correct
5 Correct 93 ms 4208 KB Output is correct
6 Correct 85 ms 4316 KB Output is correct
7 Correct 85 ms 4240 KB Output is correct
8 Correct 92 ms 4248 KB Output is correct
9 Correct 49 ms 3424 KB Output is correct
10 Correct 90 ms 4292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 4 ms 588 KB Output is correct
13 Correct 4 ms 504 KB Output is correct
14 Correct 6 ms 588 KB Output is correct
15 Correct 6 ms 588 KB Output is correct
16 Correct 5 ms 588 KB Output is correct
17 Correct 4 ms 460 KB Output is correct
18 Correct 4 ms 460 KB Output is correct
19 Correct 279 ms 9256 KB Output is correct
20 Correct 279 ms 9264 KB Output is correct
21 Correct 261 ms 9228 KB Output is correct
22 Correct 262 ms 9232 KB Output is correct
23 Correct 260 ms 9156 KB Output is correct
24 Correct 204 ms 7288 KB Output is correct
25 Correct 200 ms 7188 KB Output is correct
26 Correct 212 ms 7108 KB Output is correct
27 Correct 214 ms 7224 KB Output is correct
28 Correct 211 ms 7188 KB Output is correct
29 Correct 217 ms 7176 KB Output is correct
30 Correct 220 ms 7324 KB Output is correct
31 Correct 220 ms 7192 KB Output is correct
32 Correct 220 ms 7236 KB Output is correct
33 Correct 212 ms 7216 KB Output is correct
34 Correct 192 ms 7236 KB Output is correct
35 Correct 186 ms 7256 KB Output is correct
36 Correct 184 ms 7236 KB Output is correct
37 Correct 185 ms 7152 KB Output is correct
38 Correct 189 ms 7236 KB Output is correct
39 Correct 202 ms 7952 KB Output is correct
40 Correct 154 ms 6724 KB Output is correct
41 Correct 196 ms 7256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 4 ms 588 KB Output is correct
13 Correct 4 ms 504 KB Output is correct
14 Correct 6 ms 588 KB Output is correct
15 Correct 6 ms 588 KB Output is correct
16 Correct 5 ms 588 KB Output is correct
17 Correct 4 ms 460 KB Output is correct
18 Correct 4 ms 460 KB Output is correct
19 Correct 1655 ms 37888 KB Output is correct
20 Correct 1630 ms 37888 KB Output is correct
21 Correct 1657 ms 37840 KB Output is correct
22 Correct 1666 ms 37968 KB Output is correct
23 Correct 1269 ms 29700 KB Output is correct
24 Correct 119 ms 5188 KB Output is correct
25 Correct 119 ms 5208 KB Output is correct
26 Correct 93 ms 4200 KB Output is correct
27 Correct 93 ms 4196 KB Output is correct
28 Correct 93 ms 4208 KB Output is correct
29 Correct 85 ms 4316 KB Output is correct
30 Correct 85 ms 4240 KB Output is correct
31 Correct 92 ms 4248 KB Output is correct
32 Correct 49 ms 3424 KB Output is correct
33 Correct 90 ms 4292 KB Output is correct
34 Correct 279 ms 9256 KB Output is correct
35 Correct 279 ms 9264 KB Output is correct
36 Correct 261 ms 9228 KB Output is correct
37 Correct 262 ms 9232 KB Output is correct
38 Correct 260 ms 9156 KB Output is correct
39 Correct 204 ms 7288 KB Output is correct
40 Correct 200 ms 7188 KB Output is correct
41 Correct 212 ms 7108 KB Output is correct
42 Correct 214 ms 7224 KB Output is correct
43 Correct 211 ms 7188 KB Output is correct
44 Correct 217 ms 7176 KB Output is correct
45 Correct 220 ms 7324 KB Output is correct
46 Correct 220 ms 7192 KB Output is correct
47 Correct 220 ms 7236 KB Output is correct
48 Correct 212 ms 7216 KB Output is correct
49 Correct 192 ms 7236 KB Output is correct
50 Correct 186 ms 7256 KB Output is correct
51 Correct 184 ms 7236 KB Output is correct
52 Correct 185 ms 7152 KB Output is correct
53 Correct 189 ms 7236 KB Output is correct
54 Correct 202 ms 7952 KB Output is correct
55 Correct 154 ms 6724 KB Output is correct
56 Correct 196 ms 7256 KB Output is correct
57 Correct 1689 ms 37932 KB Output is correct
58 Correct 1635 ms 71528 KB Output is correct
59 Correct 1639 ms 71444 KB Output is correct
60 Correct 1599 ms 71660 KB Output is correct
61 Correct 1661 ms 71496 KB Output is correct
62 Correct 1647 ms 71392 KB Output is correct
63 Correct 1197 ms 61576 KB Output is correct
64 Correct 1185 ms 61412 KB Output is correct
65 Correct 1269 ms 63304 KB Output is correct
66 Correct 1289 ms 63168 KB Output is correct
67 Correct 1284 ms 63300 KB Output is correct
68 Correct 1283 ms 63300 KB Output is correct
69 Correct 1325 ms 63332 KB Output is correct
70 Correct 1305 ms 63248 KB Output is correct
71 Correct 1322 ms 63360 KB Output is correct
72 Correct 1301 ms 63248 KB Output is correct
73 Correct 1082 ms 59928 KB Output is correct
74 Correct 1125 ms 60776 KB Output is correct
75 Correct 1082 ms 59832 KB Output is correct
76 Correct 1090 ms 59788 KB Output is correct
77 Correct 1093 ms 59796 KB Output is correct
78 Correct 1190 ms 59880 KB Output is correct
79 Correct 862 ms 48628 KB Output is correct
80 Correct 1219 ms 54284 KB Output is correct