/*
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";
}
}
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 |
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 |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 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 |
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 |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 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 |
376 KB |
Output is correct |
12 |
Correct |
6 ms |
504 KB |
Output is correct |
13 |
Correct |
6 ms |
376 KB |
Output is correct |
14 |
Correct |
8 ms |
376 KB |
Output is correct |
15 |
Correct |
9 ms |
504 KB |
Output is correct |
16 |
Correct |
8 ms |
504 KB |
Output is correct |
17 |
Correct |
7 ms |
376 KB |
Output is correct |
18 |
Correct |
21 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3048 ms |
14732 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
284 ms |
1820 KB |
Output is correct |
2 |
Correct |
727 ms |
1576 KB |
Output is correct |
3 |
Correct |
287 ms |
1712 KB |
Output is correct |
4 |
Correct |
220 ms |
1656 KB |
Output is correct |
5 |
Correct |
182 ms |
1628 KB |
Output is correct |
6 |
Correct |
571 ms |
1684 KB |
Output is correct |
7 |
Correct |
634 ms |
1784 KB |
Output is correct |
8 |
Correct |
451 ms |
1784 KB |
Output is correct |
9 |
Correct |
56 ms |
632 KB |
Output is correct |
10 |
Correct |
448 ms |
1904 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 |
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 |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 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 |
376 KB |
Output is correct |
12 |
Correct |
6 ms |
504 KB |
Output is correct |
13 |
Correct |
6 ms |
376 KB |
Output is correct |
14 |
Correct |
8 ms |
376 KB |
Output is correct |
15 |
Correct |
9 ms |
504 KB |
Output is correct |
16 |
Correct |
8 ms |
504 KB |
Output is correct |
17 |
Correct |
7 ms |
376 KB |
Output is correct |
18 |
Correct |
21 ms |
504 KB |
Output is correct |
19 |
Correct |
777 ms |
2468 KB |
Output is correct |
20 |
Correct |
933 ms |
2596 KB |
Output is correct |
21 |
Execution timed out |
3010 ms |
2692 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
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 |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 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 |
376 KB |
Output is correct |
12 |
Correct |
6 ms |
504 KB |
Output is correct |
13 |
Correct |
6 ms |
376 KB |
Output is correct |
14 |
Correct |
8 ms |
376 KB |
Output is correct |
15 |
Correct |
9 ms |
504 KB |
Output is correct |
16 |
Correct |
8 ms |
504 KB |
Output is correct |
17 |
Correct |
7 ms |
376 KB |
Output is correct |
18 |
Correct |
21 ms |
504 KB |
Output is correct |
19 |
Execution timed out |
3048 ms |
14732 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |