답안 #153460

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
153460 2019-09-14T08:19:19 Z leatherman Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
0 / 100
3000 ms 137828 KB
#include <bits/stdc++.h>
 
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
 
#define ll long long
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) (x)*(x)
#define PB push_back
 
using namespace std;
typedef long double ld;
const ll MOD = 1e9 + 7;
const ll N = 1e6 + 200;
mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count());
vector<pair<ll, ll> > v;
vector<ll> of[N],q[N];
pair<ll, ll> b[N];
ll ans[N],t[4 * N],a[N],l,r,x,k,limit,n,Q;
void upd(ll v,ll tl,ll tr,ll pos,ll val)
{
    if(tl == tr)
    {
        t[v] = val;
        return;
    }
    ll tm = (tl + tr) / 2;
    if(pos <= tm) upd(2 * v, tl, tm, pos, val);
    else upd(2 * v + 1, tm + 1, tr, pos, val);
    t[v] = max(t[2 * v], t[2 * v + 1]);
}
ll get(ll v,ll tl,ll tr,ll l,ll r)
{
    if(l > r) return 0;
    if(tl == l && tr == r) return t[v];
    ll tm = (tl + tr) / 2;
    return max(get(2 * v, tl, tm, l, min(r, tm)), get(2 * v + 1, tm + 1, tr, max(l, tm + 1), r));
}
int main()
{
    ios_base::sync_with_stdio();cin.tie(0);cout.tie(0);
    cin>>n>>Q;
    for(int i = 1; i <= n; i++)
    {
        cin>>x;
        a[i] = x;
        while(!v.empty() && v.back().fi > x)
        {
            of[v.back().se].PB(i);
            v.pop_back();
        }
        v.PB({x, i});
    }
    for(int i = 1; i <= Q; i++)
    {
        cin>>l>>r>>k;
        b[i] = {r, k};
        q[l].PB(i);
    }
    limit = n;
    for(int l = n; l >= 1; l--) if(!q[l].empty())
    for(auto i : q[l])
    {
        r = b[i].fi;
        while(limit >= l)
        {
            for(auto j : of[limit]) upd(1, 1, n, limit, a[limit] + a[j]);
            limit--;
        }
        ans[i] = (get(1, 1, n, l, r) <= b[i].se);
    }
    for(int i = 1; i <= Q; i++) cout<<ans[i]<<endl;
    return 0;
 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 47352 KB Output is correct
2 Correct 44 ms 47356 KB Output is correct
3 Incorrect 46 ms 47352 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 47352 KB Output is correct
2 Correct 44 ms 47356 KB Output is correct
3 Incorrect 46 ms 47352 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3043 ms 137828 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 575 ms 58020 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 47352 KB Output is correct
2 Correct 44 ms 47356 KB Output is correct
3 Incorrect 46 ms 47352 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 47352 KB Output is correct
2 Correct 44 ms 47356 KB Output is correct
3 Incorrect 46 ms 47352 KB Output isn't correct
4 Halted 0 ms 0 KB -