이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define sf scanf
#define pf printf
#define fi first
#define se second
#define INF 2023456789
typedef pair<int,int> ii;
#define maxn 200005
int n,x[maxn],e[maxn],d[maxn];
vector<int> v;
set<ii> s1;
struct node{
int s,e,m,v;
node *l,*r;
node(int _s,int _e){
s=_s,e=_e,m=(s+e)>>1,v=-INF;
if(s!=e)l=new node(s,m),r=new node(m+1,e);
}
void up(int x,int nv){
if(s==x&&e==x){v=nv;return;}
if(x<=m)l->up(x,nv);
else r->up(x,nv);
v=max(l->v,r->v);
}
int qry(int x,int y){
if(s==x&&e==y)return v;
if(y<=m)return l->qry(x,y);
else if(x>m)return r->qry(x,y);
else return max(l->qry(x,m),r->qry(m+1,y));
}
}*rt,*rt2;
int main(){
sf("%d",&n);
for(int i=0;i<n;++i){
sf("%d%d",&x[i],&e[i]);
v.push_back(x[i]);
s1.insert({e[i],i});
}
sort(v.begin(),v.end());
v.resize(unique(v.begin(),v.end())-v.begin());
for(int i=0;i<n;++i){
d[i]=lower_bound(v.begin(),v.end(),x[i])-v.begin();
}
rt=new node(0,v.size()-1);
rt2=new node(0,v.size()-1);
int ans=0;
while(!s1.empty()){
auto[_,i]=*--s1.end();
s1.erase(--s1.end());
if(e[i]+x[i]<=rt->qry(0,d[i]))continue;
if(e[i]-x[i]<=rt2->qry(d[i],v.size()-1))continue;
++ans;
rt->up(d[i],e[i]+x[i]);
rt2->up(d[i],e[i]-x[i]);
}
pf("%d\n",ans);
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:39:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | sf("%d",&n);
| ^
Main.cpp:41:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | sf("%d%d",&x[i],&e[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... |