제출 #624541

#제출 시각아이디문제언어결과실행 시간메모리
624541Vladth11Roads (CEOI20_roads)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> #define debug(x) cerr << #x << " " << x << "\n" #define debugs(x) cerr << #x << " " << x << " " using namespace std; typedef long long ll; typedef pair <long double, long double> pii; const ll NMAX = 100001; const ll VMAX = 101; const ll INF = 1e9; const ll MOD = 1000000007; const ll BLOCK = 447; const ll base = 117; const ll nr_of_bits = 18; const ll inv2 = 500000004; set <pii> exista; struct event { pii x; long double stare; bool operator < (const event a) { if(a.x.first != x.first) { return x.first < a.x.first; } if(a.stare != stare) { return stare > a.stare; } return x.second < a.x.second; /// Nu ar trb sa aiba importanta, dar e necesar sa nu busesc sortarea } }; long double swipex; struct segment { long double a, b, c, d; long double idx; long double gety() { if(c != a) return (long double)b + (long double)(swipex - a) * (long double)(d - b) / (long double)(c - a); else return (long double)b; } } sgt[NMAX]; vector <event> events; map <pii, pii> mp; set <pii> already; bool signs(long double a, long double b) { if(a < b) swap(a, b); if(a > 0 && b < 0) return 0; return 1; } long double cnt = 0; void adauga(long double a, long double b) { if(a < b) swap(a, b); cnt++; if(already.find({a, b}) != already.end()) return; already.insert({a, b}); segment first = sgt[a]; segment second = sgt[b]; if(first.b < second.b) { swap(first, second); } else if(first.b == second.b) { if(first.a < second.a) { swap(first, second); } } if(first.a >= second.c) { cout << first.a << " " << first.b << " " << second.c << " " << second.d << "\n"; return; } if(second.a >= first.c) { cout << first.c << " " << first.d << " " << second.a << " " << second.b << "\n"; return; } cout << first.a << " " << first.b << " " << second.a << " " << second.b << "\n"; } struct ura { long double first, second; bool operator < (const ura a)const { if(a.second == -1 && second == -1) { return first < a.first; } if(a.second == -1) { return sgt[second].gety() < a.first; } if(second == -1) { return first < sgt[a.second].gety(); } return sgt[second].gety() < sgt[a.second].gety(); } }; int main() { //ifstream cin(".out"); //ofstream cout(".out"); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long double n, i; cin >> n; for(i = 1; i <= n; i++) { long double a, b, c, d; cin >> a >> b >> c >> d; if(a > c) { swap(b, d); swap(a, c); } else if(a == c) { if(b > d) swap(b, d); /// nu stiu daca e nevoie } sgt[i] = {a, b, c, d, i}; exista.insert({a, b}); exista.insert({c, d}); events.push_back({{a, b}, i}); events.push_back({{c, d}, -i}); } n += 2; sgt[n - 1] = {-INF, -INF, INF, -INF, n - 1}; events.push_back({{-INF, -INF}, n - 1}); events.push_back({{INF, -INF}, -(n - 1)}); sgt[n] = {-INF, INF, INF, INF, n}; events.push_back({{-INF, INF}, n}); events.push_back({{INF, INF}, -n}); sort(events.begin(), events.end()); set <ura> active; vector <pair <pii, long double> > facut; vector <pii> tobe; for(long double i = 0; i < events.size(); i++) { swipex = events[i].x.first; if(events[i].stare > 0) { if(events[i].x.first != -INF) { facut.push_back({events[i].x, events[i].stare}); tobe.push_back({events[i].x.second, events[i].stare}); } else { active.insert({events[i].x.second, events[i].stare}); } } else { if(-events[i].stare < n - 1) { auto sus = active.lower_bound({sgt[-events[i].stare].gety(), -1}); sus = prev(sus); auto jos = active.lower_bound({sgt[-events[i].stare].gety(), -1}); jos = next(jos); long double indS = (*sus).second; long double indJ = (*jos).second; if(mp.find({indS, indJ}) != mp.end()) mp[ {indS, indJ}] = max(mp[ {indS, indJ}], {events[i].x.first, -events[i].stare}); else mp[ {indS, indJ}] = {events[i].x.first, -events[i].stare}; } active.erase({events[i].x.second, -events[i].stare}); } if(i == events.size() || (events[i + 1].x.first != events[i].x.first || !signs(events[i + 1].stare, events[i].stare))) { long double cc = 0; if(facut.size() == 0) continue; for(auto x : facut) { cc++; /// pe primul vrem sa-l conectam la alea din spate if(cc == 1) { active.insert({tobe[0].first, tobe[0].second}); } auto sus = active.lower_bound({x.first.second, -1}); sus = prev(sus); auto jos = active.lower_bound({x.first.second, -1}); /// nu vrem daca trece chiar la limita sa-l ignor jos = next(jos); long double indS = (*sus).second; long double indJ = (*jos).second; if(mp.find({indS, indJ}) == mp.end()) { if(sgt[indS].a != -INF) { adauga(indS, x.second); } else if(sgt[indJ].a != -INF) { adauga(indJ, x.second); } } else { pii conectare = mp[ {indS, indJ}]; adauga(conectare.second, x.second); } if(cc == 1) { for(auto x : tobe) { active.insert({x.first, x.second}); } } /// Desi il conectam in urma, vrem ca atunci cand e inserat sa tina cont si de ceilalti sus = active.lower_bound({x.first.second, -1}); sus = prev(sus); jos = active.lower_bound({x.first.second, -1}); /// nu vrem daca trece chiar la limita sa-l ignor jos = next(jos); indS = (*sus).second; indJ = (*jos).second; if(mp.find({indS, indJ}) != mp.end()) mp[ {indS, indJ}] = max(mp[ {indS, indJ}], {x.first.first, x.second}); else mp[ {indS, indJ}] = {x.first.first, x.second}; } tobe.clear(); facut.clear(); } } assert(cnt == n - 3); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

