Submission #533113

# Submission time Handle Problem Language Result Execution time Memory
533113 2022-03-04T21:02:40 Z iliccmarko Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
64 / 100
3000 ms 103180 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define INF 1000000000
#define LINF 10000000000000000LL
#define pb push_back
#define all(x) x.begin(), x.end()
#define len(s) (int)s.size()
#define test_case { int t; cin>>t; while(t--)solve(); }
#define single_case solve();
#define line cerr<<"----------"<<endl;
#define ios { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);  }
#define mod 1000000007LL
const int N = 1e6 + 5;
int seg[4*N];
int a[N], n, m;
int k[N];
int l[N], r[N];
int ans[N];
vector<int> upit[N];
stack<pair<int, int> > s;
pair<int, int> veci[N];

void update(int node, int l, int r, int pos, int x)
{
    if(l==r)
    {
        seg[node] = max(seg[node], x);
        return;
    }
    int mid = (l+r)/2;
    if(pos>mid) update(node*2+2, mid+1, r, pos, x);
    else update(node*2+1, l, mid, pos, x);
    seg[node] = max(seg[node*2+1], seg[node*2+2]);
}

int get(int node, int l, int r, int i, int j)
{
    if(i>r||j<l) return 0;
    if(i>=l&&j<=r) return seg[node];
    int mid = (i+j)/2;
    return max(get(node*2+1, l, r, i, mid), get(node*2+2, l, r, mid+1, j));
}


