답안 #152612

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
152612 2019-09-08T15:06:12 Z leatherman Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
0 / 100
323 ms 68644 KB
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#define ll int
#define ld long double
#define endl "\n"
#define fi first
#define se second
#define y1 sadjfskldf
#define PB push_back
#define sqr(x) ((x) * (x))
#define all(x) x.begin(), x.end()
using namespace std;
using namespace __gnu_pbds;
mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count());

const ll N = 2e5 + 200;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct node
{
    ll val;
    node *l,*r;
    node() : val(0), l(nullptr), r(nullptr){}
};
node *root[N],*mb;
ll n,Q,a[N],x,pos;
vector<pair<ll, ll> > v;
void build(node *v,ll tl,ll tr)
{
    if(tl == tr) return;
    ll tm = (tl + tr) / 2;
    v -> l = new node();
    v -> r = new node();
    build(v -> l, tl, tm);
    build(v -> r, tm + 1, tr);
}
void upd(node *old, node *now,ll tl,ll tr,ll pos,ll val)
{
    if(tl == tr)
    {
        now -> val = val;
        return;
    }
    now -> l = old -> l;
    now -> r = old -> r;
    ll tm = (tl + tr) / 2;
    if(pos <= tm)
    {
        now -> l = new node();
        upd(old -> l, now -> l, tl, tm, pos, val);
    } else
    {
        now -> r= new node();
        upd(old -> r, now -> r, tm + 1, tr, pos, val);
    }
    now -> val = (now -> l) -> val + (now -> r) -> val;
}
ll get(node *v,ll tl,ll tr,ll l,ll r)
{
    if(l > r) return 0;
    if(tl == l && tr == r) return v -> val;
    ll tm = (tl + tr) / 2;
    return max(get(v -> l, tl, tm, l, min(r, tm)), get(v -> r, tm + 1, tr, max(l, tm + 1), r));
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>Q;
    for(int i = 1; i <= n; i++) cin>>a[i];
    root[n + 1] = new node();
    build(root[n + 1], 1, n);
    for(int i = n; i >= 1; i--)
    {
        x = a[i];
        root[i] = new node();
        root[i] -> val = root[i + 1] -> val;
        root[i] -> l = root[i + 1] -> l;
        root[i] -> r = root[i + 1] -> r;
        while(!v.empty() && v.back().fi < x)
        {
            pos = v.back().se;
            mb = new node();
            upd(root[i], mb, 1, n, pos, a[pos] + x);
            root[i] = mb;
            v.pop_back();
        }
        v.PB({x, i});
    }
    while(Q--)
    {
        ll l,r,k;
        cin>>l>>r>>k;
        x = get(root[l], 1, n, l, r);
        cout<<(x <= k)<<endl;
    }
    return 0;
}
/*
5 2
3 5 1 8 2
1 3 6
2 5 3
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 90 ms 11168 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 323 ms 68644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -