이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
#define PB push_back
#define PF push_front
#define PPB pop_back
#define PPF pop_front
#define X first
#define Y second
#define MP make_pair
#define all(x) (x).begin(), (x).end()
const int mod = 1e9 + 7; //998244353;
const int inf = 1e9 + 7;
const ll INF = 1e18 + 7;
const int logo = 20;
const int MAXN = 1e6 + 7;
const int off = 1 << logo;
const int trsz = off << 1;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
vi vals;
vii p;
struct tournament{
int seg[trsz];
tournament(){
fill(seg, seg + trsz, -1);
}
void update(int x, int vl){
x += off;
seg[x] = max(seg[x], vl);
for(x /= 2; x; x /= 2) seg[x] = max(seg[x * 2], seg[x * 2 + 1]);
}
int query(int l, int r){
int ret = -1;
for(l += off, r += off; l < r; l >>= 1, r >>= 1){
if(l & 1) ret = max(ret, seg[l++]);
if(r & 1) ret = max(ret, seg[--r]);
}
return ret;
}
}t;
bool cmp(ii &a, ii &b){
return a.Y - a.X > b.Y - b.X;
}
void solve(){
int n;
cin >> n;
for(int i=1; i<=n; i++){
int x, e;
cin >> x >> e;
vals.PB(x - e);
vals.PB(x + e);
p.PB({x - e, x + e});
}
sort(all(vals));
vals.erase(unique(all(vals)), vals.end());
for(auto &x : p){
x.X = lower_bound(all(vals), x.X) - vals.begin() + 1;
x.Y = lower_bound(all(vals), x.Y) - vals.begin() + 1;
}
sort(all(p), cmp);
int ans = 0;
for(auto &x : p){
if(t.query(0, x.X + 1) >= x.Y) continue;
t.update(x.X, x.Y);
ans++;
}
cout << ans << "\n";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int tt = 1;
//cin >> tt;
while(tt--) solve();
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... |