이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pii pair<int,int>
#define fi first
#define se second
int INF=1000000000;
const int N=500000;
pii seg[2*N];
int eminusx[N];
int nx[N];
int n;
void build(){
for(int i=0;i<n;i++){
seg[i+n]=mp(eminusx[i],i);
}
for(int i=n-1;i>0;i--){
seg[i]=max(seg[2*i],seg[2*i+1]);
}
}
int query(int l,int r){
l+=n;
r+=n;
pii ans=mp(-INF,-INF);
while(l<r){
if(l&1){
ans=max(ans,seg[l]);
l++;
}
if(r&1){
r--;
ans=max(ans,seg[r]);
}
l>>=1;
r>>=1;
}
return ans.second;
}
void solve(){
cin >>n;
int x[n];
int e[n];
for(int i=0;i<n;i++){
cin >> x[i] >> e[i];
}
vector<pii> tosort;
for(int i=0;i<n;i++) tosort.push_back(mp(e[i]+x[i],e[i]-x[i]));
sort(tosort.begin(),tosort.end());
for(int i=0;i<n;i++) eminusx[i]=tosort[i].second;
build();
int cnt=0;
int ind=-1;
while(ind!=n-1){
ind=query(ind+1,n);
cnt++;
}
cout << cnt << "\n";
}
signed main(){
auto begin = std::chrono::high_resolution_clock::now();
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
t=1;
//cin >> t;
while(t--) solve();
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n";
}
# | 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... |