int main()
{
    cin>>n>>m;
    for(int i = 1;i<=n;i++) cin>>a[i];
    for(int i = 1;i<=m;i++) cin>>l[i]>>r[i]>>k[i], upit[r[i]].pb(i);
    s.push(make_pair(INF+2, 0));
    for(int i = 1;i<=n;i++)
    {
        while(a[i]>=s.top().first)
        {
            s.pop();
        }
        veci[i] = s.top();
        s.push(make_pair(a[i], i));
    }
    for(int i = 1;i<=n;i++)
    {
        if(veci[i].first!=INF+2)
        {
            update(0, 1, n, veci[i].second, veci[i].first+a[i]);
        }
        for(int x : upit[i])
        {
            int le = l[x];
            int ri = r[x];
            int w = get(0, le, ri, 1, n);
            cerr<<x<<' '<<len(upit[i]);
            if(w<=k[x]) ans[x] = 1;
        }
        cerr<<' '<<i<<endl;
    }

    for(int i = 1;i<=m;i++) cout<<ans[i]<<endl;



    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23788 KB Output is correct
2 Correct 12 ms 23856 KB Output is correct
3 Correct 14 ms 23796 KB Output is correct
4 Correct 13 ms 23744 KB Output is correct
5 Correct 13 ms 23756 KB Output is correct
6 Correct 16 ms 23884 KB Output is correct
7 Correct 15 ms 23800 KB Output is correct
8 Correct 16 ms 23756 KB Output is correct
9 Correct 15 ms 23852 KB Output is correct
10 Correct 16 ms 23876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23788 KB Output is correct
2 Correct 12 ms 23856 KB Output is correct
3 Correct 14 ms 23796 KB Output is correct
4 Correct 13 ms 23744 KB Output is correct
5 Correct 13 ms 23756 KB Output is correct
6 Correct 16 ms 23884 KB Output is correct
7 Correct 15 ms 23800 KB Output is correct
8 Correct 16 ms 23756 KB Output is correct
9 Correct 15 ms 23852 KB Output is correct
10 Correct 16 ms 23876 KB Output is correct
11 Correct 31 ms 24012 KB Output is correct
12 Correct 43 ms 24148 KB Output is correct
13 Correct 44 ms 24148 KB Output is correct
14 Correct 70 ms 24204 KB Output is correct
15 Correct 58 ms 24264 KB Output is correct
16 Correct 51 ms 24140 KB Output is correct
17 Correct 48 ms 24148 KB Output is correct
18 Correct 50 ms 24140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3036 ms 103180 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 826 ms 32652 KB Output is correct
2 Correct 815 ms 31976 KB Output is correct
3 Correct 827 ms 31516 KB Output is correct
4 Correct 831 ms 31660 KB Output is correct
5 Correct 816 ms 31716 KB Output is correct
6 Correct 812 ms 30276 KB Output is correct
7 Correct 867 ms 30324 KB Output is correct
8 Correct 825 ms 31416 KB Output is correct
9 Correct 433 ms 28460 KB Output is correct
10 Correct 809 ms 31628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23788 KB Output is correct
2 Correct 12 ms 23856 KB Output is correct
3 Correct 14 ms 23796 KB Output is correct
4 Correct 13 ms 23744 KB Output is correct
5 Correct 13 ms 23756 KB Output is correct
6 Correct 16 ms 23884 KB Output is correct
7 Correct 15 ms 23800 KB Output is correct
8 Correct 16 ms 23756 KB Output is correct
9 Correct 15 ms 23852 KB Output is correct
10 Correct 16 ms 23876 KB Output is correct
11 Correct 31 ms 24012 KB Output is correct
12 Correct 43 ms 24148 KB Output is correct
13 Correct 44 ms 24148 KB Output is correct
14 Correct 70 ms 24204 KB Output is correct
15 Correct 58 ms 24264 KB Output is correct
16 Correct 51 ms 24140 KB Output is correct
17 Correct 48 ms 24148 KB Output is correct
18 Correct 50 ms 24140 KB Output is correct
19 Correct 1761 ms 44556 KB Output is correct
20 Correct 1861 ms 44612 KB Output is correct
21 Correct 1699 ms 42868 KB Output is correct
22 Correct 1718 ms 42756 KB Output is correct
23 Correct 1705 ms 42912 KB Output is correct
24 Correct 1674 ms 40528 KB Output is correct
25 Correct 1671 ms 40628 KB Output is correct
26 Correct 1778 ms 41292 KB Output is correct
27 Correct 1698 ms 41264 KB Output is correct
28 Correct 1699 ms 41480 KB Output is correct
29 Correct 1729 ms 42516 KB Output is correct
30 Correct 1728 ms 42412 KB Output is correct
31 Correct 1690 ms 42624 KB Output is correct
32 Correct 1702 ms 42532 KB Output is correct
33 Correct 1696 ms 42440 KB Output is correct
34 Correct 1641 ms 40532 KB Output is correct
35 Correct 1692 ms 40512 KB Output is correct
36 Correct 1677 ms 40204 KB Output is correct
37 Correct 1657 ms 40324 KB Output is correct
38 Correct 1663 ms 40432 KB Output is correct
39 Correct 1680 ms 41672 KB Output is correct
40 Correct 1377 ms 39024 KB Output is correct
41 Correct 1643 ms 40712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23788 KB Output is correct
2 Correct 12 ms 23856 KB Output is correct
3 Correct 14 ms 23796 KB Output is correct
4 Correct 13 ms 23744 KB Output is correct
5 Correct 13 ms 23756 KB Output is correct
6 Correct 16 ms 23884 KB Output is correct
7 Correct 15 ms 23800 KB Output is correct
8 Correct 16 ms 23756 KB Output is correct
9 Correct 15 ms 23852 KB Output is correct
10 Correct 16 ms 23876 KB Output is correct
11 Correct 31 ms 24012 KB Output is correct
12 Correct 43 ms 24148 KB Output is correct
13 Correct 44 ms 24148 KB Output is correct
14 Correct 70 ms 24204 KB Output is correct
15 Correct 58 ms 24264 KB Output is correct
16 Correct 51 ms 24140 KB Output is correct
17 Correct 48 ms 24148 KB Output is correct
18 Correct 50 ms 24140 KB Output is correct
19 Execution timed out 3036 ms 103180 KB Time limit exceeded
20 Halted 0 ms 0 KB -