답안 #151555

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
151555 2019-09-03T14:21:30 Z andrew Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
3000 ms 29644 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 long double ld;
const int MAXN = 1123456;
const int N = 1e6 + 200;
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<int, int> > v;
pair<pair<int, int>, int> b[N];
vector<int> q;
int t[4 * N],a[N],n,Q,limit,l,r,x,k,ans[N];
void upd(int v,int tl,int tr,int pos,int val)
{
    if(tl == tr)
    {
        t[v] = val + a[tl];
        return;
    }
    int tm = (tl + tr) >> 1;
    if(pos <= tm) upd(v << 1, tl, tm, pos, val);
    else upd(v << 1 | 1, tm + 1, tr, pos, val);
    t[v] = max(t[v << 1], t[v << 1 | 1]);
}
int get(int v,int tl,int tr,int l,int r)
{
    if(l > r) return 0;
    if(tl == l && tr == r) return t[v];
    int tm = (tl + tr) >> 1;
    return max(get(v << 1, tl, tm, l, min(r, tm)), get(v << 1 | 1, tm + 1, tr, max(l, tm + 1), r));
}
void make(int l,int r)
{
    for(int i = r; i >= l; i--)
    {
        int 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(int i,int j)
{
    return (b[i].fi.fi > b[j].fi.fi) || (b[i].fi.fi == b[j].fi.fi && (m_p(b[i].fi.se, b[i].se) < m_p(b[j].fi.se, b[j].se)));
}
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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 248 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 348 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 248 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 348 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 9 ms 504 KB Output is correct
12 Correct 11 ms 504 KB Output is correct
13 Correct 13 ms 500 KB Output is correct
14 Correct 16 ms 504 KB Output is correct
15 Correct 16 ms 504 KB Output is correct
16 Correct 13 ms 504 KB Output is correct
17 Correct 12 ms 504 KB Output is correct
18 Correct 11 ms 668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3026 ms 29644 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 245 ms 4148 KB Output is correct
2 Correct 237 ms 4164 KB Output is correct
3 Correct 227 ms 3828 KB Output is correct
4 Correct 234 ms 3816 KB Output is correct
5 Correct 229 ms 3836 KB Output is correct
6 Correct 215 ms 3948 KB Output is correct
7 Correct 215 ms 3820 KB Output is correct
8 Correct 223 ms 4380 KB Output is correct
9 Correct 152 ms 2600 KB Output is correct
10 Correct 211 ms 3996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 248 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 348 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 9 ms 504 KB Output is correct
12 Correct 11 ms 504 KB Output is correct
13 Correct 13 ms 500 KB Output is correct
14 Correct 16 ms 504 KB Output is correct
15 Correct 16 ms 504 KB Output is correct
16 Correct 13 ms 504 KB Output is correct
17 Correct 12 ms 504 KB Output is correct
18 Correct 11 ms 668 KB Output is correct
19 Correct 655 ms 7584 KB Output is correct
20 Correct 658 ms 7692 KB Output is correct
21 Correct 627 ms 7628 KB Output is correct
22 Correct 632 ms 7608 KB Output is correct
23 Correct 622 ms 7796 KB Output is correct
24 Correct 615 ms 7296 KB Output is correct
25 Correct 608 ms 7276 KB Output is correct
26 Correct 619 ms 7268 KB Output is correct
27 Correct 626 ms 7260 KB Output is correct
28 Correct 621 ms 7344 KB Output is correct
29 Correct 630 ms 7180 KB Output is correct
30 Correct 630 ms 7372 KB Output is correct
31 Correct 618 ms 7404 KB Output is correct
32 Correct 631 ms 7328 KB Output is correct
33 Correct 629 ms 7320 KB Output is correct
34 Correct 586 ms 7184 KB Output is correct
35 Correct 591 ms 7400 KB Output is correct
36 Correct 581 ms 7272 KB Output is correct
37 Correct 577 ms 7180 KB Output is correct
38 Correct 595 ms 7224 KB Output is correct
39 Correct 534 ms 8036 KB Output is correct
40 Correct 471 ms 6696 KB Output is correct
41 Correct 495 ms 7644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 248 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 348 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 9 ms 504 KB Output is correct
12 Correct 11 ms 504 KB Output is correct
13 Correct 13 ms 500 KB Output is correct
14 Correct 16 ms 504 KB Output is correct
15 Correct 16 ms 504 KB Output is correct
16 Correct 13 ms 504 KB Output is correct
17 Correct 12 ms 504 KB Output is correct
18 Correct 11 ms 668 KB Output is correct
19 Execution timed out 3026 ms 29644 KB Time limit exceeded
20 Halted 0 ms 0 KB -