/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <stack>
#include <cassert>
#include <iterator>
#include <bitset>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(),v.end()
using namespace std;
char readchar() {
char c = getchar();
while (c <= 33) {
c = getchar();
}
return c;
}
int readint() {
char c = getchar();
while (c <= 33) {
c = getchar();
}
bool sign = false;
if (c == '-') {
sign = true;
c = getchar();
}
int t = 0;
while (c >= '0' && c <= '9') {
t = (t << 3) + (t << 1) + c - '0';
c = getchar();
}
return (sign ? -t: t);
}
int n,m,a[1000006],wmin;
int ans;
vector<int> g[4*1000006];
int t[4*1000006],mn[4*1000006],mx[4*1000006];
int mergeSerge(vector<int>& a,vector<int>& b,vector<int> &c)
{
int p=0,q=0,d=0;
for(int i=0;i<b.size();i++)
if(b[i]<a.back())
d=a.back()+b[i];
while(p<a.size())
{
while(q<b.size() && b[q]<a[p])
c.PB(b[q++]);
c.PB(a[p++]);
}
while(q<b.size())
c.PB(b[q++]);
return d;
}
void build(int v,int l,int r)
{
if(l==r)
{
t[v]=a[l];
mn[v]=a[l];
g[v].PB(a[l]);
return;
}
int m=(l+r)/2;
build(v*2,l,m);
build(v*2+1,m+1,r);
mx[v]=mergeSerge(g[v*2],g[v*2+1],g[v]);
mx[v]=max(mx[v],max(mx[v*2],mx[v*2+1]));
t[v]=max(t[v*2],t[v*2+1]);
mn[v]=min(mn[v*2],mn[v*2+1]);
}
int get(int v,int l,int r,int i,int j,int lmax)
{
if(i>j)
return -1;
if(l==i && r==j)
{
//cout<<"["<<l<<":"<<r<<"]"<<" "<<lmax<<endl;
if(g[v][0]<lmax)
ans=max(ans,lmax+(*(lower_bound(all(g[v]),lmax)-1)));
ans=max(ans,mx[v]);
return t[v];
}
int m=(l+r)>>1;
int p1,p2;
p1=get(v*2,l,m,i,min(j,m),lmax);
lmax=max(lmax,p1);
p2=get(v*2+1,m+1,r,max(m+1,i),j,lmax);
lmax=max(lmax,p2);
return lmax;
}
pair<int,int> get2(int v,int l,int r,int i,int j)
{
if(i>j)
return MP(-1,mod);
if(l==i && r==j)
{
ans|=(bool)(mx[v]);
return MP(t[v],mn[v]);
}
int m=(l+r)>>1;
pair<int,int> p1,p2;
p1=get2(v*2,l,m,i,min(j,m));
p2=get2(v*2+1,m+1,r,max(m+1,i),j);
if(j<=m)
return p1;
else if(i>=m+1)
return p2;
else
{
if(p1.first>p2.second)
ans=1;
return MP(max(p1.first,p2.first),min(p1.second,p2.second));
}
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
a[i]=readint();
wmin=a[1];
for(int i=1;i<=n;i++)
wmin=min(a[i],wmin);
build(1,1,n);
while(m--)
{
int l,r,k;
ans=0;
// scanf("%d%d%d",&l,&r,&k);
l=readint();
r=readint();
k=readint();
if(k<wmin)
{
get2(1,1,n,l,r);
printf("%d",(ans==0));
}
else
{
get(1,1,n,l,r,-1);
printf("%c",'0'+(k>=ans));
}
putchar(10);
}
return 0;
}
/*
5 10
2 1 1 1 2
1 5 0
2 5 0
1 4 0
2 4 0
1 5 3
*/
Compilation message
sortbooks.cpp: In function 'int mergeSerge(std::vector<int>&, std::vector<int>&, std::vector<int>&)':
sortbooks.cpp:62:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<b.size();i++)
~^~~~~~~~~
sortbooks.cpp:65:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(p<a.size())
~^~~~~~~~~
sortbooks.cpp:67:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(q<b.size() && b[q]<a[p])
~^~~~~~~~~
sortbooks.cpp:71:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(q<b.size())
~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
90 ms |
94436 KB |
Output is correct |
2 |
Correct |
89 ms |
94320 KB |
Output is correct |
3 |
Correct |
89 ms |
94328 KB |
Output is correct |
4 |
Correct |
89 ms |
94328 KB |
Output is correct |
5 |
Correct |
89 ms |
94328 KB |
Output is correct |
6 |
Correct |
89 ms |
94328 KB |
Output is correct |
7 |
Correct |
89 ms |
94328 KB |
Output is correct |
8 |
Correct |
91 ms |
94408 KB |
Output is correct |
9 |
Correct |
90 ms |
94328 KB |
Output is correct |
10 |
Correct |
90 ms |
94328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
90 ms |
94436 KB |
Output is correct |
2 |
Correct |
89 ms |
94320 KB |
Output is correct |
3 |
Correct |
89 ms |
94328 KB |
Output is correct |
4 |
Correct |
89 ms |
94328 KB |
Output is correct |
5 |
Correct |
89 ms |
94328 KB |
Output is correct |
6 |
Correct |
89 ms |
94328 KB |
Output is correct |
7 |
Correct |
89 ms |
94328 KB |
Output is correct |
8 |
Correct |
91 ms |
94408 KB |
Output is correct |
9 |
Correct |
90 ms |
94328 KB |
Output is correct |
10 |
Correct |
90 ms |
94328 KB |
Output is correct |
11 |
Correct |
93 ms |
94584 KB |
Output is correct |
12 |
Correct |
95 ms |
95224 KB |
Output is correct |
13 |
Correct |
103 ms |
95268 KB |
Output is correct |
14 |
Correct |
108 ms |
95356 KB |
Output is correct |
15 |
Correct |
97 ms |
95352 KB |
Output is correct |
16 |
Correct |
95 ms |
95300 KB |
Output is correct |
17 |
Correct |
93 ms |
94968 KB |
Output is correct |
18 |
Correct |
95 ms |
95280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2392 ms |
262144 KB |
Output is correct |
2 |
Correct |
2339 ms |
262144 KB |
Output is correct |
3 |
Correct |
2370 ms |
262144 KB |
Output is correct |
4 |
Correct |
2368 ms |
262144 KB |
Output is correct |
5 |
Correct |
2214 ms |
262144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
326 ms |
112628 KB |
Output is correct |
2 |
Correct |
299 ms |
112864 KB |
Output is correct |
3 |
Correct |
258 ms |
112624 KB |
Output is correct |
4 |
Correct |
289 ms |
112624 KB |
Output is correct |
5 |
Correct |
284 ms |
112724 KB |
Output is correct |
6 |
Correct |
244 ms |
112496 KB |
Output is correct |
7 |
Correct |
233 ms |
112568 KB |
Output is correct |
8 |
Correct |
247 ms |
112380 KB |
Output is correct |
9 |
Correct |
125 ms |
95864 KB |
Output is correct |
10 |
Correct |
246 ms |
112368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
90 ms |
94436 KB |
Output is correct |
2 |
Correct |
89 ms |
94320 KB |
Output is correct |
3 |
Correct |
89 ms |
94328 KB |
Output is correct |
4 |
Correct |
89 ms |
94328 KB |
Output is correct |
5 |
Correct |
89 ms |
94328 KB |
Output is correct |
6 |
Correct |
89 ms |
94328 KB |
Output is correct |
7 |
Correct |
89 ms |
94328 KB |
Output is correct |
8 |
Correct |
91 ms |
94408 KB |
Output is correct |
9 |
Correct |
90 ms |
94328 KB |
Output is correct |
10 |
Correct |
90 ms |
94328 KB |
Output is correct |
11 |
Correct |
93 ms |
94584 KB |
Output is correct |
12 |
Correct |
95 ms |
95224 KB |
Output is correct |
13 |
Correct |
103 ms |
95268 KB |
Output is correct |
14 |
Correct |
108 ms |
95356 KB |
Output is correct |
15 |
Correct |
97 ms |
95352 KB |
Output is correct |
16 |
Correct |
95 ms |
95300 KB |
Output is correct |
17 |
Correct |
93 ms |
94968 KB |
Output is correct |
18 |
Correct |
95 ms |
95280 KB |
Output is correct |
19 |
Correct |
768 ms |
133740 KB |
Output is correct |
20 |
Correct |
710 ms |
133688 KB |
Output is correct |
21 |
Correct |
578 ms |
133228 KB |
Output is correct |
22 |
Correct |
612 ms |
133996 KB |
Output is correct |
23 |
Correct |
580 ms |
132824 KB |
Output is correct |
24 |
Correct |
460 ms |
132624 KB |
Output is correct |
25 |
Correct |
449 ms |
132460 KB |
Output is correct |
26 |
Correct |
487 ms |
131072 KB |
Output is correct |
27 |
Correct |
497 ms |
130924 KB |
Output is correct |
28 |
Correct |
501 ms |
131024 KB |
Output is correct |
29 |
Correct |
514 ms |
131136 KB |
Output is correct |
30 |
Correct |
519 ms |
131052 KB |
Output is correct |
31 |
Correct |
537 ms |
131436 KB |
Output is correct |
32 |
Correct |
541 ms |
131828 KB |
Output is correct |
33 |
Correct |
577 ms |
133228 KB |
Output is correct |
34 |
Correct |
391 ms |
132852 KB |
Output is correct |
35 |
Correct |
391 ms |
132844 KB |
Output is correct |
36 |
Correct |
389 ms |
131228 KB |
Output is correct |
37 |
Correct |
404 ms |
131180 KB |
Output is correct |
38 |
Correct |
389 ms |
130852 KB |
Output is correct |
39 |
Correct |
476 ms |
133228 KB |
Output is correct |
40 |
Correct |
349 ms |
118116 KB |
Output is correct |
41 |
Correct |
489 ms |
132664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
90 ms |
94436 KB |
Output is correct |
2 |
Correct |
89 ms |
94320 KB |
Output is correct |
3 |
Correct |
89 ms |
94328 KB |
Output is correct |
4 |
Correct |
89 ms |
94328 KB |
Output is correct |
5 |
Correct |
89 ms |
94328 KB |
Output is correct |
6 |
Correct |
89 ms |
94328 KB |
Output is correct |
7 |
Correct |
89 ms |
94328 KB |
Output is correct |
8 |
Correct |
91 ms |
94408 KB |
Output is correct |
9 |
Correct |
90 ms |
94328 KB |
Output is correct |
10 |
Correct |
90 ms |
94328 KB |
Output is correct |
11 |
Correct |
93 ms |
94584 KB |
Output is correct |
12 |
Correct |
95 ms |
95224 KB |
Output is correct |
13 |
Correct |
103 ms |
95268 KB |
Output is correct |
14 |
Correct |
108 ms |
95356 KB |
Output is correct |
15 |
Correct |
97 ms |
95352 KB |
Output is correct |
16 |
Correct |
95 ms |
95300 KB |
Output is correct |
17 |
Correct |
93 ms |
94968 KB |
Output is correct |
18 |
Correct |
95 ms |
95280 KB |
Output is correct |
19 |
Correct |
2392 ms |
262144 KB |
Output is correct |
20 |
Correct |
2339 ms |
262144 KB |
Output is correct |
21 |
Correct |
2370 ms |
262144 KB |
Output is correct |
22 |
Correct |
2368 ms |
262144 KB |
Output is correct |
23 |
Correct |
2214 ms |
262144 KB |
Output is correct |
24 |
Correct |
326 ms |
112628 KB |
Output is correct |
25 |
Correct |
299 ms |
112864 KB |
Output is correct |
26 |
Correct |
258 ms |
112624 KB |
Output is correct |
27 |
Correct |
289 ms |
112624 KB |
Output is correct |
28 |
Correct |
284 ms |
112724 KB |
Output is correct |
29 |
Correct |
244 ms |
112496 KB |
Output is correct |
30 |
Correct |
233 ms |
112568 KB |
Output is correct |
31 |
Correct |
247 ms |
112380 KB |
Output is correct |
32 |
Correct |
125 ms |
95864 KB |
Output is correct |
33 |
Correct |
246 ms |
112368 KB |
Output is correct |
34 |
Correct |
768 ms |
133740 KB |
Output is correct |
35 |
Correct |
710 ms |
133688 KB |
Output is correct |
36 |
Correct |
578 ms |
133228 KB |
Output is correct |
37 |
Correct |
612 ms |
133996 KB |
Output is correct |
38 |
Correct |
580 ms |
132824 KB |
Output is correct |
39 |
Correct |
460 ms |
132624 KB |
Output is correct |
40 |
Correct |
449 ms |
132460 KB |
Output is correct |
41 |
Correct |
487 ms |
131072 KB |
Output is correct |
42 |
Correct |
497 ms |
130924 KB |
Output is correct |
43 |
Correct |
501 ms |
131024 KB |
Output is correct |
44 |
Correct |
514 ms |
131136 KB |
Output is correct |
45 |
Correct |
519 ms |
131052 KB |
Output is correct |
46 |
Correct |
537 ms |
131436 KB |
Output is correct |
47 |
Correct |
541 ms |
131828 KB |
Output is correct |
48 |
Correct |
577 ms |
133228 KB |
Output is correct |
49 |
Correct |
391 ms |
132852 KB |
Output is correct |
50 |
Correct |
391 ms |
132844 KB |
Output is correct |
51 |
Correct |
389 ms |
131228 KB |
Output is correct |
52 |
Correct |
404 ms |
131180 KB |
Output is correct |
53 |
Correct |
389 ms |
130852 KB |
Output is correct |
54 |
Correct |
476 ms |
133228 KB |
Output is correct |
55 |
Correct |
349 ms |
118116 KB |
Output is correct |
56 |
Correct |
489 ms |
132664 KB |
Output is correct |
57 |
Execution timed out |
3046 ms |
262144 KB |
Time limit exceeded |
58 |
Halted |
0 ms |
0 KB |
- |