Submission #471677

# Submission time Handle Problem Language Result Execution time Memory
471677 2021-09-10T08:58:35 Z jeroenodb Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
2592 ms 112556 KB
#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x),end(x)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#define debug(a) cerr << "(" << #a << ": " << a << ")\n";
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int mxN = 1e5+1, oo = 1e9;
struct segtree {
    int ptwo;
    vector<ll> seg;
    segtree(){}
    ll& operator[](int i) {
        return seg[i+ptwo];
    }
    segtree(int nn) {
        ptwo=1;
        while(ptwo<nn) 
            ptwo*=2;
        seg.assign(ptwo*2,0);
    }
    auto query(int l, int r) {
        assert(l>=0 and l<ptwo and r >=0 and r<ptwo);
        l+=ptwo; r+=ptwo;
        ll res = -oo;
        while(l and l<=r) {
            if(l%2==1) res = max(res,seg[l++]);
            if(r%2==0) res = max(res,seg[r--]);
            l/=2; r/=2;
        }
        return res;
    }
    void update(int i, ll val) {
        assert(i>=0 and i<ptwo);
        i+=ptwo;
        seg[i] += val;
        for(i/=2;i>=1;i/=2) {
            seg[i] = max(seg[2*i],seg[2*i+1]);
        }
    }
};
int main() {
    int n,m; cin >> n >> m;
    struct query {
        int l,k,id;
    };
    vector<vector<query>> queries(n);
    vi w(n); for(auto& i : w) cin >> i;
    segtree seg(n);
    for(int i=0;i<m;++i) {
        int l,r,k; cin >> l >> r >> k,--l,--r;
        queries[r].push_back({l,k,i});
    }
    vi prv(n,-1), from(n,0),ans(m,-1);
    int active=-1;
    for(int i=0;i<n;++i) {
        prv[i]=i-1;
        while(prv[i]!=-1 and w[prv[i]]<=w[i]) prv[i] = prv[prv[i]];
        while(active<prv[i]) {
            ++active;
            seg.update(active,w[active]);
        }
        if(prv[i]!=-1) {
            int& before = from[prv[i]];
            if(w[i]>before) {
                seg.update(prv[i], w[i]-before);
                before=w[i];
            }
        }
        for(auto& q : queries[i]) {
            ans[q.id]=seg.query(q.l, i)<=q.k;
        }
    }
    for(auto i : ans) {
        cout << i << '\n';
    }
}
# 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 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 272 KB Output is correct
9 Correct 2 ms 204 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 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 272 KB Output is correct
9 Correct 2 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 5 ms 332 KB Output is correct
12 Correct 7 ms 716 KB Output is correct
13 Correct 7 ms 588 KB Output is correct
14 Correct 10 ms 716 KB Output is correct
15 Correct 10 ms 712 KB Output is correct
16 Correct 10 ms 716 KB Output is correct
17 Correct 7 ms 588 KB Output is correct
18 Correct 7 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2401 ms 79572 KB Output is correct
2 Correct 2527 ms 112504 KB Output is correct
3 Correct 2459 ms 112328 KB Output is correct
4 Correct 2592 ms 112380 KB Output is correct
5 Correct 2318 ms 112384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 175 ms 8660 KB Output is correct
2 Correct 165 ms 8516 KB Output is correct
3 Correct 174 ms 8668 KB Output is correct
4 Correct 158 ms 8676 KB Output is correct
5 Correct 158 ms 8860 KB Output is correct
6 Correct 136 ms 8380 KB Output is correct
7 Correct 145 ms 8412 KB Output is correct
8 Correct 140 ms 8640 KB Output is correct
9 Correct 94 ms 2560 KB Output is correct
10 Correct 166 ms 8600 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 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 272 KB Output is correct
9 Correct 2 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 5 ms 332 KB Output is correct
12 Correct 7 ms 716 KB Output is correct
13 Correct 7 ms 588 KB Output is correct
14 Correct 10 ms 716 KB Output is correct
15 Correct 10 ms 712 KB Output is correct
16 Correct 10 ms 716 KB Output is correct
17 Correct 7 ms 588 KB Output is correct
18 Correct 7 ms 716 KB Output is correct
19 Correct 432 ms 17036 KB Output is correct
20 Correct 438 ms 17268 KB Output is correct
21 Correct 397 ms 16668 KB Output is correct
22 Correct 409 ms 16580 KB Output is correct
23 Correct 401 ms 16636 KB Output is correct
24 Correct 371 ms 16564 KB Output is correct
25 Correct 359 ms 16648 KB Output is correct
26 Correct 396 ms 16768 KB Output is correct
27 Correct 386 ms 16964 KB Output is correct
28 Correct 430 ms 16744 KB Output is correct
29 Correct 459 ms 17124 KB Output is correct
30 Correct 396 ms 17112 KB Output is correct
31 Correct 453 ms 17056 KB Output is correct
32 Correct 397 ms 17092 KB Output is correct
33 Correct 407 ms 17124 KB Output is correct
34 Correct 379 ms 16224 KB Output is correct
35 Correct 353 ms 16236 KB Output is correct
36 Correct 350 ms 16136 KB Output is correct
37 Correct 361 ms 16160 KB Output is correct
38 Correct 344 ms 16136 KB Output is correct
39 Correct 357 ms 16716 KB Output is correct
40 Correct 356 ms 11940 KB Output is correct
41 Correct 348 ms 16876 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 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 272 KB Output is correct
9 Correct 2 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 5 ms 332 KB Output is correct
12 Correct 7 ms 716 KB Output is correct
13 Correct 7 ms 588 KB Output is correct
14 Correct 10 ms 716 KB Output is correct
15 Correct 10 ms 712 KB Output is correct
16 Correct 10 ms 716 KB Output is correct
17 Correct 7 ms 588 KB Output is correct
18 Correct 7 ms 716 KB Output is correct
19 Correct 2401 ms 79572 KB Output is correct
20 Correct 2527 ms 112504 KB Output is correct
21 Correct 2459 ms 112328 KB Output is correct
22 Correct 2592 ms 112380 KB Output is correct
23 Correct 2318 ms 112384 KB Output is correct
24 Correct 175 ms 8660 KB Output is correct
25 Correct 165 ms 8516 KB Output is correct
26 Correct 174 ms 8668 KB Output is correct
27 Correct 158 ms 8676 KB Output is correct
28 Correct 158 ms 8860 KB Output is correct
29 Correct 136 ms 8380 KB Output is correct
30 Correct 145 ms 8412 KB Output is correct
31 Correct 140 ms 8640 KB Output is correct
32 Correct 94 ms 2560 KB Output is correct
33 Correct 166 ms 8600 KB Output is correct
34 Correct 432 ms 17036 KB Output is correct
35 Correct 438 ms 17268 KB Output is correct
36 Correct 397 ms 16668 KB Output is correct
37 Correct 409 ms 16580 KB Output is correct
38 Correct 401 ms 16636 KB Output is correct
39 Correct 371 ms 16564 KB Output is correct
40 Correct 359 ms 16648 KB Output is correct
41 Correct 396 ms 16768 KB Output is correct
42 Correct 386 ms 16964 KB Output is correct
43 Correct 430 ms 16744 KB Output is correct
44 Correct 459 ms 17124 KB Output is correct
45 Correct 396 ms 17112 KB Output is correct
46 Correct 453 ms 17056 KB Output is correct
47 Correct 397 ms 17092 KB Output is correct
48 Correct 407 ms 17124 KB Output is correct
49 Correct 379 ms 16224 KB Output is correct
50 Correct 353 ms 16236 KB Output is correct
51 Correct 350 ms 16136 KB Output is correct
52 Correct 361 ms 16160 KB Output is correct
53 Correct 344 ms 16136 KB Output is correct
54 Correct 357 ms 16716 KB Output is correct
55 Correct 356 ms 11940 KB Output is correct
56 Correct 348 ms 16876 KB Output is correct
57 Correct 2414 ms 95588 KB Output is correct
58 Correct 2427 ms 112504 KB Output is correct
59 Correct 2320 ms 111172 KB Output is correct
60 Correct 2440 ms 111032 KB Output is correct
61 Correct 2412 ms 111052 KB Output is correct
62 Correct 2308 ms 111108 KB Output is correct
63 Correct 1940 ms 107796 KB Output is correct
64 Correct 1807 ms 107984 KB Output is correct
65 Correct 2153 ms 110852 KB Output is correct
66 Correct 2142 ms 110852 KB Output is correct
67 Correct 2198 ms 110964 KB Output is correct
68 Correct 2235 ms 112556 KB Output is correct
69 Correct 2245 ms 95360 KB Output is correct
70 Correct 2240 ms 95040 KB Output is correct
71 Correct 2242 ms 95064 KB Output is correct
72 Correct 2245 ms 95248 KB Output is correct
73 Correct 1728 ms 103736 KB Output is correct
74 Correct 1768 ms 104716 KB Output is correct
75 Correct 1753 ms 103760 KB Output is correct
76 Correct 1813 ms 103876 KB Output is correct
77 Correct 1754 ms 103568 KB Output is correct
78 Correct 2035 ms 104780 KB Output is correct
79 Correct 1625 ms 72656 KB Output is correct
80 Correct 1877 ms 101660 KB Output is correct