답안 #1058045

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1058045 2024-08-14T08:06:28 Z vjudge1 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
64 / 100
370 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
#define pb push_back
const ll mod = 1e9+7, mxn = 1e6+1;
struct node 
{
    vector<ll> v;
    ll ans = -mod;
};
void merge(node& c, node& a, node& b)
{
    c.ans = max({a.ans, b.ans});
    ll p = lower_bound(b.v.begin(), b.v.end(), a.v.back())-b.v.begin()-1;
    if (p >= 0) c.ans = max({c.ans,b.v[p]+a.v.back()});
    ll id_a = 0, id_b = 0;
    while (id_a < a.v.size() && id_b < b.v.size())
    {
        if (a.v[id_a] < b.v[id_b]) 
        {
            if (c.v.empty() || c.v.back() != a.v[id_a]) c.v.pb(a.v[id_a++]);
            else id_a++;
        }
        else 
        {
            if (c.v.empty() || b.v[id_b] != c.v.back()) c.v.pb(b.v[id_b++]);
            else id_b++;
        }
    } 
    while (id_a < a.v.size()) 
    {
        if (c.v.empty() || c.v.back() != a.v[id_a]) c.v.pb(a.v[id_a++]);
        else id_a++;
    }
    while (id_b < b.v.size()) 
    {
        if (c.v.empty() || b.v[id_b] != c.v.back()) c.v.pb(b.v[id_b++]);
        else id_b++;
    }
}
vector<node> st(mxn<<2);
ll a[mxn], n, q, ans, f;
void build(ll id, ll l, ll r)
{
    if (l == r) {st[id].v = {a[l]}; return;}
    ll m = (r+l)>>1;
    build(id<<1,l,m); build(id<<1|1,m+1,r);
    merge(st[id], st[id<<1], st[id<<1|1]);
    if (l == m) st[id<<1].v.clear();
    if (m+1 == r) st[id<<1|1].v.clear();
}
void get(ll id, ll l, ll r, ll u, ll v)
{
    if (u <= l && r <= v)
    {
        if (l == r)
        {
            if (a[l] < f) ans = max(ans, a[l]+f);
            f = max(f, a[l]);
            return;
        }
        ans = max({ans, st[id].ans});
        ll p = lower_bound(st[id].v.begin(), st[id].v.end(), f)-st[id].v.begin()-1;
        if (p >= 0) ans = max({ans, st[id].v[p]+f});
        f = max(f, st[id].v.back());
        return;
    }
    ll m = (r+l)>>1;
    if (v <= m) get(id<<1,l,m,u,v);
    else if (m+1 <= u) get(id<<1|1,m+1,r,u,v);
    else {get(id<<1,l,m,u,v); get(id<<1|1,m+1,r,u,v);}
}
signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // freopen("test.inp","r",stdin); freopen("test.out","w",stdout); freopen("test.err","w",stderr);
    cin >> n >> q;
    for (ll i = 1; i <= n; i++) cin >> a[i];
    build(1,1,n);
    while (q--)
    {
        ll l, r, k; cin >> l >> r >> k; ans = 0; f = -mod; get(1,1,n,l,r);
        cout << (ans <= k) << '\n';
    }
}

Compilation message

sortbooks.cpp: In function 'void merge(node&, node&, node&)':
sortbooks.cpp:17:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     while (id_a < a.v.size() && id_b < b.v.size())
      |            ~~~~~^~~~~~~~~~~~
sortbooks.cpp:17:38: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     while (id_a < a.v.size() && id_b < b.v.size())
      |                                 ~~~~~^~~~~~~~~~~~
sortbooks.cpp:30:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     while (id_a < a.v.size())
      |            ~~~~~^~~~~~~~~~~~
sortbooks.cpp:35:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     while (id_b < b.v.size())
      |            ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 125528 KB Output is correct
