Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int,int>
- #define vec vector
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvl(vector <ll> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvv(vector <vector <int> > &v){
- for (auto x: v) cv(x);
- cout<<"\n";
- }
- int n;
- struct el{
- ll a,b, c,d;
- };
- void mk(el &x){
- cin>>x.a>>x.b>>x.c>>x.d;
- }
- ll tm(el x, int st){
- return x.c + x.d * (st - x.a);
- }
- pii inter(el x, el y){
- pii res = {max(x.a, y.a), min(x.b, y.b)};
- if (res.first <= res.second){
- return res;
- }
- return {-1, -1};
- }
- vector <el> v;
- vector <vector <int> > G;
- void mkG(){
- el x,y;
- ll tx, ty;
- pii cmn;
- G.resize(n);
- for (int i = 0; i < n;++i){
- x = v[i];
- for (int j = 0; j < n && j != i ; ++ j){
- y = v[j];
- cmn = inter(x, y);
- if (cmn == pii {-1, -1}){
- continue;
- }
- //int stn = (cmn.first + cmn.second) / 2;
- int stn = cmn.first;
- tx = tm(x, stn);
- ty = tm(y, stn);
- if (tx < ty){
- G[i].push_back(j);
- }
- else if (tx > ty){
- G[j].push_back(i);
- }
- else if (tx == ty){
- stn = cmn.second;
- tx = tm(x, stn);
- ty = tm(y, stn);
- if (tx < ty){
- G[i].push_back(j);
- }
- else if (tx > ty){
- G[j].push_back(i);
- }
- else{
- stn = (cmn.first + cmn.second) / 2;
- tx = tm(x, stn);
- ty = tm(y, stn);
- if (tx < ty){
- G[i].push_back(j);
- }
- else if (tx > ty){
- G[j].push_back(i);
- }
- }
- }
- }
- }
- }
- const int wh=0, gr=1, bl=2;
- vector <int> clr;
- vector <int> ans;
- void dfs(int v) {
- clr[v] = gr;
- for (int u: G[v]){
- if (clr[u] == wh){
- dfs(u);
- }
- }
- clr[v] = bl;
- ans.push_back(v+1);
- }
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- cin>>n;
- v.resize(n);
- for (int i=0;i<n;++i) mk(v[i]);
- mkG();
- clr.assign(n, wh);
- for (int i = 0; i < n;++i){
- if (clr[i] == wh) dfs(i);
- }
- reverse(ans.begin(), ans.end());
- cv(ans);
- }
- /*
- 3
- 1 10 3 4
- 3 5 3 4
- 10 11 10 1
- */
Add Comment
Please, Sign In to add comment