roads.cpp: In function 'void adauga(long double, long double)':
roads.cpp:67:24: error: invalid types 'segment [100001][long double]' for array subscript
   67 |     segment first = sgt[a];
      |                        ^
roads.cpp:68:25: error: invalid types 'segment [100001][long double]' for array subscript
   68 |     segment second = sgt[b];
      |                         ^
roads.cpp: In member function 'bool ura::operator<(ura) const':
roads.cpp:94:23: error: invalid types 'segment [100001][const long double]' for array subscript
   94 |             return sgt[second].gety() < a.first;
      |                       ^
roads.cpp:97:31: error: invalid types 'segment [100001][const long double]' for array subscript
   97 |             return first < sgt[a.second].gety();
      |                               ^
roads.cpp:99:19: error: invalid types 'segment [100001][const long double]' for array subscript
   99 |         return sgt[second].gety() < sgt[a.second].gety();
      |                   ^
roads.cpp:99:40: error: invalid types 'segment [100001][const long double]' for array subscript
   99 |         return sgt[second].gety() < sgt[a.second].gety();
      |                                        ^
roads.cpp: In function 'int main()':
roads.cpp:121:12: error: invalid types 'segment [100001][long double]' for array subscript
  121 |         sgt[i] = {a, b, c, d, i};
      |            ^
roads.cpp:128:8: error: invalid types 'segment [100001][long double]' for array subscript
  128 |     sgt[n - 1] = {-INF, -INF, INF, -INF, n - 1};
      |        ^
roads.cpp:131:8: error: invalid types 'segment [100001][long double]' for array subscript
  131 |     sgt[n] = {-INF, INF, INF, INF, n};
      |        ^
roads.cpp:149:51: error: invalid types 'segment [100001][long double]' for array subscript
  149 |                 auto sus = active.lower_bound({sgt[-events[i].stare].gety(), -1});
      |                                                   ^