2 Correct 22 ms 125612 KB Output is correct
3 Correct 21 ms 125532 KB Output is correct
4 Correct 23 ms 125532 KB Output is correct
5 Correct 20 ms 125528 KB Output is correct
6 Correct 21 ms 125532 KB Output is correct
7 Correct 23 ms 125604 KB Output is correct
8 Correct 23 ms 125532 KB Output is correct
9 Correct 18 ms 125528 KB Output is correct
10 Correct 22 ms 125532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 125528 KB Output is correct
2 Correct 22 ms 125612 KB Output is correct
3 Correct 21 ms 125532 KB Output is correct
4 Correct 23 ms 125532 KB Output is correct
5 Correct 20 ms 125528 KB Output is correct
6 Correct 21 ms 125532 KB Output is correct
7 Correct 23 ms 125604 KB Output is correct
8 Correct 23 ms 125532 KB Output is correct
9 Correct 18 ms 125528 KB Output is correct
10 Correct 22 ms 125532 KB Output is correct
11 Correct 25 ms 125788 KB Output is correct
12 Correct 20 ms 126296 KB Output is correct
13 Correct 21 ms 126300 KB Output is correct
14 Correct 27 ms 126300 KB Output is correct
15 Correct 29 ms 126408 KB Output is correct
16 Correct 28 ms 126264 KB Output is correct
17 Correct 22 ms 126044 KB Output is correct
18 Correct 20 ms 126040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 370 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 111 ms 138320 KB Output is correct
2 Correct 141 ms 139772 KB Output is correct
3 Correct 107 ms 135580 KB Output is correct
4 Correct 92 ms 135548 KB Output is correct
5 Correct 87 ms 135512 KB Output is correct
6 Correct 96 ms 135504 KB Output is correct
7 Correct 90 ms 135476 KB Output is correct
8 Correct 84 ms 135368 KB Output is correct
9 Correct 41 ms 126948 KB Output is correct
10 Correct 77 ms 135252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 125528 KB Output is correct
2 Correct 22 ms 125612 KB Output is correct
3 Correct 21 ms 125532 KB Output is correct
4 Correct 23 ms 125532 KB Output is correct
5 Correct 20 ms 125528 KB Output is correct
6 Correct 21 ms 125532 KB Output is correct
7 Correct 23 ms 125604 KB Output is correct
8 Correct 23 ms 125532 KB Output is correct
9 Correct 18 ms 125528 KB Output is correct
10 Correct 22 ms 125532 KB Output is correct
11 Correct 25 ms 125788 KB Output is correct
12 Correct 20 ms 126296 KB Output is correct
13 Correct 21 ms 126300 KB Output is correct
14 Correct 27 ms 126300 KB Output is correct
15 Correct 29 ms 126408 KB Output is correct
16 Correct 28 ms 126264 KB Output is correct
17 Correct 22 ms 126044 KB Output is correct
18 Correct 20 ms 126040 KB Output is correct
19 Correct 258 ms 157928 KB Output is correct
20 Correct 272 ms 159320 KB Output is correct
21 Correct 307 ms 158996 KB Output is correct
22 Correct 259 ms 159096 KB Output is correct
23 Correct 274 ms 159108 KB Output is correct
24 Correct 211 ms 158712 KB Output is correct
25 Correct 238 ms 158776 KB Output is correct
26 Correct 248 ms 159320 KB Output is correct
27 Correct 219 ms 158920 KB Output is correct
28 Correct 287 ms 159036 KB Output is correct
29 Correct 223 ms 158936 KB Output is correct
30 Correct 264 ms 159428 KB Output is correct
31 Correct 217 ms 159052 KB Output is correct
32 Correct 267 ms 159032 KB Output is correct
33 Correct 249 ms 159144 KB Output is correct
34 Correct 204 ms 158872 KB Output is correct
35 Correct 223 ms 158860 KB Output is correct
36 Correct 207 ms 158816 KB Output is correct
37 Correct 210 ms 158848 KB Output is correct
38 Correct 229 ms 158632 KB Output is correct
39 Correct 223 ms 158216 KB Output is correct
40 Correct 149 ms 146380 KB Output is correct
41 Correct 143 ms 143264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 125528 KB Output is correct
2 Correct 22 ms 125612 KB Output is correct
3 Correct 21 ms 125532 KB Output is correct
4 Correct 23 ms 125532 KB Output is correct
5 Correct 20 ms 125528 KB Output is correct
6 Correct 21 ms 125532 KB Output is correct
7 Correct 23 ms 125604 KB Output is correct
8 Correct 23 ms 125532 KB Output is correct
9 Correct 18 ms 125528 KB Output is correct
10 Correct 22 ms 125532 KB Output is correct
11 Correct 25 ms 125788 KB Output is correct
12 Correct 20 ms 126296 KB Output is correct
13 Correct 21 ms 126300 KB Output is correct
14 Correct 27 ms 126300 KB Output is correct
15 Correct 29 ms 126408 KB Output is correct
16 Correct 28 ms 126264 KB Output is correct
17 Correct 22 ms 126044 KB Output is correct
18 Correct 20 ms 126040 KB Output is correct
19 Runtime error 370 ms 262144 KB Execution killed with signal 9
20 Halted 0 ms 0 KB -