답안 #993227

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
993227 2024-06-05T12:56:15 Z serkanrashid Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
0 / 100
938 ms 105300 KB
#include <bits/stdc++.h>
#define endl "\n"

using namespace std;

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

const int maxn = 1e6+5;

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

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

void make_bigidx()
{
    w[0] = 1e9+1;
    stack<int>s1;
    s1.push(0);
    for(int 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(int i = 1; i <= n; i++) cin >> w[i];

    make_bigidx();

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

void update(int v, int l, int r)
{
    if(r<ql||qr<l||l>r) return;
    if(ql<=l&&r<=qr)
    {
        tree[v] = max(tree[v],val);
        return;
    }
    int 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]);
}

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

void solve()
{
    for(int 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(int i = 1; i <= m; i++) cout << ans[i] << endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	read();
	solve();
return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 29020 KB Output is correct
2 Correct 5 ms 29192 KB Output is correct
3 Correct 5 ms 29020 KB Output is correct
4 Correct 5 ms 29020 KB Output is correct
5 Correct 4 ms 29140 KB Output is correct
6 Correct 5 ms 29020 KB Output is correct
7 Correct 5 ms 29020 KB Output is correct
8 Correct 5 ms 29020 KB Output is correct
9 Correct 4 ms 29020 KB Output is correct
10 Incorrect 4 ms 29132 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 29020 KB Output is correct
2 Correct 5 ms 29192 KB Output is correct
3 Correct 5 ms 29020 KB Output is correct
4 Correct 5 ms 29020 KB Output is correct
5 Correct 4 ms 29140 KB Output is correct
6 Correct 5 ms 29020 KB Output is correct
7 Correct 5 ms 29020 KB Output is correct
8 Correct 5 ms 29020 KB Output is correct
9 Correct 4 ms 29020 KB Output is correct
10 Incorrect 4 ms 29132 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 936 ms 104340 KB Output is correct
2 Correct 920 ms 105296 KB Output is correct
3 Correct 901 ms 105192 KB Output is correct
4 Correct 938 ms 105300 KB Output is correct
5 Incorrect 761 ms 105040 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 69 ms 36436 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 29020 KB Output is correct
2 Correct 5 ms 29192 KB Output is correct
3 Correct 5 ms 29020 KB Output is correct
4 Correct 5 ms 29020 KB Output is correct
5 Correct 4 ms 29140 KB Output is correct
6 Correct 5 ms 29020 KB Output is correct
7 Correct 5 ms 29020 KB Output is correct
8 Correct 5 ms 29020 KB Output is correct
9 Correct 4 ms 29020 KB Output is correct
10 Incorrect 4 ms 29132 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 29020 KB Output is correct
2 Correct 5 ms 29192 KB Output is correct
3 Correct 5 ms 29020 KB Output is correct
4 Correct 5 ms 29020 KB Output is correct
5 Correct 4 ms 29140 KB Output is correct
6 Correct 5 ms 29020 KB Output is correct
7 Correct 5 ms 29020 KB Output is correct
8 Correct 5 ms 29020 KB Output is correct
9 Correct 4 ms 29020 KB Output is correct
10 Incorrect 4 ms 29132 KB Output isn't correct
11 Halted 0 ms 0 KB -