roads.cpp:149:81: error: no matching function for call to 'std::set<ura>::lower_bound(<brace-enclosed initializer list>)'
  149 |                 auto sus = active.lower_bound({sgt[-events[i].stare].gety(), -1});
      |                                                                                 ^
In file included from /usr/include/c++/10/set:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:87,
                 from roads.cpp:1:
/usr/include/c++/10/bits/stl_set.h:829:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::lower_bound(const key_type&) [with _Key = ura; _Compare = std::less<ura>; _Alloc = std::allocator<ura>; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree<ura, ura, std::_Identity<ura>, std::less<ura>, std::allocator<ura> >::const_iterator; std::set<_Key, _Compare, _Alloc>::key_type = ura]'
  829 |       lower_bound(const key_type& __x)
      |       ^~~~~~~~~~~
/usr/include/c++/10/bits/stl_set.h:829:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const key_type&' {aka 'const ura&'}
  829 |       lower_bound(const key_type& __x)
      |                   ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_set.h:833:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::const_iterator std::set<_Key, _Compare, _Alloc>::lower_bound(const key_type&) const [with _Key = ura; _Compare = std::less<ura>; _Alloc = std::allocator<ura>; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree<ura, ura, std::_Identity<ura>, std::less<ura>, std::allocator<ura> >::const_iterator; std::set<_Key, _Compare, _Alloc>::key_type = ura]'
  833 |       lower_bound(const key_type& __x) const
      |       ^~~~~~~~~~~
/usr/include/c++/10/bits/stl_set.h:833:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const key_type&' {aka 'const ura&'}
  833 |       lower_bound(const key_type& __x) const
      |                   ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_set.h:839:2: note: candidate: 'template<class _Kt> decltype ((std::set<_Key, _Compare, _Alloc>::iterator)(((std::set<_Key, _Compare, _Alloc>*)this)->std::set<_Key, _Compare, _Alloc>::_M_t._M_lower_bound_tr(__x))) std::set<_Key, _Compare, _Alloc>::lower_bound(const _Kt&) [with _Kt = _Kt; _Key = ura; _Compare = std::less<ura>; _Alloc = std::allocator<ura>]'
  839 |  lower_bound(const _Kt& __x)
      |  ^~~~~~~~~~~
/usr/include/c++/10/bits/stl_set.h:839:2: note:   template argument deduction/substitution failed:
roads.cpp:149:81: note:   couldn't deduce template parameter '_Kt'
  149 |                 auto sus = active.lower_bound({sgt[-events[i].stare].gety(), -1});
      |                                                                                 ^
In file included from /usr/include/c++/10/set:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:87,
                 from roads.cpp:1:
/usr/include/c++/10/bits/stl_set.h:845:2: note: candidate: 'template<class _Kt> decltype ((std::set<_Key, _Compare, _Alloc>::const_iterator)(((const std::set<_Key, _Compare, _Alloc>*)this)->std::set<_Key, _Compare, _Alloc>::_M_t._M_lower_bound_tr(__x))) std::set<_Key, _Compare, _Alloc>::lower_bound(const _Kt&) const [with _Kt = _Kt; _Key = ura; _Compare = std::less<ura>; _Alloc = std::allocator<ura>]'
  845 |  lower_bound(const _Kt& __x) const
      |  ^~~~~~~~~~~
/usr/include/c++/10/bits/stl_set.h:845:2: note:   template argument deduction/substitution failed:
roads.cpp:149:81: note:   couldn't deduce template parameter '_Kt'
  149 |                 auto sus = active.lower_bound({sgt[-events[i].stare].gety(), -1});
      |                                                                                 ^
roads.cpp:151:51: error: invalid types 'segment [100001][long double]' for array subscript
  151 |                 auto jos = active.lower_bound({sgt[-events[i].stare].gety(), -1});
      |                                                   ^
