// ZapZu's code hohoho
// #pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define dfs_black 1
#define dfs_white -1
#define pr pair
#define vt vector
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ln 2*id
#define rn 2*id+1
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
typedef double db;
typedef long long li;
typedef long double ld;
typedef pr<int, int> ii;
typedef pr<ld,ld> dd;
typedef vt<int> vi;
typedef vt<li> vli;
typedef vt<ld> vld;
typedef vt<ii> vii;
typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef map<int, char> mic;
typedef set<int> s_i;
typedef set<char> s_c;
const int MOD = 1e9+7;
const li INF = 1e18;
const ld PI = 4*atan((ld)1);
int a[1000005];
struct it
{
vi mx, mx_inv; vt<vi> arr; int n, re, cur_mx;
it(int _n): n(_n)
{
mx.assign(5*n+5, 0);
mx_inv.assign(5*n+5, 0);
arr.assign(5*n+5, vi());
}
void build(int id, int l, int r)
{
if(l==r)
{
mx[id] = a[l];
mx_inv[id] = 0;
arr[id].eb(a[l]);
return;
}
build(ln, l, (l+r)/2);
build(rn, (l+r)/2+1, r);
mx[id] = max(mx[ln], mx[rn]); arr[id].resize(r-l+1); mx_inv[id] = max(mx_inv[2*id], mx_inv[2*id+1]);
for(int i=0; i<arr[rn].size(); i++) if(arr[rn][i]<mx[ln])mx_inv[id] = max(mx_inv[id],mx[ln]+arr[rn][i]);
int p1=-1, p2=-1;
while(p1+1<arr[ln].size() || p2+1<arr[rn].size())
{
if(p2+1>=arr[rn].size())
{
arr[id][p1+p2+2] = arr[ln][p1+1]; //w?
p1++;
}
else if(p1+1>=arr[ln].size())
{
arr[id][p1+p2+2] = arr[rn][p2+1];
p2++;
}
else if(arr[ln][p1+1]<arr[rn][p2+1])
{
arr[id][p1+p2+2] = arr[ln][p1+1]; //w?
p1++;
}
else
{
arr[id][p1+p2+2] = arr[rn][p2+1];
p2++;
}
}
}
void g(int id, int l, int r, int ll, int rr)
{
if(ll>r or l>rr) return;
if(ll<=l and r<=rr)
{
re = max(re, mx_inv[id]);
int lb = 0, rb = arr[id].size()-1;
while(lb<rb)
{
int mid = (lb+rb+1)/2;
if(arr[id][mid]<cur_mx) lb=mid;
else rb=mid-1;
}
if(arr[id][lb]<cur_mx) re = max(re, cur_mx+arr[id][lb]);
cur_mx = max(cur_mx, mx[id]);
}
else
{
g(ln, l, (l+r)/2, ll, rr);
g(rn, (l+r)/2+1, r, ll, rr);
}
}
int query(int l, int r)
{
re=0; cur_mx=0;
g(1, 1, n, l, r);
return re;
}
} IT(1);
signed main()
{
// freopen(".inp", "r", stdin);
// freopen(".out", "w", stdout);
fastio;
int n, q; cin>>n>>q; IT = it(n);
for(int i=1; i<=n; i++) cin>>a[i];
IT.build(1, 1, n);
while(q--)
{
int l, r, k;
cin>>l>>r>>k;
if(IT.query(l, r)>k) cout<<0;
else cout<<1;
cout<<endl;
}
}
Compilation message
sortbooks.cpp: In member function 'void it::build(int, int, int)':
sortbooks.cpp:68:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<arr[rn].size(); i++) if(arr[rn][i]<mx[ln])mx_inv[id] = max(mx_inv[id],mx[ln]+arr[rn][i]);
~^~~~~~~~~~~~~~~
sortbooks.cpp:70:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(p1+1<arr[ln].size() || p2+1<arr[rn].size())
~~~~^~~~~~~~~~~~~~~
sortbooks.cpp:70:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(p1+1<arr[ln].size() || p2+1<arr[rn].size())
~~~~^~~~~~~~~~~~~~~
sortbooks.cpp:72:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(p2+1>=arr[rn].size())
~~~~^~~~~~~~~~~~~~~~
sortbooks.cpp:77:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
else if(p1+1>=arr[ln].size())
~~~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
9 ms |
768 KB |
Output is correct |
12 |
Correct |
10 ms |
1792 KB |
Output is correct |
13 |
Correct |
12 ms |
1792 KB |
Output is correct |
14 |
Correct |
18 ms |
1792 KB |
Output is correct |
15 |
Correct |
18 ms |
1792 KB |
Output is correct |
16 |
Correct |
17 ms |
1848 KB |
Output is correct |
17 |
Correct |
15 ms |
1536 KB |
Output is correct |
18 |
Correct |
18 ms |
1792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
478 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
426 ms |
28152 KB |
Output is correct |
2 |
Correct |
396 ms |
30200 KB |
Output is correct |
3 |
Correct |
408 ms |
30096 KB |
Output is correct |
4 |
Correct |
395 ms |
30140 KB |
Output is correct |
5 |
Correct |
386 ms |
30072 KB |
Output is correct |
6 |
Correct |
346 ms |
29944 KB |
Output is correct |
7 |
Correct |
351 ms |
29948 KB |
Output is correct |
8 |
Correct |
364 ms |
29944 KB |
Output is correct |
9 |
Correct |
242 ms |
2044 KB |
Output is correct |
10 |
Correct |
372 ms |
29816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
9 ms |
768 KB |
Output is correct |
12 |
Correct |
10 ms |
1792 KB |
Output is correct |
13 |
Correct |
12 ms |
1792 KB |
Output is correct |
14 |
Correct |
18 ms |
1792 KB |
Output is correct |
15 |
Correct |
18 ms |
1792 KB |
Output is correct |
16 |
Correct |
17 ms |
1848 KB |
Output is correct |
17 |
Correct |
15 ms |
1536 KB |
Output is correct |
18 |
Correct |
18 ms |
1792 KB |
Output is correct |
19 |
Correct |
1010 ms |
63436 KB |
Output is correct |
20 |
Correct |
957 ms |
63252 KB |
Output is correct |
21 |
Correct |
841 ms |
63096 KB |
Output is correct |
22 |
Correct |
843 ms |
63096 KB |
Output is correct |
23 |
Correct |
846 ms |
63092 KB |
Output is correct |
24 |
Correct |
804 ms |
63352 KB |
Output is correct |
25 |
Correct |
797 ms |
63096 KB |
Output is correct |
26 |
Correct |
903 ms |
63352 KB |
Output is correct |
27 |
Correct |
919 ms |
63352 KB |
Output is correct |
28 |
Correct |
919 ms |
63352 KB |
Output is correct |
29 |
Correct |
940 ms |
63276 KB |
Output is correct |
30 |
Correct |
871 ms |
63372 KB |
Output is correct |
31 |
Correct |
906 ms |
63376 KB |
Output is correct |
32 |
Correct |
871 ms |
63224 KB |
Output is correct |
33 |
Correct |
889 ms |
63276 KB |
Output is correct |
34 |
Correct |
756 ms |
62840 KB |
Output is correct |
35 |
Correct |
808 ms |
62840 KB |
Output is correct |
36 |
Correct |
803 ms |
62840 KB |
Output is correct |
37 |
Correct |
765 ms |
62712 KB |
Output is correct |
38 |
Correct |
794 ms |
62824 KB |
Output is correct |
39 |
Correct |
846 ms |
61944 KB |
Output is correct |
40 |
Correct |
664 ms |
41720 KB |
Output is correct |
41 |
Correct |
814 ms |
61432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
9 ms |
768 KB |
Output is correct |
12 |
Correct |
10 ms |
1792 KB |
Output is correct |
13 |
Correct |
12 ms |
1792 KB |
Output is correct |
14 |
Correct |
18 ms |
1792 KB |
Output is correct |
15 |
Correct |
18 ms |
1792 KB |
Output is correct |
16 |
Correct |
17 ms |
1848 KB |
Output is correct |
17 |
Correct |
15 ms |
1536 KB |
Output is correct |
18 |
Correct |
18 ms |
1792 KB |
Output is correct |
19 |
Runtime error |
478 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
20 |
Halted |
0 ms |
0 KB |
- |