이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define S second
#define F first
#define sz size()
#define int long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define yes "YES\n"
#define no "NO\n"
#define ent "\n"
#define give_me_more_speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int maxn = 1e6 + 5, mod = 1e9 + 7;
int pref[maxn];
int a[maxn] , t[maxn * 4];
void build(int v ,int tl , int tr){
if(tl == tr){
t[v] = a[tl];
return;
}
int tm = tl + tr >> 1;
build(v * 2, tl ,tm);
build(v * 2 + 1 , tm + 1 , tr);
t[v] = max(t[v * 2] , t[v * 2 + 1]);
}
int get(int v ,int tl , int tr , int l , int r){
if(tl > r || l > tr) return 0;
if(l <= tl && tr <= r) return t[v];
int tm = tl + tr >> 1;
return max(get(v * 2 , tl , tm , l , r) , get(v * 2 + 1, tm + 1 , tr , l , r));
}
void solve(){
int n , q;
cin >> n >> q;
pref[1] = 0;
for(int i = 1;i <= n;i++){
cin >> a[i];
if(i > 1){
pref[i] = pref[i - 1] + (a[i - 1] <= a[i]);
}
}
build(1 , 1 , n);
int mn = *min_element(a + 1,a + 1 + n);
// cout<<mn<<ent;
while(q--){
int l , r , k;
cin >> l >> r >> k;
if(k < mn){
// cout<<pref[r] - pref[l]<<ent;
if(pref[r] - pref[l] == (r - l)){
cout<<1<<ent;
}
else cout<<0<<ent;
continue;
}
int ok = 1;
for(int i = l + 1;i <= r;i++){
int mx = get(1 , 1 , n, l , i - 1);
if(mx + a[i] > k && mx > a[i]){
ok = 0;
break;
}
}
cout<<ok<<ent;
}
}
signed main(){
give_me_more_speed
int t = 1;
//cin>>t;
for(int i = 1;i <= t;i++){
solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
sortbooks.cpp: In function 'void build(long long int, long long int, long long int)':
sortbooks.cpp:26:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
26 | int tm = tl + tr >> 1;
| ~~~^~~~
sortbooks.cpp: In function 'long long int get(long long int, long long int, long long int, long long int, long long int)':
sortbooks.cpp:35:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
35 | int tm = tl + tr >> 1;
| ~~~^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |