# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
573242 | guugiuh | Lightning Rod (NOI18_lightningrod) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
using namespace std;
inline int readInt() {
int x = 0;
char ch = getchar_unlocked();
while (ch < '0' || ch > '9') ch = getchar_unlocked();
while (ch >= '0' && ch <= '9'){
x = (x << 3) + (x << 1) + ch - '0';
ch = getchar_unlocked();
}
return x;
}
int MinPyramids(int N, vi X, vi Y)
{
int res = 0;
vi T1(N + 1), T2(N + 1);
for (int i = 0; i < N; i++)
T1[N - i] = X[i] - Y[i], T2[i + 1] = X[i] + Y[i];
for (int i = 0; i < N; i++)
if (i + (i & -i) <= N)
T1[i + (i & -i)] = min(T1[i + (i & -i)], T1[i]), T2[i + (i & -i)] = max(T2[i + (i & -i)], T2[i]);
for (int i = 0; i < N; i++)
{
int mn = 2e9+1, mx = -mn;
for (int j = N - i - 1; j > 0; j -= j & -j)
mn = min(mn, T1[j]);
for (int j = i; j > 0; j -= j & -j)
mx = max(mx, T2[j]);
if (mx < X[i] + Y[i] && mn > X[i] - Y[i])
res++;
}
return res;
}
int main(){
int N = readInt();
vector <int> X(N);
vector <int> Y(N);
for(int i = 0; i < N; i++) {
X[i] = readInt();
Y[i] = readInt();
}
int ans= MinPyramids(N,X,Y);
printf("%d", ans);
return 0;
}