Submission #162950

# Submission time Handle Problem Language Result Execution time Memory
162950 2019-11-10T11:52:04 Z dandrozavr Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
64 / 100
3000 ms 10076 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
# Verdict Execution time Memory 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 2 ms 380 KB Output is correct
5 Correct 2 ms 452 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 380 KB Output is correct
9 Correct 2 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 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 2 ms 380 KB Output is correct
5 Correct 2 ms 452 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 380 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 4 ms 504 KB Output is correct
12 Correct 6 ms 504 KB Output is correct
13 Correct 17 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 10 ms 504 KB Output is correct
17 Correct 7 ms 504 KB Output is correct
18 Correct 10 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3015 ms 10076 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 280 ms 2600 KB Output is correct
2 Correct 745 ms 3192 KB Output is correct
3 Correct 288 ms 2304 KB Output is correct
4 Correct 219 ms 2564 KB Output is correct
5 Correct 186 ms 2552 KB Output is correct
6 Correct 561 ms 2512 KB Output is correct
7 Correct 573 ms 2680 KB Output is correct
8 Correct 462 ms 2504 KB Output is correct
9 Correct 57 ms 1272 KB Output is correct
10 Correct 423 ms 2552 KB Output is correct
# Verdict Execution time Memory 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 2 ms 380 KB Output is correct
5 Correct 2 ms 452 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 380 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 4 ms 504 KB Output is correct
12 Correct 6 ms 504 KB Output is correct
13 Correct 17 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 10 ms 504 KB Output is correct
17 Correct 7 ms 504 KB Output is correct
18 Correct 10 ms 504 KB Output is correct
19 Correct 751 ms 3832 KB Output is correct
20 Correct 736 ms 3192 KB Output is correct
21 Correct 2567 ms 3632 KB Output is correct
22 Correct 2518 ms 3728 KB Output is correct
23 Correct 2538 ms 3716 KB Output is correct
24 Correct 1910 ms 3716 KB Output is correct
25 Correct 1918 ms 3696 KB Output is correct
26 Correct 1192 ms 3780 KB Output is correct
27 Correct 1360 ms 3684 KB Output is correct
28 Correct 1032 ms 3832 KB Output is correct
29 Correct 543 ms 3624 KB Output is correct
30 Correct 534 ms 3664 KB Output is correct
31 Correct 602 ms 3688 KB Output is correct
32 Correct 593 ms 3804 KB Output is correct
33 Correct 662 ms 3704 KB Output is correct
34 Correct 2058 ms 3708 KB Output is correct
35 Correct 2047 ms 3812 KB Output is correct
36 Correct 2063 ms 3740 KB Output is correct
37 Correct 2057 ms 3716 KB Output is correct
38 Correct 2008 ms 3648 KB Output is correct
39 Correct 1341 ms 3796 KB Output is correct
40 Correct 950 ms 3344 KB Output is correct
41 Correct 1435 ms 3528 KB Output is correct
# Verdict Execution time Memory 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 2 ms 380 KB Output is correct
5 Correct 2 ms 452 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 380 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 4 ms 504 KB Output is correct
12 Correct 6 ms 504 KB Output is correct
13 Correct 17 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 10 ms 504 KB Output is correct
17 Correct 7 ms 504 KB Output is correct
18 Correct 10 ms 504 KB Output is correct
19 Execution timed out 3015 ms 10076 KB Time limit exceeded
20 Halted 0 ms 0 KB -