#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include<bitset>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<pii,int>
#define vi vector<int>
#define pb push_back
//#define p push
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
#pragma GCC optimize ("03,unroll-lopps")
const int mxn=1e6+10,inf=1e9;
int n,m;
struct seg{
int v[2*mxn+10];
void update(int pos,int val){
pos+=n;
v[pos]=max(v[pos],val);
for(;pos>0;pos>>=1)v[pos>>1]=max(v[pos],v[pos^1]);
}
int qry(int l,int r){
int ans=0;
for(l+=n,r+=n;l<=r;l>>=1,r>>=1){
if(l&1)ans=max(ans,v[l++]);
if(!(r&1))ans=max(ans,v[r--]);
}
return ans;
}
}t;
int32_t main(){
cin>>n>>m;
vector<int>v(n);
for(int i=0;i<n;i++)cin>>v[i];
vector<ppii>g;
vector<pair<pii,pii>>q(m);
for(int i=0;i<m;i++)cin>>q[i].f.f>>q[i].f.s>>q[i].s.f,q[i].s.s=i,q[i].f.f--,q[i].f.s--;
stack<int>st;
for(int i=0;i<n;i++){
while(!st.empty()&&v[st.top()]<=v[i])st.pop();
if(!st.empty())g.pb({{st.top(),i},v[i]+v[st.top()]});
st.push(i);
}
sort(rall(g));
sort(rall(q));
vector<int>ans(m,0);
int cur=0;
for(int i=0;i<m;i++){
while(cur<g.size()&&g[cur].f.f>=q[i].f.f)t.update(g[cur].f.s,g[cur].s),cur++;
ans[q[i].s.s]=(t.qry(0,q[i].f.s)<=q[i].s.f);
}
for(auto i:ans)cout<<i<<'\n';
}
Compilation message
sortbooks.cpp:35:40: warning: bad option '-funroll-lopps' to pragma 'optimize' [-Wpragmas]
35 | #pragma GCC optimize ("03,unroll-lopps")
| ^
sortbooks.cpp:40:32: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
40 | void update(int pos,int val){
| ^
sortbooks.cpp:45:24: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
45 | int qry(int l,int r){
| ^
sortbooks.cpp:54:14: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
54 | int32_t main(){
| ^
sortbooks.cpp: In function 'int32_t main()':
sortbooks.cpp:72:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | while(cur<g.size()&&g[cur].f.f>=q[i].f.f)t.update(g[cur].f.s,g[cur].s),cur++;
| ~~~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
452 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
452 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
3 ms |
604 KB |
Output is correct |
12 |
Correct |
5 ms |
560 KB |
Output is correct |
13 |
Correct |
5 ms |
616 KB |
Output is correct |
14 |
Correct |
6 ms |
684 KB |
Output is correct |
15 |
Correct |
7 ms |
960 KB |
Output is correct |
16 |
Correct |
5 ms |
600 KB |
Output is correct |
17 |
Correct |
5 ms |
600 KB |
Output is correct |
18 |
Correct |
4 ms |
708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1305 ms |
77712 KB |
Output is correct |
2 |
Correct |
1354 ms |
78660 KB |
Output is correct |
3 |
Correct |
1369 ms |
78264 KB |
Output is correct |
4 |
Correct |
1301 ms |
78380 KB |
Output is correct |
5 |
Correct |
1225 ms |
58836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
98 ms |
6732 KB |
Output is correct |
2 |
Correct |
102 ms |
6860 KB |
Output is correct |
3 |
Correct |
96 ms |
4944 KB |
Output is correct |
4 |
Correct |
90 ms |
4804 KB |
Output is correct |
5 |
Correct |
92 ms |
4944 KB |
Output is correct |
6 |
Correct |
92 ms |
5140 KB |
Output is correct |
7 |
Correct |
91 ms |
5308 KB |
Output is correct |
8 |
Correct |
85 ms |
5972 KB |
Output is correct |
9 |
Correct |
67 ms |
3916 KB |
Output is correct |
10 |
Correct |
86 ms |
5836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
452 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
3 ms |
604 KB |
Output is correct |
12 |
Correct |
5 ms |
560 KB |
Output is correct |
13 |
Correct |
5 ms |
616 KB |
Output is correct |
14 |
Correct |
6 ms |
684 KB |
Output is correct |
15 |
Correct |
7 ms |
960 KB |
Output is correct |
16 |
Correct |
5 ms |
600 KB |
Output is correct |
17 |
Correct |
5 ms |
600 KB |
Output is correct |
18 |
Correct |
4 ms |
708 KB |
Output is correct |
19 |
Correct |
261 ms |
15852 KB |
Output is correct |
20 |
Correct |
261 ms |
15812 KB |
Output is correct |
21 |
Correct |
259 ms |
16068 KB |
Output is correct |
22 |
Correct |
251 ms |
15812 KB |
Output is correct |
23 |
Correct |
250 ms |
15812 KB |
Output is correct |
24 |
Correct |
232 ms |
11856 KB |
Output is correct |
25 |
Correct |
238 ms |
11856 KB |
Output is correct |
26 |
Correct |
246 ms |
12240 KB |
Output is correct |
27 |
Correct |
253 ms |
11856 KB |
Output is correct |
28 |
Correct |
247 ms |
12212 KB |
Output is correct |
29 |
Correct |
238 ms |
12116 KB |
Output is correct |
30 |
Correct |
259 ms |
12016 KB |
Output is correct |
31 |
Correct |
256 ms |
12084 KB |
Output is correct |
32 |
Correct |
244 ms |
11996 KB |
Output is correct |
33 |
Correct |
250 ms |
12048 KB |
Output is correct |
34 |
Correct |
238 ms |
11764 KB |
Output is correct |
35 |
Correct |
237 ms |
11632 KB |
Output is correct |
36 |
Correct |
240 ms |
11384 KB |
Output is correct |
37 |
Correct |
243 ms |
11344 KB |
Output is correct |
38 |
Correct |
248 ms |
11636 KB |
Output is correct |
39 |
Correct |
226 ms |
11980 KB |
Output is correct |
40 |
Correct |
188 ms |
10340 KB |
Output is correct |
41 |
Correct |
203 ms |
12520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
452 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
3 ms |
604 KB |
Output is correct |
12 |
Correct |
5 ms |
560 KB |
Output is correct |
13 |
Correct |
5 ms |
616 KB |
Output is correct |
14 |
Correct |
6 ms |
684 KB |
Output is correct |
15 |
Correct |
7 ms |
960 KB |
Output is correct |
16 |
Correct |
5 ms |
600 KB |
Output is correct |
17 |
Correct |
5 ms |
600 KB |
Output is correct |
18 |
Correct |
4 ms |
708 KB |
Output is correct |
19 |
Correct |
1305 ms |
77712 KB |
Output is correct |
20 |
Correct |
1354 ms |
78660 KB |
Output is correct |
21 |
Correct |
1369 ms |
78264 KB |
Output is correct |
22 |
Correct |
1301 ms |
78380 KB |
Output is correct |
23 |
Correct |
1225 ms |
58836 KB |
Output is correct |
24 |
Correct |
98 ms |
6732 KB |
Output is correct |
25 |
Correct |
102 ms |
6860 KB |
Output is correct |
26 |
Correct |
96 ms |
4944 KB |
Output is correct |
27 |
Correct |
90 ms |
4804 KB |
Output is correct |
28 |
Correct |
92 ms |
4944 KB |
Output is correct |
29 |
Correct |
92 ms |
5140 KB |
Output is correct |
30 |
Correct |
91 ms |
5308 KB |
Output is correct |
31 |
Correct |
85 ms |
5972 KB |
Output is correct |
32 |
Correct |
67 ms |
3916 KB |
Output is correct |
33 |
Correct |
86 ms |
5836 KB |
Output is correct |
34 |
Correct |
261 ms |
15852 KB |
Output is correct |
35 |
Correct |
261 ms |
15812 KB |
Output is correct |
36 |
Correct |
259 ms |
16068 KB |
Output is correct |
37 |
Correct |
251 ms |
15812 KB |
Output is correct |
38 |
Correct |
250 ms |
15812 KB |
Output is correct |
39 |
Correct |
232 ms |
11856 KB |
Output is correct |
40 |
Correct |
238 ms |
11856 KB |
Output is correct |
41 |
Correct |
246 ms |
12240 KB |
Output is correct |
42 |
Correct |
253 ms |
11856 KB |
Output is correct |
43 |
Correct |
247 ms |
12212 KB |
Output is correct |
44 |
Correct |
238 ms |
12116 KB |
Output is correct |
45 |
Correct |
259 ms |
12016 KB |
Output is correct |
46 |
Correct |
256 ms |
12084 KB |
Output is correct |
47 |
Correct |
244 ms |
11996 KB |
Output is correct |
48 |
Correct |
250 ms |
12048 KB |
Output is correct |
49 |
Correct |
238 ms |
11764 KB |
Output is correct |
50 |
Correct |
237 ms |
11632 KB |
Output is correct |
51 |
Correct |
240 ms |
11384 KB |
Output is correct |
52 |
Correct |
243 ms |
11344 KB |
Output is correct |
53 |
Correct |
248 ms |
11636 KB |
Output is correct |
54 |
Correct |
226 ms |
11980 KB |
Output is correct |
55 |
Correct |
188 ms |
10340 KB |
Output is correct |
56 |
Correct |
203 ms |
12520 KB |
Output is correct |
57 |
Correct |
1480 ms |
78884 KB |
Output is correct |
58 |
Correct |
1365 ms |
79004 KB |
Output is correct |
59 |
Correct |
1340 ms |
78880 KB |
Output is correct |
60 |
Correct |
1401 ms |
78936 KB |
Output is correct |
61 |
Correct |
1398 ms |
78880 KB |
Output is correct |
62 |
Correct |
1358 ms |
78964 KB |
Output is correct |
63 |
Correct |
1256 ms |
57340 KB |
Output is correct |
64 |
Correct |
1283 ms |
57356 KB |
Output is correct |
65 |
Correct |
1298 ms |
59376 KB |
Output is correct |
66 |
Correct |
1278 ms |
59332 KB |
Output is correct |
67 |
Correct |
1303 ms |
59112 KB |
Output is correct |
68 |
Correct |
1315 ms |
59324 KB |
Output is correct |
69 |
Correct |
1257 ms |
59460 KB |
Output is correct |
70 |
Correct |
1313 ms |
59320 KB |
Output is correct |
71 |
Correct |
1285 ms |
59272 KB |
Output is correct |
72 |
Correct |
1243 ms |
59252 KB |
Output is correct |
73 |
Correct |
1200 ms |
36616 KB |
Output is correct |
74 |
Correct |
1199 ms |
29944 KB |
Output is correct |
75 |
Correct |
1165 ms |
29984 KB |
Output is correct |
76 |
Correct |
1183 ms |
29956 KB |
Output is correct |
77 |
Correct |
1154 ms |
29984 KB |
Output is correct |
78 |
Correct |
1160 ms |
34184 KB |
Output is correct |
79 |
Correct |
932 ms |
26676 KB |
Output is correct |
80 |
Correct |
1053 ms |
40104 KB |
Output is correct |