이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// Problem: A - Hedgehog Daniyar and Algorithms
// Contest: Virtual Judge - IOI contest #3 (div 1 + 2)
// URL: https://vjudge.net/contest/610287#problem/A
// Memory Limit: 256 MB
// Time Limit: 3000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#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;
vector <int> g[maxn];
int ans[maxn];
deque <int> dq;
int a[maxn] , t[maxn * 4];
void upd(int v ,int tl , int tr , int pos , int val){
if(pos < tl || tr < pos) return;
if(tl == tr){
t[v] = max(val + a[pos], t[v]);
return;
}
int tm = tl + tr >> 1;
upd(v * 2 , tl , tm , pos , val);
upd(v * 2 + 1 ,tm + 1 , tr , pos , val);
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 , m;
cin >> n >> m;
for(int i = 1;i <= n;i++){
cin >> a[i];
while(!dq.empty() && a[dq.back()] <= a[i]){
dq.pop_back();
}
if(dq.empty()){
ans[i] = -1;
}
else ans[i] = dq.back();
dq.pb(i);
}
int res[m + 5];
int l[m + 5] , r[m + 5] , k[m + 5];
for(int i = 1;i <= m;i++){
cin>>l[i] >> r[i] >> k[i];
g[r[i]].pb(i);
}
for(int i = 1;i <= n;i++){
if(ans[i] != -1) upd(1 , 1 , n , ans[i] , a[i]);
for(auto to : g[i]){
res[to] = get(1 , 1 , n , l[to] , r[to]) > k[to] ? 0 : 1;
}
}
for(int i = 1;i <= m;i++){
cout<<res[i]<<ent;
}
}
signed main(){
give_me_more_speed
int tt = 1;
//cin>>t;
for(int i = 1;i <= tt;i++){
solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
sortbooks.cpp: In function 'void upd(long long int, long long int, long long int, long long int, long long int)':
sortbooks.cpp:37:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
37 | 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:46:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
46 | 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... |