Submission #168502

# Submission time Handle Problem Language Result Execution time Memory
168502 2019-12-13T11:36:04 Z IldarKA Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
64 / 100
3000 ms 69760 KB
#include <bits/stdc++.h>

using namespace std;
bool ans[1000001];
int n, m, a[1000001], t[4000001];
vector < int > inv[1000001];
stack < int > s;
vector < pair < pair < int, int >, pair < int, int > > >  q;
void upd(int v, int tl, int tr, int pos, int val){
    if(tl == tr){
        t[v] = max(t[v], val);
        return;
    }
    int mid = (tl + tr) / 2;
    if(mid >= pos){
        upd(v + v, tl, mid, pos, val);
    }
    else{
        upd(v + 1 + v, mid + 1, tr, pos, val);
    }
    t[v] = max(t[v + v], t[v + 1 + v]);
}
int get(int v, int tl, int tr, int l, int r){
    if(l > r){
        return 0;
    }
    if(l == tl && tr == r){
        return t[v];
    }
    int mid = (tl + tr) / 2;
    return max(get(v + v, tl, mid, l, min(r, mid)), get(v + 1 + v, mid + 1, tr, max(l, mid + 1), r));
}
int main(){
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    for(int i = n; i >= 1; i--){
        while(!s.empty() && a[s.top()] < a[i]){
            inv[i].push_back(s.top());
            s.pop();
        }
        s.push(i);
    }
    for(int i = 1; i <= m; i++){
        int l, r, k;
        cin >> l >> r >> k;
        q.push_back({{l, r}, {k, i}});
    }
    sort(q.begin(), q.end());
    reverse(q.begin(), q.end());
    int l = n;
    for(int i = 0; i < m; i++){
        while(q[i].first.first <= l){
            for(auto to : inv[l]){
                upd(1, 1, n, to, a[to] + a[l]);
            }
            l--;
        }
        ans[q[i].second.second] = (get(1, 1, n, 1, q[i].first.second) <= q[i].second.first);
    }
    for(int i = 1; i <= m; i++){
        cout << ans[i] << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 24 ms 23928 KB Output is correct
4 Correct 23 ms 23800 KB Output is correct
5 Correct 23 ms 23804 KB Output is correct
6 Correct 25 ms 23800 KB Output is correct
7 Correct 25 ms 23928 KB Output is correct
8 Correct 24 ms 23800 KB Output is correct
9 Correct 24 ms 23800 KB Output is correct
10 Correct 24 ms 23916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 24 ms 23928 KB Output is correct
4 Correct 23 ms 23800 KB Output is correct
5 Correct 23 ms 23804 KB Output is correct
6 Correct 25 ms 23800 KB Output is correct
7 Correct 25 ms 23928 KB Output is correct
8 Correct 24 ms 23800 KB Output is correct
9 Correct 24 ms 23800 KB Output is correct
10 Correct 24 ms 23916 KB Output is correct
11 Correct 30 ms 24056 KB Output is correct
12 Correct 33 ms 24184 KB Output is correct
13 Correct 34 ms 24184 KB Output is correct
14 Correct 39 ms 24312 KB Output is correct
15 Correct 38 ms 24316 KB Output is correct
16 Correct 35 ms 24260 KB Output is correct
17 Correct 33 ms 24184 KB Output is correct
18 Correct 33 ms 24312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3041 ms 69760 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 266 ms 29540 KB Output is correct
2 Correct 267 ms 29668 KB Output is correct
3 Correct 249 ms 27496 KB Output is correct
4 Correct 241 ms 27644 KB Output is correct
5 Correct 243 ms 27500 KB Output is correct
6 Correct 232 ms 27468 KB Output is correct
7 Correct 239 ms 27496 KB Output is correct
8 Correct 228 ms 28268 KB Output is correct
9 Correct 278 ms 26780 KB Output is correct
10 Correct 234 ms 28364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 24 ms 23928 KB Output is correct
4 Correct 23 ms 23800 KB Output is correct
5 Correct 23 ms 23804 KB Output is correct
6 Correct 25 ms 23800 KB Output is correct
7 Correct 25 ms 23928 KB Output is correct
8 Correct 24 ms 23800 KB Output is correct
9 Correct 24 ms 23800 KB Output is correct
10 Correct 24 ms 23916 KB Output is correct
11 Correct 30 ms 24056 KB Output is correct
12 Correct 33 ms 24184 KB Output is correct
13 Correct 34 ms 24184 KB Output is correct
14 Correct 39 ms 24312 KB Output is correct
15 Correct 38 ms 24316 KB Output is correct
16 Correct 35 ms 24260 KB Output is correct
17 Correct 33 ms 24184 KB Output is correct
18 Correct 33 ms 24312 KB Output is correct
19 Correct 675 ms 37292 KB Output is correct
20 Correct 679 ms 36184 KB Output is correct
21 Correct 667 ms 38084 KB Output is correct
22 Correct 670 ms 37712 KB Output is correct
23 Correct 663 ms 38340 KB Output is correct
24 Correct 605 ms 33764 KB Output is correct
25 Correct 606 ms 33692 KB Output is correct
26 Correct 635 ms 34032 KB Output is correct
27 Correct 621 ms 33808 KB Output is correct
28 Correct 621 ms 34000 KB Output is correct
29 Correct 623 ms 34644 KB Output is correct
30 Correct 625 ms 35804 KB Output is correct
31 Correct 624 ms 35988 KB Output is correct
32 Correct 625 ms 35944 KB Output is correct
33 Correct 623 ms 35884 KB Output is correct
34 Correct 605 ms 35624 KB Output is correct
35 Correct 602 ms 35564 KB Output is correct
36 Correct 587 ms 35316 KB Output is correct
37 Correct 590 ms 35320 KB Output is correct
38 Correct 597 ms 35556 KB Output is correct
39 Correct 566 ms 36024 KB Output is correct
40 Correct 467 ms 33504 KB Output is correct
41 Correct 518 ms 35256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 24 ms 23928 KB Output is correct
4 Correct 23 ms 23800 KB Output is correct
5 Correct 23 ms 23804 KB Output is correct
6 Correct 25 ms 23800 KB Output is correct
7 Correct 25 ms 23928 KB Output is correct
8 Correct 24 ms 23800 KB Output is correct
9 Correct 24 ms 23800 KB Output is correct
10 Correct 24 ms 23916 KB Output is correct
11 Correct 30 ms 24056 KB Output is correct
12 Correct 33 ms 24184 KB Output is correct
13 Correct 34 ms 24184 KB Output is correct
14 Correct 39 ms 24312 KB Output is correct
15 Correct 38 ms 24316 KB Output is correct
16 Correct 35 ms 24260 KB Output is correct
17 Correct 33 ms 24184 KB Output is correct
18 Correct 33 ms 24312 KB Output is correct
19 Execution timed out 3041 ms 69760 KB Time limit exceeded
20 Halted 0 ms 0 KB -