#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,h,k,a[100002],sum,res;
pair <int, int> p[100001];
set <int> s;
void update(int i, int j){
a[i]+=j;
if (a[i])
s.insert(i);
else
s.erase(i);
}
int32_t main(){
ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
cin >> n;
for (int i=1;i<=n;i++)
cin >> p[i].first >> p[i].second;
sort(p+1,p+n+1);
s.insert(1);
s.insert(100001);
for (int i=1;i<=n;i++){
auto [h,k]=p[i];
if (a[h-k+1]){
update(h-k+1,1);
update(h+1,-1);
continue;
}
auto it=s.lower_bound(h-k+1);
int r=*it;
r--;
it--;
int l=*it;
r=min(r,h);
update(l,1);
update(l+r-h+k,-1);
update(h+1,-1);
update(r+1,1);
}
for (int i=1;i<=100000;i++){
sum+=a[i];
res+=sum*(sum-1)/2;
}
cout << res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
1112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
860 KB |
Output is correct |
2 |
Correct |
11 ms |
3160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
3904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
2904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
2896 KB |
Output is correct |
2 |
Correct |
25 ms |
4376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
4980 KB |
Output is correct |
2 |
Correct |
24 ms |
3620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
3428 KB |
Output is correct |
2 |
Correct |
24 ms |
2648 KB |
Output is correct |