답안 #162949

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
162949 2019-11-10T11:41:42 Z dandrozavr Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
64 / 100
3000 ms 9352 KB
/*
Uruchamiamy samolot zwiadowczy ( + 500% do wzlamaniej )

/▄/  /█/  /◐/   /▐/   /▌/ /▀/ /░/ /🔥/   choose  own style!

***IT'S OUR LONG WAY TO THE OIILLLL***


░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░▌░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░◐◐◐█████████▀▀▀▀▀▀🔥░░░░░░░░███░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░▌░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░█▌░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▄▄▀██████████████████████████████████████████████████
░░░░░░░░░░░░░░░░░░░░░░░░░░▄▄▄████▄████████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ █████
░░░░░░░░░░░░░░░░░░░░░░░░░░░▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█████████▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░◐◐◐█████████▀▀▀▀▀▀🔥░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░███████░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██████░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████░░░░░░░░░░░░░░░
*/



//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#include <bits/stdc++.h>

using namespace std;
#include <ext/pb_ds/detail/standard_policies.hpp>'
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;template <typename T> using ordered_set = tree <T, null_type, less< T >, rb_tree_tag,tree_order_statistics_node_update>;

#define pb push_back
#define ll long long
#define ld long double
#define mp make_pair
#define fi first
#define se second
//#define pi 3.14159265358979323846
#define pii pair < ll , int >
#define pipii pair< int, pair < int , int > >
#define siz(n) (int)(n.size())


const int inf=1e9 + 7;
const ll inf18=1e18 + 7;
const int N=1e6 + 7;
const int MN = 2097152;
int t[MN + 5], need[MN + 5], a[N], otv[N], sqr, al;
vector < int > b[1005];

int solve(int l, int r)
{
    int vl = l / sqr, vr = r / sqr;

    if (vl == vr)
    {
        int ans = 0;
        int mx = 0;
        for (int i = l; i <= r; ++i)
        {
            if (mx > a[i])
                ans = max(ans, mx + a[i]); else
                mx = a[i];
        }
        return ans;
    }
    int sl = (vl + 1) * sqr;
    int ans = 0, mx = 0;

    for (int i = l; i < sl; ++i)
    {
        if (mx > a[i])
            ans = max(ans, mx + a[i]); else
            mx = a[i];
    }
    for (int bl = vl + 1; bl < vr; ++bl)
    {
        ans = max(ans, otv[bl]);
        int poz = lower_bound(b[bl].begin(), b[bl].end(), mx) - b[bl].begin();
        if (poz)
        {
            --poz;
//        cerr<<mx<<" "<<b[bl][poz + 1]<<endl;
            ans = max(ans, b[bl][poz] + mx);
        }

        if (b[bl].back() > mx) mx = b[bl].back();
    }

    for (int i = vr * sqr; i <= r; ++i)
    {
        if (mx > a[i])
            ans = max(ans, mx + a[i]); else
            mx = a[i];
    }

    return ans;
}


int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifdef Estb_probitie
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int n, m;
    cin >> n >> m;
    sqr = sqrt(n);
    int nxt = sqr;
    int now = 0, mx = 0;

    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];

        if (i == nxt)
        {
            ++now;
            nxt += sqr;
            mx = 0;
        }

        b[now].pb(a[i]);
        if (mx > a[i])
            otv[now] = max(otv[now], mx + a[i]); else
            mx = a[i];
    }

    for (int i = 0; i < 1000; ++i)
        sort(b[i].begin(),b[i].end());

    for (int i = 0; i < m; ++i)
    {
        int l, r, k;
        cin >> l >> r >> k;
        --l, --r;
        int ans = solve(l, r);
        if (ans > k)
            cout << 0 << '\n'; else cout << 1 << '\n';
    }


}

Compilation message

sortbooks.cpp:35:50: warning: missing terminating ' character
 #include <ext/pb_ds/detail/standard_policies.hpp>'
                                                  ^
sortbooks.cpp:35:50: warning: extra tokens at end of #include directive
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 380 KB Output is correct
8 Correct 4 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 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 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 380 KB Output is correct
8 Correct 4 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 5 ms 504 KB Output is correct
12 Correct 6 ms 504 KB Output is correct
13 Correct 6 ms 632 KB Output is correct
14 Correct 8 ms 632 KB Output is correct
15 Correct 8 ms 632 KB Output is correct
16 Correct 8 ms 508 KB Output is correct
17 Correct 7 ms 504 KB Output is correct
18 Correct 8 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3036 ms 9352 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 285 ms 1912 KB Output is correct
2 Correct 735 ms 2980 KB Output is correct
3 Correct 286 ms 3596 KB Output is correct
4 Correct 227 ms 3708 KB Output is correct
5 Correct 198 ms 3548 KB Output is correct
6 Correct 567 ms 3536 KB Output is correct
7 Correct 577 ms 3512 KB Output is correct
8 Correct 450 ms 3348 KB Output is correct
9 Correct 57 ms 1912 KB Output is correct
10 Correct 438 ms 3448 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 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 380 KB Output is correct
8 Correct 4 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 5 ms 504 KB Output is correct
12 Correct 6 ms 504 KB Output is correct
13 Correct 6 ms 632 KB Output is correct
14 Correct 8 ms 632 KB Output is correct
15 Correct 8 ms 632 KB Output is correct
16 Correct 8 ms 508 KB Output is correct
17 Correct 7 ms 504 KB Output is correct
18 Correct 8 ms 504 KB Output is correct
19 Correct 780 ms 5948 KB Output is correct
20 Correct 763 ms 9172 KB Output is correct
21 Correct 2593 ms 9084 KB Output is correct
22 Correct 2556 ms 8988 KB Output is correct
23 Correct 2548 ms 9100 KB Output is correct
24 Correct 1931 ms 8960 KB Output is correct
25 Correct 2005 ms 9140 KB Output is correct
26 Correct 1180 ms 9152 KB Output is correct
27 Correct 1326 ms 9080 KB Output is correct
28 Correct 1099 ms 9208 KB Output is correct
29 Correct 545 ms 9312 KB Output is correct
30 Correct 537 ms 9180 KB Output is correct
31 Correct 592 ms 9080 KB Output is correct
32 Correct 590 ms 9236 KB Output is correct
33 Correct 590 ms 9228 KB Output is correct
34 Correct 2021 ms 8720 KB Output is correct
35 Correct 2033 ms 8868 KB Output is correct
36 Correct 1960 ms 8536 KB Output is correct
37 Correct 2025 ms 8684 KB Output is correct
38 Correct 2076 ms 8808 KB Output is correct
39 Correct 1450 ms 7680 KB Output is correct
40 Correct 903 ms 6636 KB Output is correct
41 Correct 1429 ms 7380 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 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 380 KB Output is correct
8 Correct 4 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 5 ms 504 KB Output is correct
12 Correct 6 ms 504 KB Output is correct
13 Correct 6 ms 632 KB Output is correct
14 Correct 8 ms 632 KB Output is correct
15 Correct 8 ms 632 KB Output is correct
16 Correct 8 ms 508 KB Output is correct
17 Correct 7 ms 504 KB Output is correct
18 Correct 8 ms 504 KB Output is correct
19 Execution timed out 3036 ms 9352 KB Time limit exceeded
20 Halted 0 ms 0 KB -