Submission #151538

# Submission time Handle Problem Language Result Execution time Memory
151538 2019-09-03T14:03:57 Z andrew Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
3000 ms 29804 KB
#include <bits/stdc++.h>

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

#define fi first
#define se second
#define p_b push_back
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define all(x) x.begin(),x.end()
#define sqr(x) (x)*(x)
#define pw(x) (1ll << x)

using namespace std;
typedef int ll;
typedef long double ld;
const ll MAXN = 1123456;
const ll N = 1e6 + 5;
mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count());

template <typename T> void vout(T s){cout << s << endl;exit(0);}
vector<pair<ll, ll> > v;
pair<pair<ll, ll>, ll> b[N];
vector<ll> q;
ll t[4 * N],a[N],n,Q,limit,l,r,x,k,ans[N];
void upd(ll v,ll tl,ll tr,ll pos,ll val)
{
    if(tl == tr)
    {
        t[v] = val + a[tl];
        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));
}
void make(ll l,ll r)
{
    for(int i = r; i >= l; i--)
    {
        ll x = a[i],pos;
        while(!v.empty() && x > v.back().fi)
        {
            pos = v.back().se;
            upd(1, 1, n, pos, x);
            v.pop_back();
        }
        v.push_back({x, i});
    }
}
bool comp(ll i,ll j)
{
    return b[i].fi.fi > b[j].fi.fi;
}
int main()
{
    ios_base::sync_with_stdio();cin.tie(0);cout.tie(0);
    cin>>n>>Q;
    for(int i = 1; i <= n; i++) cin>>a[i];
    limit = n;
    for(int i = 1; i <= Q; i++)
    {
        cin>>l>>r>>x;
        b[i] = {{l, r}, x};
        q.push_back(i);
    }
    sort(all(q), comp);
    for(auto i : q)
    {
        l = b[i].fi.fi;
        r = b[i].fi.se;
        k = b[i].se;
        if(limit >= l)
        {
            make(l, limit);
            limit = l - 1;
        }
        x = get(1, 1, n, l, r);
        ans[i] = (x <= k);
    }
    for(int i = 1; i <= Q; i++) cout<<ans[i]<<"\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 372 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 408 KB Output is correct
6 Correct 4 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 372 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 408 KB Output is correct
6 Correct 4 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 9 ms 508 KB Output is correct
12 Correct 12 ms 504 KB Output is correct
13 Correct 13 ms 504 KB Output is correct
14 Correct 17 ms 504 KB Output is correct
15 Correct 17 ms 504 KB Output is correct
16 Correct 13 ms 504 KB Output is correct
17 Correct 12 ms 604 KB Output is correct
18 Correct 11 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3023 ms 29804 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 245 ms 4080 KB Output is correct
2 Correct 236 ms 4008 KB Output is correct
3 Correct 232 ms 4076 KB Output is correct
4 Correct 233 ms 3824 KB Output is correct
5 Correct 236 ms 3952 KB Output is correct
6 Correct 216 ms 3948 KB Output is correct
7 Correct 214 ms 4028 KB Output is correct
8 Correct 212 ms 4180 KB Output is correct
9 Correct 146 ms 2676 KB Output is correct
10 Correct 212 ms 3996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 372 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 408 KB Output is correct
6 Correct 4 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 9 ms 508 KB Output is correct
12 Correct 12 ms 504 KB Output is correct
13 Correct 13 ms 504 KB Output is correct
14 Correct 17 ms 504 KB Output is correct
15 Correct 17 ms 504 KB Output is correct
16 Correct 13 ms 504 KB Output is correct
17 Correct 12 ms 604 KB Output is correct
18 Correct 11 ms 632 KB Output is correct
19 Correct 711 ms 7864 KB Output is correct
20 Correct 669 ms 7752 KB Output is correct
21 Correct 631 ms 7684 KB Output is correct
22 Correct 627 ms 7788 KB Output is correct
23 Correct 631 ms 7824 KB Output is correct
24 Correct 602 ms 7252 KB Output is correct
25 Correct 599 ms 7264 KB Output is correct
26 Correct 630 ms 7404 KB Output is correct
27 Correct 619 ms 7272 KB Output is correct
28 Correct 718 ms 7280 KB Output is correct
29 Correct 628 ms 7296 KB Output is correct
30 Correct 637 ms 7268 KB Output is correct
31 Correct 636 ms 7452 KB Output is correct
32 Correct 687 ms 7532 KB Output is correct
33 Correct 630 ms 7300 KB Output is correct
34 Correct 584 ms 7420 KB Output is correct
35 Correct 590 ms 7272 KB Output is correct
36 Correct 583 ms 7240 KB Output is correct
37 Correct 575 ms 7288 KB Output is correct
38 Correct 600 ms 7224 KB Output is correct
39 Correct 529 ms 7944 KB Output is correct
40 Correct 449 ms 6736 KB Output is correct
41 Correct 497 ms 7444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 372 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 408 KB Output is correct
6 Correct 4 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 9 ms 508 KB Output is correct
12 Correct 12 ms 504 KB Output is correct
13 Correct 13 ms 504 KB Output is correct
14 Correct 17 ms 504 KB Output is correct
15 Correct 17 ms 504 KB Output is correct
16 Correct 13 ms 504 KB Output is correct
17 Correct 12 ms 604 KB Output is correct
18 Correct 11 ms 632 KB Output is correct
19 Execution timed out 3023 ms 29804 KB Time limit exceeded
20 Halted 0 ms 0 KB -