이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#define DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}
// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
public:
template<typename T>
_Debug& operator,(T val) {
cout << val << endl;
return *this;
}
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif
// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back
// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;
// ---------- END OF TEMPLATE ----------
struct event { int x,l,r,t; };
bool comp(event a,event b) {
if (a.x == b.x) return a.t > b.t;
else return a.x > b.x;
}
int H[200000],A[200000],B[200000],L[200000],R[200000];
int ans[200000];
vector<event> events;
int tree[1 << 19],best[1 << 19],lazy[1 << 19];
int build(int s,int e,int i) {
if (s == e) {
tree[i] = best[i] = -1,lazy[i] = 1e9;
return 0;
}
int mid = (s+e) / 2;
build(s,mid,2*i+1),build(mid+1,e,2*i+2);
tree[i] = best[i] = -1,lazy[i] = 1e9;
return 0;
}
int prop(int s,int e,int i) {
best[i] = max(best[i],tree[i]-lazy[i]);
if (s != e) lazy[2*i+1] = min(lazy[2*i+1],lazy[i]),lazy[2*i+2] = min(lazy[2*i+2],lazy[i]);
lazy[i] = 1e9;
return 0;
}
int update(int s,int e,int ai,int i,int num) {
prop(s,e,i);
if ((s > ai) || (e < ai)) return 0;
else if (s == e) {
tree[i] = num;
return 0;
}
int mid = (s+e) / 2;
update(s,mid,ai,2*i+1,num),update(mid+1,e,ai,2*i+2,num);
tree[i] = max(tree[2*i+1],tree[2*i+2]);
return 0;
}
int update2(int s,int e,int as,int ae,int i,int num) {
prop(s,e,i);
if ((s > ae) || (e < as)) return 0;
else if ((s >= as) && (e <= ae)) {
lazy[i] = min(lazy[i],num);
prop(s,e,i);
return 0;
}
int mid = (s+e) / 2;
update2(s,mid,as,ae,2*i+1,num),update2(mid+1,e,as,ae,2*i+2,num);
best[i] = max(best[i],max(best[2*i+1],best[2*i+2]));
return 0;
}
int query(int s,int e,int qs,int qe,int i) {
prop(s,e,i);
if ((s > qe) || (e < qs)) return -1;
else if ((s >= qs) && (e <= qe)) return best[i];
int mid = (s+e) / 2;
return max(query(s,mid,qs,qe,2*i+1),query(mid+1,e,qs,qe,2*i+2));
}
int main() {
int i;
int N,Q;
scanf("%d",&N);
for (i = 0; i < N; i++) scanf("%d %d %d",&H[i],&A[i],&B[i]);
scanf("%d",&Q);
for (i = 0; i < Q; i++) scanf("%d %d",&L[i],&R[i]),L[i]--,R[i]--;
int j,r;
fill(ans,ans+Q,-1);
for (r = 0; r < 2; r++) {
for (i = 0; i < N; i++) {
events.pb((event){i-A[i],i,i,1});
events.pb((event){i-B[i],i,i,-1});
events.pb((event){i,i+A[i],i+B[i],0});
}
for (i = 0; i < Q; i++) events.pb((event){L[i],i,R[i],-2});
sort(events.begin(),events.end(),comp);
build(0,N-1,0);
for (i = 0; i < events.size(); i++) {
if (events[i].t == 1) update(0,N-1,events[i].l,0,H[events[i].l]);
else if (events[i].t == -1) update(0,N-1,events[i].l,0,-1);
else if (events[i].t == 0) update2(0,N-1,events[i].l,events[i].r,0,H[events[i].x]);
else ans[events[i].l] = max(ans[events[i].l],query(0,N-1,0,events[i].r,0));
}
events.clear();
for (i = 0; i < Q; i++) L[i] = N-L[i]-1,R[i] = N-R[i]-1,swap(L[i],R[i]);
reverse(A,A+N),reverse(B,B+N),reverse(H,H+N);
}
for (i = 0; i < Q; i++) printf("%d\n",ans[i]);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
antennas.cpp: In function 'int main()':
antennas.cpp:138:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < events.size(); i++) {
~~^~~~~~~~~~~~~~~
antennas.cpp:127:9: warning: unused variable 'j' [-Wunused-variable]
int j,r;
^
antennas.cpp:122:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&N);
~~~~~^~~~~~~~~
antennas.cpp:123:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for (i = 0; i < N; i++) scanf("%d %d %d",&H[i],&A[i],&B[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
antennas.cpp:124:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&Q);
~~~~~^~~~~~~~~
antennas.cpp:125:62: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for (i = 0; i < Q; i++) scanf("%d %d",&L[i],&R[i]),L[i]--,R[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... |