#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int bk=800;
const int nmax=2e6+50;
const int mod=1e9+7;
using namespace std;
int n,m,a[nmax],mx,i,j,l,r,k,mxx,bukmx[nmax/bk],bukmn[nmax/bk],buk[nmax/bk],x;
vector<int>vc[nmax/bk];
void calc(int l,int r)
{
int mxx=0,mx=0,mn=inf;
for(int i=l;i<=r;i++)
{
if(a[i]<mx)mxx=max(mxx,a[i]+mx);
mx=max(mx,a[i]);
mn=min(mn,a[i]);
vc[l/bk].pb(a[i]);
}
buk[l/bk]=mxx;
bukmx[l/bk]=mx;
bukmn[l/bk]=mn;
sort(vc[l/bk].begin(),vc[l/bk].end());
}
int main()
{
//freopen("sol.in","r",stdin);
//freopen("sol.out","w",stdout);
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
cin>>n>>m;
for(i=0;i<n;i++)cin>>a[i];
for(i=0;i<n;i+=bk)
{
calc(i,min(i+bk-1,n-1));
}
while(m--)
{
cin>>l>>r>>k;
l--,r--;
mx=mxx=0;
for(i=l;i<=r;i++)
{
if(i%bk==0)break;
if(a[i]<mx)mxx=max(mxx,a[i]+mx);
mx=max(mx,a[i]);
}
for(;i+bk<=r;i+=bk)
{
mxx=max(mxx,buk[i/bk]);
if(bukmn[i/bk]<mx)
{
x=*(--upper_bound(vc[i/bk].begin(),vc[i/bk].end(),mx-1));
mxx=max(mxx,mx+x);
}
mx=max(mx,bukmx[i/bk]);
}
for(;i<=r;i++)
{
if(a[i]<mx)mxx=max(mxx,a[i]+mx);
mx=max(mx,a[i]);
}
if(mxx<=k)cout<<"1\n";
else cout<<"0\n";
}
return 0;
}
Compilation message
sortbooks.cpp:2:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization("O3")
sortbooks.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization("unroll-loops")
# |
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 |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
504 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 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 |
# |
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 |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
504 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 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 |
6 ms |
504 KB |
Output is correct |
12 |
Correct |
8 ms |
504 KB |
Output is correct |
13 |
Correct |
8 ms |
504 KB |
Output is correct |
14 |
Correct |
12 ms |
504 KB |
Output is correct |
15 |
Correct |
11 ms |
504 KB |
Output is correct |
16 |
Correct |
9 ms |
504 KB |
Output is correct |
17 |
Correct |
7 ms |
504 KB |
Output is correct |
18 |
Correct |
8 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3038 ms |
9844 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
290 ms |
1564 KB |
Output is correct |
2 |
Correct |
513 ms |
1676 KB |
Output is correct |
3 |
Correct |
183 ms |
1528 KB |
Output is correct |
4 |
Correct |
175 ms |
1500 KB |
Output is correct |
5 |
Correct |
182 ms |
1572 KB |
Output is correct |
6 |
Correct |
234 ms |
1592 KB |
Output is correct |
7 |
Correct |
240 ms |
1628 KB |
Output is correct |
8 |
Correct |
297 ms |
1528 KB |
Output is correct |
9 |
Correct |
70 ms |
636 KB |
Output is correct |
10 |
Correct |
267 ms |
1680 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 |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
504 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 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 |
6 ms |
504 KB |
Output is correct |
12 |
Correct |
8 ms |
504 KB |
Output is correct |
13 |
Correct |
8 ms |
504 KB |
Output is correct |
14 |
Correct |
12 ms |
504 KB |
Output is correct |
15 |
Correct |
11 ms |
504 KB |
Output is correct |
16 |
Correct |
9 ms |
504 KB |
Output is correct |
17 |
Correct |
7 ms |
504 KB |
Output is correct |
18 |
Correct |
8 ms |
504 KB |
Output is correct |
19 |
Correct |
735 ms |
2780 KB |
Output is correct |
20 |
Correct |
729 ms |
2768 KB |
Output is correct |
21 |
Correct |
1560 ms |
2792 KB |
Output is correct |
22 |
Correct |
1511 ms |
2808 KB |
Output is correct |
23 |
Correct |
1590 ms |
2820 KB |
Output is correct |
24 |
Correct |
488 ms |
2680 KB |
Output is correct |
25 |
Correct |
486 ms |
2684 KB |
Output is correct |
26 |
Correct |
453 ms |
2680 KB |
Output is correct |
27 |
Correct |
609 ms |
2692 KB |
Output is correct |
28 |
Correct |
457 ms |
2620 KB |
Output is correct |
29 |
Correct |
390 ms |
2680 KB |
Output is correct |
30 |
Correct |
381 ms |
2680 KB |
Output is correct |
31 |
Correct |
390 ms |
2808 KB |
Output is correct |
32 |
Correct |
389 ms |
2556 KB |
Output is correct |
33 |
Correct |
390 ms |
2792 KB |
Output is correct |
34 |
Correct |
516 ms |
2680 KB |
Output is correct |
35 |
Correct |
519 ms |
2772 KB |
Output is correct |
36 |
Correct |
518 ms |
2680 KB |
Output is correct |
37 |
Correct |
530 ms |
2808 KB |
Output is correct |
38 |
Correct |
523 ms |
2680 KB |
Output is correct |
39 |
Correct |
751 ms |
2752 KB |
Output is correct |
40 |
Correct |
437 ms |
2168 KB |
Output is correct |
41 |
Correct |
797 ms |
2808 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 |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
504 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 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 |
6 ms |
504 KB |
Output is correct |
12 |
Correct |
8 ms |
504 KB |
Output is correct |
13 |
Correct |
8 ms |
504 KB |
Output is correct |
14 |
Correct |
12 ms |
504 KB |
Output is correct |
15 |
Correct |
11 ms |
504 KB |
Output is correct |
16 |
Correct |
9 ms |
504 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 |
3038 ms |
9844 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |