Pagini recente » Cod sursa (job #2039847) | Cod sursa (job #3156449) | Cod sursa (job #361218) | Cod sursa (job #2680080) | Cod sursa (job #757624)
Cod sursa(job #757624)
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
const int INF = 0x3f3f3f3f;
int N;
pair<int, int> A[100002];
int pos[100002];
int AIB[2][100002];
int result;
void update(int wh, int pos, int val)
{
for (; pos <= N; pos += pos & -pos)
AIB[wh][pos] += val;
}
int query(int wh, int pos)
{
int sum = 0;
for (; pos >= 1; pos -= pos & -pos)
sum += AIB[wh][pos];
return sum;
}
class compareB
{
public:
inline bool operator () (const int& p1, const int& p2)
{
return A[p1].second < A[p2].second;
}
};
int main()
{
ifstream fin("cadrane.in");
ofstream fout("cadrane.out");
fin >> N;
for (int i = 1; i <= N; ++i)
fin >> A[i].first >> A[i].second;
sort(A + 1, A + N + 1);
for (int i = 1; i <= N; ++i)
pos[i] = i;
sort(pos + 1, pos + N + 1, compareB());
int now = 0;
for (int i = 1; i <= N; ++i)
{
++now;
while (i + 1 <= N && A[pos[i]].second == A[pos[i + 1]].second)
{
A[pos[i]].second = now;
++i;
}
A[pos[i]].second = now;
}
for (int i = 1; i <= N; ++i)
update(1, A[i].second, 1);
int wh = 1;
for (int i = 1; i <= N; ++i) // baleez
{
while (A[wh].first < A[i].first)
{
update(1, A[wh].second, -1);
++wh;
}
while (i + 1 <= N && A[i].first == A[i + 1].first)
{
update(0, A[i].second, 1);
++i;
}
update(0, A[i].second, 1);
int resnow = INF;
for (int j = now; j >= 1; --j)
resnow = min(resnow, query(0, j) + query(1, now) - query(1, j - 1));
result = max(result, resnow);
printf("%d %d %d\n", resnow, A[i].first, A[i].second);
}
fout << result << '\n';
fin.close();
fout.close();
}