#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int)size(x))
#define all(x) begin(x), end(x)
#define trace(x) cout << #x << ": " << (x) << endl;
typedef long long ll;
typedef double db;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r) { return (int) ((ll) rnd() % (r - l + 1)) + l; }
const int N = 100002, infI = 1e9 + 7;
int X[N][2], Y[N][2];
pair<int, int> R[N];
int x_now = -infI;
db get(int i) {
if (x_now == X[i][0]) {
return Y[i][0];
}
db k = (Y[i][0] - Y[i][1]) / (db) (X[i][0] - X[i][1]);
db b = Y[i][0] - X[i][0] * k;
return k * x_now + b;
}
auto comp = [](int i, int j) {
return get(i) < get(j);
};
set<int, decltype(comp)> st(comp);
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<tuple<int, int, int, int>> qu;
for (int i = 0; i < n; ++i) {
cin >> X[i][0] >> Y[i][0] >> X[i][1] >> Y[i][1];
if (X[i][0] > X[i][1] || (X[i][0] == X[i][1] && Y[i][0] > Y[i][1])) {
swap(X[i][0], X[i][1]);
swap(Y[i][0], Y[i][1]);
}
qu.emplace_back(X[i][0], Y[i][0], 0, i);
qu.emplace_back(X[i][1], Y[i][1], 1, i);
}
fill(all(R), make_pair(-infI, -infI));
sort(all(qu));
X[n][0] = -infI, Y[n][0] = -infI;
X[n][1] = infI, Y[n][1] = -infI;
X[n + 1][0] = -infI, Y[n + 1][0] = infI;
X[n + 1][1] = infI, Y[n + 1][1] = infI;
st.insert(n);
st.insert(n + 1);
for (auto [x, y, tt, i]: qu) {
x_now = x;
if (tt == 0) {
auto it = st.insert(i).first;
pair<int, int> now = R[*prev(it)];
R[*prev(it)] = R[i] = {X[i][0], Y[i][0]};
if (now.first != -infI) {
cout << now.first << " " << now.second << " " << X[i][0] << " " << Y[i][0] << '\n';
}
} else {
auto it = st.find(i);
R[*prev(it)] = {X[i][1], Y[i][1]};
st.erase(i);
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1108 KB |
Output is correct |
2 |
Correct |
46 ms |
3780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1108 KB |
Output is correct |
2 |
Correct |
1 ms |
1108 KB |
Output is correct |
3 |
Correct |
2 ms |
1108 KB |
Output is correct |
4 |
Correct |
10 ms |
2040 KB |
Output is correct |
5 |
Correct |
19 ms |
2760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1108 KB |
Output is correct |
2 |
Correct |
1 ms |
1108 KB |
Output is correct |
3 |
Correct |
2 ms |
1108 KB |
Output is correct |
4 |
Correct |
10 ms |
2004 KB |
Output is correct |
5 |
Correct |
19 ms |
2796 KB |
Output is correct |
6 |
Correct |
1 ms |
1108 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
2 ms |
1108 KB |
Output is correct |
9 |
Correct |
11 ms |
2004 KB |
Output is correct |
10 |
Correct |
142 ms |
8876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1108 KB |
Output is correct |
2 |
Correct |
1 ms |
1108 KB |
Output is correct |
3 |
Correct |
2 ms |
1108 KB |
Output is correct |
4 |
Correct |
10 ms |
2004 KB |
Output is correct |
5 |
Correct |
19 ms |
2768 KB |
Output is correct |
6 |
Correct |
1 ms |
1108 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
1 ms |
1108 KB |
Output is correct |
9 |
Correct |
10 ms |
1968 KB |
Output is correct |
10 |
Correct |
47 ms |
5056 KB |
Output is correct |
11 |
Correct |
1 ms |
1108 KB |
Output is correct |
12 |
Correct |
1 ms |
1108 KB |
Output is correct |
13 |
Correct |
1 ms |
1108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1108 KB |
Output is correct |
2 |
Correct |
1 ms |
1108 KB |
Output is correct |
3 |
Correct |
1 ms |
1108 KB |
Output is correct |
4 |
Correct |
2 ms |
1108 KB |
Output is correct |
5 |
Correct |
10 ms |
2004 KB |
Output is correct |
6 |
Correct |
1 ms |
1108 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
2 ms |
1108 KB |
Output is correct |
9 |
Correct |
12 ms |
1928 KB |
Output is correct |
10 |
Correct |
1 ms |
1108 KB |
Output is correct |
11 |
Correct |
1 ms |
1108 KB |
Output is correct |
12 |
Correct |
2 ms |
1108 KB |
Output is correct |
13 |
Correct |
10 ms |
2004 KB |
Output is correct |
14 |
Correct |
1 ms |
1108 KB |
Output is correct |
15 |
Correct |
1 ms |
1108 KB |
Output is correct |
16 |
Correct |
1 ms |
1108 KB |
Output is correct |
17 |
Correct |
1 ms |
1108 KB |
Output is correct |
18 |
Correct |
1 ms |
1108 KB |
Output is correct |
19 |
Correct |
1 ms |
1108 KB |
Output is correct |
20 |
Correct |
2 ms |
1108 KB |
Output is correct |
21 |
Correct |
1 ms |
1108 KB |
Output is correct |
22 |
Correct |
5 ms |
1492 KB |
Output is correct |
23 |
Correct |
6 ms |
1492 KB |
Output is correct |
24 |
Correct |
9 ms |
1716 KB |
Output is correct |
25 |
Correct |
1 ms |
1108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1108 KB |
Output is correct |
2 |
Correct |
51 ms |
3784 KB |
Output is correct |
3 |
Correct |
1 ms |
1108 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
1108 KB |
Output is correct |
6 |
Correct |
10 ms |
2004 KB |
Output is correct |
7 |
Correct |
20 ms |
2768 KB |
Output is correct |
8 |
Correct |
1 ms |
1108 KB |
Output is correct |
9 |
Correct |
1 ms |
1108 KB |
Output is correct |
10 |
Correct |
2 ms |
1108 KB |
Output is correct |
11 |
Correct |
12 ms |
2004 KB |
Output is correct |
12 |
Correct |
137 ms |
8888 KB |
Output is correct |
13 |
Correct |
1 ms |
1108 KB |
Output is correct |
14 |
Correct |
2 ms |
1108 KB |
Output is correct |
15 |
Correct |
2 ms |
1108 KB |
Output is correct |
16 |
Correct |
11 ms |
2004 KB |
Output is correct |
17 |
Correct |
48 ms |
4964 KB |
Output is correct |
18 |
Correct |
1 ms |
1108 KB |
Output is correct |
19 |
Correct |
1 ms |
1108 KB |
Output is correct |
20 |
Correct |
1 ms |
1108 KB |
Output is correct |
21 |
Correct |
1 ms |
1108 KB |
Output is correct |
22 |
Correct |
1 ms |
1108 KB |
Output is correct |
23 |
Correct |
1 ms |
1108 KB |
Output is correct |
24 |
Correct |
2 ms |
1108 KB |
Output is correct |
25 |
Correct |
1 ms |
1108 KB |
Output is correct |
26 |
Correct |
5 ms |
1472 KB |
Output is correct |
27 |
Correct |
5 ms |
1492 KB |
Output is correct |
28 |
Correct |
10 ms |
1720 KB |
Output is correct |
29 |
Correct |
70 ms |
6332 KB |
Output is correct |
30 |
Correct |
99 ms |
8544 KB |
Output is correct |
31 |
Correct |
1 ms |
1108 KB |
Output is correct |
32 |
Correct |
101 ms |
6300 KB |
Output is correct |
33 |
Correct |
89 ms |
6304 KB |
Output is correct |
34 |
Correct |
116 ms |
7956 KB |
Output is correct |
35 |
Correct |
122 ms |
8292 KB |
Output is correct |
36 |
Correct |
126 ms |
9784 KB |
Output is correct |