Submission #1196591

#TimeUsernameProblemLanguageResultExecution timeMemory
1196591Zbyszek99Roads (CEOI20_roads)C++20
100 / 100
104 ms13748 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long #define ld long double #define ull unsigned long long #define ff first #define ss second #define pii pair<int,int> #define pll pair<long long, long long> #define vi vector<int> #define vl vector<long long> #define pb push_back #define rep(i, b) for(int i = 0; i < (b); ++i) #define rep2(i,a,b) for(int i = a; i <= (b); ++i) #define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c) #define count_bits(x) __builtin_popcountll((x)) #define all(x) (x).begin(),(x).end() #define siz(x) (int)(x).size() #define forall(it,x) for(auto& it:(x)) using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; //mt19937 mt;void random_start(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());} //ll los(ll a, ll b) {return a + (mt() % (b-a+1));} const int INF = 1e9+50; const ll INF_L = 1e18+40; const ll MOD = 1e9+7; struct seg { ll x1,y1,x2,y2; int ind; bool operator<(const seg& other) const { if(x1 > other.x1) { if((y1) * (other.x1 - other.x2) == (x1 * (other.y1 - other.y2) - other.y1 * other.x2 + other.y2 * other.x1)) return y1 < other.y1; return (y1) * (other.x1 - other.x2) < (x1 * (other.y1 - other.y2) - other.y1 * other.x2 + other.y2 * other.x1); } else { if((other.x1 * (y1 - y2) - y1 * x2 + y2 * x1) == (other.y1) * (x1 - x2)) return y1 < other.y1; return (other.x1 * (y1 - y2) - y1 * x2 + y2 * x1) < (other.y1) * (x1 - x2); } } }; seg segs[100001]; pii most_rup[100001]; pii most_rdown[100001]; int main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); //random_start(); int n; cin >> n; vector<pair<pii,int>> points; rep(i,n) { int x1,y1,x2,y2; cin >> x1 >> y1 >> x2 >> y2; if(x1 > x2 || (x1 == x2 && y1 > y2)) { swap(x1,x2); swap(y1,y2); } segs[i] = {x1,y1,x2,y2,i}; points.pb({{x1,y1},i}); points.pb({{x2,y2},i}); } set<seg> segs_set; sort(all(points)); pair<pii,int> prev = {{-1,-1},-1}; forall(it,points) { int x = it.ff.ff; int y = it.ff.ss; int ind = it.ss; if(x == segs[ind].x2 && y == segs[ind].y2) { if(segs[ind].x1 != segs[ind].x2) { segs_set.erase(segs_set.find(segs[ind])); } auto it = segs_set.lower_bound(segs[ind]); if(it != segs_set.end()) { most_rdown[(*it).ind] = {x,y}; } if(it != segs_set.begin()) { it--; most_rup[(*it).ind] = {x,y}; } } else { if(siz(segs_set) == 0) { if(prev.ss == -1) { if(segs[ind].x1 != segs[ind].x2) segs_set.insert(segs[ind]); most_rdown[ind] = {x,y}; most_rup[ind] = {x,y}; } else { cout << x << " " << y << " " << prev.ff.ff << " " << prev.ff.ss << "\n"; if(segs[ind].x1 != segs[ind].x2) segs_set.insert(segs[ind]); most_rdown[ind] = {x,y}; most_rup[ind] = {x,y}; } continue; } else { auto it = segs_set.lower_bound(segs[ind]); if(it != segs_set.end()) { cout << x << " " << y << " " << most_rdown[(*it).ind].ff << " " << most_rdown[(*it).ind].ss << "\n"; } else { it--; cout << x << " " << y << " " << most_rup[(*it).ind].ff << " " << most_rup[(*it).ind].ss << "\n"; } it = segs_set.lower_bound(segs[ind]); if(it != segs_set.end()) { most_rdown[(*it).ind] = {x,y}; } if(it != segs_set.begin()) { it--; most_rup[(*it).ind] = {x,y}; } most_rdown[ind] = {x,y}; most_rup[ind] = {x,y}; if(segs[ind].x1 != segs[ind].x2) segs_set.insert(segs[ind]); } } prev = {{x,y},ind}; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...