이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MAX=5e5+10,P=1e9+7;
const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f;
int n;
pii res[MAX]; // power,pos
int main() {
speed;
cin>>n;
for (int i=0;i<n;i++) {
cin>>res[i].second>>res[i].first;
}
sort(res,res+n);
set<pii> rh,lh;
rh.insert({res[n-1].second,res[n-1].first});
lh.insert({res[n-1].second,res[n-1].first});
int ans=1;
for (int i=n-2;i>=0;i--) {
// cout<<"dsgdgfsgfg\n"<<flush;
auto it=rh.lower_bound(make_pair(res[i].second,0));
if (it!=rh.end()) {
auto [pos,pwr]=*it;
if (pos-res[i].second<=pwr-res[i].first) continue;
}
it=lh.upper_bound(make_pair(res[i].second,0));
if (it!=lh.begin()) {
auto [pos,pwr]=*prev(it);
if (res[i].second-pos<=pwr-res[i].first) continue;
}
// cout<<"dsgdgfsgfg\n"<<flush;
ans++;
it=rh.insert({res[i].second,res[i].first}).first;
while (it!=rh.begin()) {
it--;
auto [pos,pwr]=*it;
if (res[i].second-pos<=res[i].first-pwr) {
it=rh.erase(it);
} else break;
}
it=lh.insert({res[i].second,res[i].first}).first;
it++;
// cout<<"dsgdgfsgfg\n"<<flush;
while (it!=lh.end()) {
auto [pos,pwr]=*it;
// cout<<pos<<" "<<pwr<<"\n"<<flush;
if (pos-res[i].second<=res[i].first-pwr) {
it=lh.erase(it);
it--;
} else break;
}
}
cout<<ans<<"\n";
return 0;
}
# | 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... |