#include <iostream>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <map>
#include <queue>
#include <vector>
#define mk make_pair
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pos;
const ll MOD = 1000000007,N=10000010;
int dp[N],n,ans,bt1[N],bt2[N];
pair<int, int> xy[N],yl[N];
priority_queue<pair<int, int> > q;
void ad(int v1, int v2,int bt[]) {
while (v1 < N) {
bt[v1] = max(bt[v1], v2);
v1 += v1 & -v1;
}
}
ll sm(int v1,int bt[]) {
int v2 = -2147483647;
while (v1 > 0) {
v2 = max(v2, bt[v1]);
v1 -= v1 & -v1;
}
return v2;
}
int main() {
for (int i = 0; i < N; i++)bt1[i] = bt2[i] = (int)-2147483647;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d%d", &xy[i].first, &xy[i].second);
yl[i] = mk(xy[i].second, i);
}
sort(yl + 1, yl + n + 1);
for (int i = n; i >= 1; i--) {
int ci = yl[i].second;
int v1 = sm(ci,bt1),v2=-sm(n+1-ci,bt2);
if (v1 >= xy[ci].first + xy[ci].second || v2 <= xy[ci].first - xy[ci].second)continue;
ad(ci, xy[ci].first + xy[ci].second, bt1);
ad(n + 1 - ci, -xy[ci].first + xy[ci].second,bt2);
ans++;
}
cout << ans << endl;
return 0;
}
Compilation message
lightningrod.cpp: In function 'int main()':
lightningrod.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
lightningrod.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &xy[i].first, &xy[i].second);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2091 ms |
263168 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
78584 KB |
Output is correct |
2 |
Correct |
74 ms |
78632 KB |
Output is correct |
3 |
Correct |
79 ms |
78584 KB |
Output is correct |
4 |
Correct |
84 ms |
78616 KB |
Output is correct |
5 |
Correct |
71 ms |
78584 KB |
Output is correct |
6 |
Correct |
73 ms |
78584 KB |
Output is correct |
7 |
Correct |
77 ms |
78584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
78584 KB |
Output is correct |
2 |
Correct |
74 ms |
78632 KB |
Output is correct |
3 |
Correct |
79 ms |
78584 KB |
Output is correct |
4 |
Correct |
84 ms |
78616 KB |
Output is correct |
5 |
Correct |
71 ms |
78584 KB |
Output is correct |
6 |
Correct |
73 ms |
78584 KB |
Output is correct |
7 |
Correct |
77 ms |
78584 KB |
Output is correct |
8 |
Correct |
81 ms |
78544 KB |
Output is correct |
9 |
Correct |
79 ms |
78584 KB |
Output is correct |
10 |
Correct |
89 ms |
78584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
78584 KB |
Output is correct |
2 |
Correct |
74 ms |
78632 KB |
Output is correct |
3 |
Correct |
79 ms |
78584 KB |
Output is correct |
4 |
Correct |
84 ms |
78616 KB |
Output is correct |
5 |
Correct |
71 ms |
78584 KB |
Output is correct |
6 |
Correct |
73 ms |
78584 KB |
Output is correct |
7 |
Correct |
77 ms |
78584 KB |
Output is correct |
8 |
Correct |
81 ms |
78544 KB |
Output is correct |
9 |
Correct |
79 ms |
78584 KB |
Output is correct |
10 |
Correct |
89 ms |
78584 KB |
Output is correct |
11 |
Correct |
72 ms |
78680 KB |
Output is correct |
12 |
Correct |
78 ms |
78648 KB |
Output is correct |
13 |
Correct |
83 ms |
78740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
78584 KB |
Output is correct |
2 |
Correct |
74 ms |
78632 KB |
Output is correct |
3 |
Correct |
79 ms |
78584 KB |
Output is correct |
4 |
Correct |
84 ms |
78616 KB |
Output is correct |
5 |
Correct |
71 ms |
78584 KB |
Output is correct |
6 |
Correct |
73 ms |
78584 KB |
Output is correct |
7 |
Correct |
77 ms |
78584 KB |
Output is correct |
8 |
Correct |
81 ms |
78544 KB |
Output is correct |
9 |
Correct |
79 ms |
78584 KB |
Output is correct |
10 |
Correct |
89 ms |
78584 KB |
Output is correct |
11 |
Correct |
72 ms |
78680 KB |
Output is correct |
12 |
Correct |
78 ms |
78648 KB |
Output is correct |
13 |
Correct |
83 ms |
78740 KB |
Output is correct |
14 |
Correct |
188 ms |
85084 KB |
Output is correct |
15 |
Correct |
161 ms |
85184 KB |
Output is correct |
16 |
Correct |
191 ms |
84472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2109 ms |
263168 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2091 ms |
263168 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |