Submission #993237

# Submission time Handle Problem Language Result Execution time Memory
993237 2024-06-05T12:57:36 Z serkanrashid Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
0 / 100
1129 ms 123000 KB
#include <bits/stdc++.h>
#define endl "\n"

using namespace std;

struct qqq
{
    long long l,k,num;
    qqq(){}
    qqq(long long li, long long ki, long long ni)
    {
        l = li;
        k = ki;
        num = ni;
    }
};

const long long maxn = 1e6+5;

long long n,m,w[maxn];
pair<long long,long long> inv[maxn];
vector<qqq> q[maxn];

long long ans[maxn],tree[4*maxn];
long long ql,qr,val;

void make_bigidx()
{
    w[0] = 1e9+1;
    stack<long long>s1;
    s1.push(0);
    for(long long i = 1; i <= n; i++)
    {
        while(!s1.empty()&&w[s1.top()]<w[i]) s1.pop();
        inv[i].first = w[i] + w[s1.top()];
        inv[i].second = s1.top();
        s1.push(i);
    }
}

void read()
{
    cin >> n >> m;
    for(long long i = 1; i <= n; i++) cin >> w[i];

    make_bigidx();

    long long l,r,k;
    for(long long i = 1; i <= m; i++)
    {
        cin >> l >> r >> k;
        q[r].push_back({l,k,i});
    }
}

void update(long long v, long long l, long long r)
{
    if(r<ql||qr<l||l>r) return;
    if(ql<=l&&r<=qr)
    {
        tree[v] = max(tree[v],val);
        return;
    }
    long long mid = (l+r)/2;
    update(v*2+0,l,mid+0);
    update(v*2+1,mid+1,r);
    tree[v] = max(tree[v*2+0],tree[v*2+1]);
}

long long query(long long v, long long l, long long r)
{
    if(r<ql||qr<l||l>r) return 0;
    if(ql<=l&&r<=qr)return tree[v];
    long long mid = (l+r)/2;
    return max(query(v*2+0,l,mid+0),query(v*2+1,mid+1,r));
}

void solve()
{
    for(long long i = 1; i <= n; i++)
    {
        if(inv[i].second != 0)
        {
            ql = qr = inv[i].second;
            val = inv[i].first;
            update(1,1,n);
        }
        for(qqq nb : q[i])
        {
            ql = nb.l;
            qr = i;
            ans[nb.num] = (nb.k >= query(1,1,n));
        }
    }
    for(long long i = 1; i <= m; i++) cout << ans[i] << endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	read();
	solve();
return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 31068 KB Output is correct
2 Correct 4 ms 31064 KB Output is correct
3 Correct 6 ms 31276 KB Output is correct
4 Correct 6 ms 31068 KB Output is correct
5 Correct 5 ms 31068 KB Output is correct
6 Correct 5 ms 31068 KB Output is correct
7 Correct 5 ms 31200 KB Output is correct
8 Correct 5 ms 31064 KB Output is correct
9 Correct 7 ms 31068 KB Output is correct
10 Incorrect 6 ms 31068 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 31068 KB Output is correct
2 Correct 4 ms 31064 KB Output is correct
3 Correct 6 ms 31276 KB Output is correct
4 Correct 6 ms 31068 KB Output is correct
5 Correct 5 ms 31068 KB Output is correct
6 Correct 5 ms 31068 KB Output is correct
7 Correct 5 ms 31200 KB Output is correct
8 Correct 5 ms 31064 KB Output is correct
9 Correct 7 ms 31068 KB Output is correct
10 Incorrect 6 ms 31068 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1129 ms 122444 KB Output is correct
2 Correct 1025 ms 122968 KB Output is correct
3 Correct 1040 ms 123000 KB Output is correct
4 Correct 1058 ms 122952 KB Output is correct
5 Incorrect 823 ms 106068 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 72 ms 38736 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 31068 KB Output is correct
2 Correct 4 ms 31064 KB Output is correct
3 Correct 6 ms 31276 KB Output is correct
4 Correct 6 ms 31068 KB Output is correct
5 Correct 5 ms 31068 KB Output is correct
6 Correct 5 ms 31068 KB Output is correct
7 Correct 5 ms 31200 KB Output is correct
8 Correct 5 ms 31064 KB Output is correct
9 Correct 7 ms 31068 KB Output is correct
10 Incorrect 6 ms 31068 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 31068 KB Output is correct
2 Correct 4 ms 31064 KB Output is correct
3 Correct 6 ms 31276 KB Output is correct
4 Correct 6 ms 31068 KB Output is correct
5 Correct 5 ms 31068 KB Output is correct
6 Correct 5 ms 31068 KB Output is correct
7 Correct 5 ms 31200 KB Output is correct
8 Correct 5 ms 31064 KB Output is correct
9 Correct 7 ms 31068 KB Output is correct
10 Incorrect 6 ms 31068 KB Output isn't correct
11 Halted 0 ms 0 KB -