roads.cpp:151:81: error: no matching function for call to 'std::set<ura>::lower_bound(<brace-enclosed initializer list>)'
  151 |                 auto jos = active.lower_bound({sgt[-events[i].stare].gety(), -1});
      |                                                                                 ^
In file included from /usr/include/c++/10/set:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:87,
                 from roads.cpp:1:
/usr/include/c++/10/bits/stl_set.h:829:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::lower_bound(const key_type&) [with _Key = ura; _Compare = std::less<ura>; _Alloc = std::allocator<ura>; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree<ura, ura, std::_Identity<ura>, std::less<ura>, std::allocator<ura> >::const_iterator; std::set<_Key, _Compare, _Alloc>::key_type = ura]'
  829 |       lower_bound(const key_type& __x)
      |       ^~~~~~~~~~~
/usr/include/c++/10/bits/stl_set.h:829:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const key_type&' {aka 'const ura&'}
  829 |       lower_bound(const key_type& __x)
      |                   ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_set.h:833:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::const_iterator std::set<_Key, _Compare, _Alloc>::lower_bound(const key_type&) const [with _Key = ura; _Compare = std::less<ura>; _Alloc = std::allocator<ura>; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree<ura, ura, std::_Identity<ura>, std::less<ura>, std::allocator<ura> >::const_iterator; std::set<_Key, _Compare, _Alloc>::key_type = ura]'
  833 |       lower_bound(const key_type& __x) const
      |       ^~~~~~~~~~~
/usr/include/c++/10/bits/stl_set.h:833:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const key_type&' {aka 'const ura&'}
  833 |       lower_bound(const key_type& __x) const
      |                   ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_set.h:839:2: note: candidate: 'template<class _Kt> decltype ((std::set<_Key, _Compare, _Alloc>::iterator)(((std::set<_Key, _Compare, _Alloc>*)this)->std::set<_Key, _Compare, _Alloc>::_M_t._M_lower_bound_tr(__x))) std::set<_Key, _Compare, _Alloc>::lower_bound(const _Kt&) [with _Kt = _Kt; _Key = ura; _Compare = std::less<ura>; _Alloc = std::allocator<ura>]'
  839 |  lower_bound(const _Kt& __x)
      |  ^~~~~~~~~~~
/usr/include/c++/10/bits/stl_set.h:839:2: note:   template argument deduction/substitution failed:
roads.cpp:151:81: note:   couldn't deduce template parameter '_Kt'
  151 |                 auto jos = active.lower_bound({sgt[-events[i].stare].gety(), -1});
      |                                                                                 ^
In file included from /usr/include/c++/10/set:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:87,
                 from roads.cpp:1:
/usr/include/c++/10/bits/stl_set.h:845:2: note: candidate: 'template<class _Kt> decltype ((std::set<_Key, _Compare, _Alloc>::const_iterator)(((const std::set<_Key, _Compare, _Alloc>*)this)->std::set<_Key, _Compare, _Alloc>::_M_t._M_lower_bound_tr(__x))) std::set<_Key, _Compare, _Alloc>::lower_bound(const _Kt&) const [with _Kt = _Kt; _Key = ura; _Compare = std::less<ura>; _Alloc = std::allocator<ura>]'
  845 |  lower_bound(const _Kt& __x) const
      |  ^~~~~~~~~~~
/usr/include/c++/10/bits/stl_set.h:845:2: note:   template argument deduction/substitution failed:
roads.cpp:151:81: note:   couldn't deduce template parameter '_Kt'
  151 |                 auto jos = active.lower_bound({sgt[-events[i].stare].gety(), -1});
      |                                                                                 ^
roads.cpp:178:27: error: invalid types 'segment [100001][long double]' for array subscript
  178 |                     if(sgt[indS].a != -INF) {
      |                           ^
roads.cpp:180:34: error: invalid types 'segment [100001][long double]' for array subscript
  180 |                     } else if(sgt[indJ].a != -INF) {
      |                                  ^