/*
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 a[N], otv[N], sqr, al, nxt[N];
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;
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;
if (n > 2e5 || m > 2e5)
{
for (int i = 0; i < n; ++i)
cin >> a[i];
int now = 1e9;
for (int i = n - 1; i >= 0; --i)
{
if (i + 1 < n && a[i] > a[i + 1])
now = i;
nxt[i] = now;
}
for (int i = 0; i < m; ++i)
{
int l, r, k;
cin >> l >> r >> k;
--l, --r;
if (nxt[l] >= r)
cout << "1\n"; else cout << "0\n";
}
exit(0);
}
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 |
3 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 |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 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 |
3 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 |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 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 |
4 ms |
380 KB |
Output is correct |
12 |
Correct |
6 ms |
552 KB |
Output is correct |
13 |
Correct |
6 ms |
376 KB |
Output is correct |
14 |
Correct |
9 ms |
376 KB |
Output is correct |
15 |
Correct |
8 ms |
504 KB |
Output is correct |
16 |
Correct |
8 ms |
504 KB |
Output is correct |
17 |
Correct |
7 ms |
504 KB |
Output is correct |
18 |
Correct |
8 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
612 ms |
10360 KB |
Output is correct |
2 |
Correct |
723 ms |
20596 KB |
Output is correct |
3 |
Correct |
628 ms |
20476 KB |
Output is correct |
4 |
Correct |
610 ms |
20752 KB |
Output is correct |
5 |
Correct |
949 ms |
20648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
283 ms |
1660 KB |
Output is correct |
2 |
Correct |
742 ms |
1788 KB |
Output is correct |
3 |
Correct |
289 ms |
1680 KB |
Output is correct |
4 |
Correct |
215 ms |
1672 KB |
Output is correct |
5 |
Correct |
186 ms |
1656 KB |
Output is correct |
6 |
Correct |
613 ms |
1800 KB |
Output is correct |
7 |
Correct |
531 ms |
1724 KB |
Output is correct |
8 |
Correct |
464 ms |
1656 KB |
Output is correct |
9 |
Correct |
55 ms |
632 KB |
Output is correct |
10 |
Correct |
461 ms |
1656 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 |
3 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 |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 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 |
4 ms |
380 KB |
Output is correct |
12 |
Correct |
6 ms |
552 KB |
Output is correct |
13 |
Correct |
6 ms |
376 KB |
Output is correct |
14 |
Correct |
9 ms |
376 KB |
Output is correct |
15 |
Correct |
8 ms |
504 KB |
Output is correct |
16 |
Correct |
8 ms |
504 KB |
Output is correct |
17 |
Correct |
7 ms |
504 KB |
Output is correct |
18 |
Correct |
8 ms |
376 KB |
Output is correct |
19 |
Correct |
751 ms |
2672 KB |
Output is correct |
20 |
Correct |
769 ms |
2624 KB |
Output is correct |
21 |
Correct |
2508 ms |
2816 KB |
Output is correct |
22 |
Correct |
2651 ms |
2728 KB |
Output is correct |
23 |
Correct |
2674 ms |
2636 KB |
Output is correct |
24 |
Correct |
1882 ms |
2788 KB |
Output is correct |
25 |
Correct |
1901 ms |
2680 KB |
Output is correct |
26 |
Correct |
1212 ms |
2592 KB |
Output is correct |
27 |
Correct |
1210 ms |
2548 KB |
Output is correct |
28 |
Correct |
1004 ms |
2452 KB |
Output is correct |
29 |
Correct |
537 ms |
2608 KB |
Output is correct |
30 |
Correct |
552 ms |
2704 KB |
Output is correct |
31 |
Correct |
629 ms |
2724 KB |
Output is correct |
32 |
Correct |
579 ms |
2552 KB |
Output is correct |
33 |
Correct |
570 ms |
2552 KB |
Output is correct |
34 |
Correct |
1964 ms |
2564 KB |
Output is correct |
35 |
Correct |
1998 ms |
2676 KB |
Output is correct |
36 |
Correct |
2025 ms |
2796 KB |
Output is correct |
37 |
Correct |
2001 ms |
2672 KB |
Output is correct |
38 |
Correct |
1967 ms |
2784 KB |
Output is correct |
39 |
Correct |
1466 ms |
2552 KB |
Output is correct |
40 |
Correct |
989 ms |
2196 KB |
Output is correct |
41 |
Correct |
1441 ms |
2680 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 |
3 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 |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 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 |
4 ms |
380 KB |
Output is correct |
12 |
Correct |
6 ms |
552 KB |
Output is correct |
13 |
Correct |
6 ms |
376 KB |
Output is correct |
14 |
Correct |
9 ms |
376 KB |
Output is correct |
15 |
Correct |
8 ms |
504 KB |
Output is correct |
16 |
Correct |
8 ms |
504 KB |
Output is correct |
17 |
Correct |
7 ms |
504 KB |
Output is correct |
18 |
Correct |
8 ms |
376 KB |
Output is correct |
19 |
Correct |
612 ms |
10360 KB |
Output is correct |
20 |
Correct |
723 ms |
20596 KB |
Output is correct |
21 |
Correct |
628 ms |
20476 KB |
Output is correct |
22 |
Correct |
610 ms |
20752 KB |
Output is correct |
23 |
Correct |
949 ms |
20648 KB |
Output is correct |
24 |
Correct |
283 ms |
1660 KB |
Output is correct |
25 |
Correct |
742 ms |
1788 KB |
Output is correct |
26 |
Correct |
289 ms |
1680 KB |
Output is correct |
27 |
Correct |
215 ms |
1672 KB |
Output is correct |
28 |
Correct |
186 ms |
1656 KB |
Output is correct |
29 |
Correct |
613 ms |
1800 KB |
Output is correct |
30 |
Correct |
531 ms |
1724 KB |
Output is correct |
31 |
Correct |
464 ms |
1656 KB |
Output is correct |
32 |
Correct |
55 ms |
632 KB |
Output is correct |
33 |
Correct |
461 ms |
1656 KB |
Output is correct |
34 |
Correct |
751 ms |
2672 KB |
Output is correct |
35 |
Correct |
769 ms |
2624 KB |
Output is correct |
36 |
Correct |
2508 ms |
2816 KB |
Output is correct |
37 |
Correct |
2651 ms |
2728 KB |
Output is correct |
38 |
Correct |
2674 ms |
2636 KB |
Output is correct |
39 |
Correct |
1882 ms |
2788 KB |
Output is correct |
40 |
Correct |
1901 ms |
2680 KB |
Output is correct |
41 |
Correct |
1212 ms |
2592 KB |
Output is correct |
42 |
Correct |
1210 ms |
2548 KB |
Output is correct |
43 |
Correct |
1004 ms |
2452 KB |
Output is correct |
44 |
Correct |
537 ms |
2608 KB |
Output is correct |
45 |
Correct |
552 ms |
2704 KB |
Output is correct |
46 |
Correct |
629 ms |
2724 KB |
Output is correct |
47 |
Correct |
579 ms |
2552 KB |
Output is correct |
48 |
Correct |
570 ms |
2552 KB |
Output is correct |
49 |
Correct |
1964 ms |
2564 KB |
Output is correct |
50 |
Correct |
1998 ms |
2676 KB |
Output is correct |
51 |
Correct |
2025 ms |
2796 KB |
Output is correct |
52 |
Correct |
2001 ms |
2672 KB |
Output is correct |
53 |
Correct |
1967 ms |
2784 KB |
Output is correct |
54 |
Correct |
1466 ms |
2552 KB |
Output is correct |
55 |
Correct |
989 ms |
2196 KB |
Output is correct |
56 |
Correct |
1441 ms |
2680 KB |
Output is correct |
57 |
Incorrect |
661 ms |
23220 KB |
Output isn't correct |
58 |
Halted |
0 ms |
0 KB |
- |