This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
const int N = 1e6+100, M = 1e5+10, K = 52, MX = 30;
int n, T[N*2][2], ans;
array<int, 3> A[N], B[N];
vector<bool> re;
void build(int l, int r, int k){
if(l == r){
T[k][0] = A[l][1] - A[l][0];
T[k][1] = A[l][1] + A[l][0];
return;
}
int m = l+r>>1;
build(l, m, k<<1);
build(m+1, r, k<<1|1);
T[k][0] = min(T[k<<1][0], T[k<<1|1][0]);
T[k][1] = min(T[k<<1][1], T[k<<1|1][1]);
}
void rem1(int l, int r, int p, int k, int val){
if(l > p || T[k][0] > val) return;
if(l == r){
if(T[k][0] <= val){
re[l] = 1;
T[k][0] = INT_MAX;
T[k][1] = INT_MAX;
}
return;
}
int m = l+r>>1;
rem1(l, m, p, k<<1, val);
rem1(m+1, r, p, k<<1|1, val);
T[k][0] = min(T[k<<1][0], T[k<<1|1][0]);
T[k][1] = min(T[k<<1][1], T[k<<1|1][1]);
}
void rem2(int l, int r, int p, int k, int val){
if(r < p || T[k][1] > val) return;
if(l == r){
if(T[k][1] <= val){
re[l] = 1;
T[k][0] = INT_MAX;
T[k][1] = INT_MAX;
}
return;
}
int m = l+r>>1;
rem2(l, m, p, k<<1, val);
rem2(m+1, r, p, k<<1|1, val);
T[k][0] = min(T[k<<1][0], T[k<<1|1][0]);
T[k][1] = min(T[k<<1][1], T[k<<1|1][1]);
}
void rem(int l, int r, int p, int k){
if(l == r){
re[l] = 1;
T[k][0] = INT_MAX;
T[k][1] = INT_MAX;
return;
}
int m = l+r>>1;
if(p <= m)
rem(l, m, p, k<<1);
else
rem(m+1, r, p, k<<1|1);
T[k][0] = min(T[k<<1][0], T[k<<1|1][0]);
T[k][1] = min(T[k<<1][1], T[k<<1|1][1]);
}
void solve(){
cin >> n;
ans = 0;
for(int i = 1; i <= n; ++i){
cin >> A[i][0] >> A[i][1];
}
sort(A+1, A+1+n);
for(int i = 1; i <= n; ++i) A[i][2] = i;
re.resize(n+1);
build(1, n, 1);
for(int i = 1; i <= n; ++i) B[i] = A[i];
sort(B+1, B+1+n, [&](const array<int, 3> &x, const array<int, 3> &y){
return x[1] < y[1];
});
for(int i = n; i >= 1; --i){
int pos = B[i][2];
if(re[pos]) continue;
rem1(1, n, pos - 1, 1, B[i][1] - B[i][0]);
rem2(1, n, pos + 1, 1, B[i][1] + B[i][0]);
rem(1, n, pos, 1);
++ans;
}
cout << ans;
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int tt = 1, aa;
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
while(tt--){
solve();
// en;
en;
}
cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'void build(int, int, int)':
Main.cpp:22:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
22 | int m = l+r>>1;
| ~^~
Main.cpp: In function 'void rem1(int, int, int, int, int)':
Main.cpp:39:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
39 | int m = l+r>>1;
| ~^~
Main.cpp: In function 'void rem2(int, int, int, int, int)':
Main.cpp:55:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
55 | int m = l+r>>1;
| ~^~
Main.cpp: In function 'void rem(int, int, int, int)':
Main.cpp:68:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
68 | int m = l+r>>1;
| ~^~
Main.cpp: In function 'int main()':
Main.cpp:112:15: warning: unused variable 'aa' [-Wunused-variable]
112 | int tt = 1, aa;
| ^~
# | 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... |