이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define all(s) s.begin(),s.end()
//#define int long long
using namespace std;
const int N = (1e6 + 12);
const int mod = (1e9 + 7);
const int INF = (0x3f3f3f3f);
int a[N], pos[N], l[N], r[N], k[N], t[N * 4], ans[N];
vector<int > vec[N];
void update(int v,int tl,int tr,int pos,int val){
if(tl == tr){
t[v] = val;
return;
}
int mid = (tl + tr) >> 1;
if(pos <= mid){
update(v + v, tl, mid, pos, val);
}
else{
update(v + v + 1, mid + 1, tr, pos, val);
}
t[v] = max(t[v + v], t[v + v + 1]);
}
int get(int v,int tl,int tr,int ll,int rr){
if(tl > rr || tr < ll){
return 0;
}
if(ll <= tl && tr <= rr){
return t[v];
}
int mid = (tl + tr) >> 1;
return max(get(v + v, tl, mid, ll, rr), get(v + v + 1, mid + 1, tr, ll, rr));
}
main()
{
int n, m;
scanf("%d%d", &n, &m);
for(int i = 1;i <= n; i++){
scanf("%d", &a[i]);
pos[i] = i - 1;
while(pos[i] && a[pos[i]] <= a[i]){
pos[i] = pos[pos[i]];
}
}
for(int i = 1;i <= m; i++){
scanf("%d%d%d", &l[i], &r[i], &k[i]);
vec[r[i]].pb(i);
}
for(int i = 1;i <= n; i++){
if(pos[i]){
update(1, 1, n, i, a[i] + a[pos[i]]);
}
for(auto to : vec[i]){
ans[to] = (get(1, 1, n, l[to], r[to]) <= k[to] ? 1 : 0);
}
}
for(int i = 1;i <= m; i++){
printf("%d\n", ans[i]);
}
}
컴파일 시 표준 에러 (stderr) 메시지
sortbooks.cpp:44:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main()
^
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:47:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~
sortbooks.cpp:49:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &a[i]);
~~~~~^~~~~~~~~~~~~
sortbooks.cpp:56:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &l[i], &r[i], &k[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |