Pagini recente » Autentificare | Cod sursa (job #1731215) | Istoria paginii runda/daupentrumata | Cod sursa (job #1030143) | Cod sursa (job #2015539)
#include <fstream>
#include <iostream>
#include <vector>
#include <stack>
#include <bitset>
#include <algorithm>
#define DIM 200010
#define X first.first
#define Y first.second
#define Z second
using namespace std;
vector<pair<pair<int, int>, int > >S, J;
int n, x1, x2, y, sol;
stack<int> st;
bitset<DIM> B;
int cmp(const pair<pair<int, int>, int > &a, const pair<pair<int, int>, int > & b) {
long long t = a.X * 1LL * b.Y - a.Y * 1LL * b.X;
if (t == 0)
return a.Z < b.Z;
else
return t < 0;
}
int main () {
ifstream fin ("rays.in");
ofstream fout("rays.out");
fin>>n;
for (int i=1;i<=n;i++) {
fin>>y>>x1>>x2;
if (x1 > x2) {
swap(x1, x2);
}
if (y > 0) {
S.push_back(make_pair(make_pair(x1, y),i));
S.push_back(make_pair(make_pair(x2, y),-i));
}else {
J.push_back(make_pair(make_pair(x1, -y),i));
J.push_back(make_pair(make_pair(x2, -y),-i));
}
}
for (int t = 2; t--;) {
sort(S.begin(), S.end(), cmp);
while (!st.empty())
st.pop();
B.reset();
for (int i=0;i<S.size(); i++) {
int tip = S[i].Z;
if (tip > 0) {
st.push(i);
} else {
if (B[-tip] == 0) {
sol ++;
while (!st.empty()) {
B[ S[st.top()].Z ] = 1;
st.pop();
}
}
}
}
S.clear();
for (int i=0;i<J.size();i++)
S.push_back(J[i]);
}
fout<<sol;
return 0;
}