Submission #287451

# Submission time Handle Problem Language Result Execution time Memory
287451 2020-08-31T17:07:24 Z Namnamseo Traffic (CEOI11_tra) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
void read(int& x){ scanf("%d",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define x first
#define y second
const int inf=1e9;

int n, A, B;

pp data[300010];
vector<int> ed[300010];
vector<int> re[300010];

void in(){
	int m;
	read(n, m, A, B);
	for(int i=1; i<=n; ++i){
		int x, y; read(x, y);
		data[i] = {x, y};
	}
	for(;m--;){
		int f, t, k;
		read(f, t, k);
		ed[f].pb(t);
		re[t].pb(f);
		if(k != 1) ed[t].pb(f), re[f].pb(t);
	}
}

vector<int> right;
int miny[300010];
int maxy[300010];

bool vis[300010];

void bfs(){
	queue<int> q;
	for(int i=1; i<=n; ++i) if(data[i].x == 0) q.push(i), vis[i]=1;
	while(q.size()){
		int x=q.front(); q.pop();
		for(int y:ed[x]){
			if(!vis[y]) vis[y]=1, q.push(y);
		}
	}
}

void sep(){
	fill(miny+1, miny+n+1, inf);
	fill(maxy+1, maxy+n+1, -inf);
	vector<int> ys;
	for(int i=1; i<=n; ++i) if(data[i].x == A && vis[i]) ys.pb(data[i].y);
	sort(all(ys)); ys.erase(unique(all(ys)), ys.end());
	for(int i=1; i<=n; ++i) if(data[i].x == A && vis[i]){
		miny[i] = maxy[i] = lower_bound(all(ys), data[i].y) - ys.begin();
	}
}

void dijk(){
	priority_queue<pp> pq;
	for(int i=1; i<=n; ++i) if(data[i].x == A){
		pq.push(pp{-miny[i], i});
	}
	while(pq.size()){
		int d, i; tie(d, i) = pq.top(); pq.pop(); d=-d;
		if(d != miny[i]) continue;
		for(int y:re[i]) if(miny[y] > d){
			miny[y]=d;
			pq.push(pp{-miny[y], y});
		}
	}
	
	for(int i=1; i<=n; ++i) if(data[i].x == A){
		pq.push(pp{maxy[i], i});
	}
	while(pq.size()){
		int d, i; tie(d, i) = pq.top(); pq.pop();
		if(d != maxy[i]) continue;
		for(int y:re[i]) if(maxy[y] < d){
			maxy[y]=d;
			pq.push(pp{maxy[y], y});
		}
	}
}

int main()
{
    in(); bfs(); sep(); dijk();
    vector<pp> ans;
    for(int i=1; i<=n; ++i) if(data[i].x == 0){
		if(maxy[i] == -inf) maxy[i]=0, miny[i]=1;
		ans.pb(pp{data[i].y, maxy[i] - miny[i] + 1});
    }
    sort(all(ans)); reverse(all(ans));
    for(auto tmp:ans) printf("%d\n", tmp.second);
    return 0;
}

Compilation message

tra.cpp: In function 'void in()':
tra.cpp:25:3: error: reference to 'data' is ambiguous
   25 |   data[i] = {x, y};
      |   ^~~~
In file included from /usr/include/c++/9/string:54,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from tra.cpp:1:
/usr/include/c++/9/bits/range_access.h:318:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)'
  318 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:309:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  309 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:299:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  299 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:289:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  289 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
tra.cpp:16:4: note:                 'pp data [300010]'
   16 | pp data[300010];
      |    ^~~~
tra.cpp: In function 'void bfs()':
tra.cpp:44:29: error: reference to 'data' is ambiguous
   44 |  for(int i=1; i<=n; ++i) if(data[i].x == 0) q.push(i), vis[i]=1;
      |                             ^~~~
In file included from /usr/include/c++/9/string:54,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from tra.cpp:1:
/usr/include/c++/9/bits/range_access.h:318:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)'
  318 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:309:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  309 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:299:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  299 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:289:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  289 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
tra.cpp:16:4: note:                 'pp data [300010]'
   16 | pp data[300010];
      |    ^~~~
tra.cpp: In function 'void sep()':
tra.cpp:57:29: error: reference to 'data' is ambiguous
   57 |  for(int i=1; i<=n; ++i) if(data[i].x == A && vis[i]) ys.pb(data[i].y);
      |                             ^~~~
In file included from /usr/include/c++/9/string:54,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from tra.cpp:1:
/usr/include/c++/9/bits/range_access.h:318:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)'
  318 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:309:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  309 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:299:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  299 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:289:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  289 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
tra.cpp:16:4: note:                 'pp data [300010]'
   16 | pp data[300010];
      |    ^~~~
tra.cpp:57:61: error: reference to 'data' is ambiguous
   57 |  for(int i=1; i<=n; ++i) if(data[i].x == A && vis[i]) ys.pb(data[i].y);
      |                                                             ^~~~
In file included from /usr/include/c++/9/string:54,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from tra.cpp:1:
/usr/include/c++/9/bits/range_access.h:318:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)'
  318 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:309:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  309 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:299:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  299 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:289:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  289 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
tra.cpp:16:4: note:                 'pp data [300010]'
   16 | pp data[300010];
      |    ^~~~
tra.cpp:59:29: error: reference to 'data' is ambiguous
   59 |  for(int i=1; i<=n; ++i) if(data[i].x == A && vis[i]){
      |                             ^~~~
In file included from /usr/include/c++/9/string:54,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from tra.cpp:1:
/usr/include/c++/9/bits/range_access.h:318:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)'
  318 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:309:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  309 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:299:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  299 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:289:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  289 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
tra.cpp:16:4: note:                 'pp data [300010]'
   16 | pp data[300010];
      |    ^~~~
tra.cpp:60:44: error: reference to 'data' is ambiguous
   60 |   miny[i] = maxy[i] = lower_bound(all(ys), data[i].y) - ys.begin();
      |                                            ^~~~
In file included from /usr/include/c++/9/string:54,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from tra.cpp:1:
/usr/include/c++/9/bits/range_access.h:318:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)'
  318 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:309:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  309 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:299:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  299 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:289:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  289 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
tra.cpp:16:4: note:                 'pp data [300010]'
   16 | pp data[300010];
      |    ^~~~
tra.cpp: In function 'void dijk()':
tra.cpp:66:29: error: reference to 'data' is ambiguous
   66 |  for(int i=1; i<=n; ++i) if(data[i].x == A){
      |                             ^~~~
In file included from /usr/include/c++/9/string:54,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from tra.cpp:1:
/usr/include/c++/9/bits/range_access.h:318:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)'
  318 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:309:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  309 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:299:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  299 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:289:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  289 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
tra.cpp:16:4: note:                 'pp data [300010]'
   16 | pp data[300010];
      |    ^~~~
tra.cpp:78:29: error: reference to 'data' is ambiguous
   78 |  for(int i=1; i<=n; ++i) if(data[i].x == A){
      |                             ^~~~
In file included from /usr/include/c++/9/string:54,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from tra.cpp:1:
/usr/include/c++/9/bits/range_access.h:318:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)'
  318 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:309:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  309 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:299:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  299 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:289:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  289 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
tra.cpp:16:4: note:                 'pp data [300010]'
   16 | pp data[300010];
      |    ^~~~
tra.cpp: In function 'int main()':
tra.cpp:95:32: error: reference to 'data' is ambiguous
   95 |     for(int i=1; i<=n; ++i) if(data[i].x == 0){
      |                                ^~~~
In file included from /usr/include/c++/9/string:54,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from tra.cpp:1:
/usr/include/c++/9/bits/range_access.h:318:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)'
  318 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:309:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  309 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:299:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  299 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:289:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  289 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
tra.cpp:16:4: note:                 'pp data [300010]'
   16 | pp data[300010];
      |    ^~~~
tra.cpp:97:30: error: no matching function for call to 'std::pair<int, int>::pair(<brace-enclosed initializer list>)'
   97 |   ans.pb(pp{data[i].y, maxy[i] - miny[i] + 1});
      |                              ^
In file included from /usr/include/c++/9/bits/stl_algobase.h:64,
                 from /usr/include/c++/9/bits/specfun.h:45,
                 from /usr/include/c++/9/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:41,
                 from tra.cpp:1:
/usr/include/c++/9/bits/stl_pair.h:436:9: note: candidate: 'template<class ... _Args1, long unsigned int ..._Indexes1, class ... _Args2, long unsigned int ..._Indexes2> std::pair<_T1, _T2>::pair(std::tuple<_Args1 ...>&, std::tuple<_Args2 ...>&, std::_Index_tuple<_Indexes1 ...>, std::_Index_tuple<_Indexes2 ...>)'
  436 |         pair(tuple<_Args1...>&, tuple<_Args2...>&,
      |         ^~~~
/usr/include/c++/9/bits/stl_pair.h:436:9: note:   template argument deduction/substitution failed:
/usr/include/c++/9/bits/stl_pair.h:375:9: note: candidate: 'template<class ... _Args1, class ... _Args2> std::pair<_T1, _T2>::pair(std::piecewise_construct_t, std::tuple<_Args1 ...>, std::tuple<_Args2 ...>)'
  375 |         pair(piecewise_construct_t, tuple<_Args1...>, tuple<_Args2...>);
      |         ^~~~
/usr/include/c++/9/bits/stl_pair.h:375:9: note:   template argument deduction/substitution failed:
/usr/include/c++/9/bits/stl_pair.h:370:21: note: candidate: 'template<class _U1, class _U2, typename std::enable_if<(std::_PCC<((! std::is_same<int, _U1>::value) || (! std::is_same<int, _U2>::value)), int, int>::_MoveConstructiblePair<_U1, _U2>() && (! std::_PCC<((! std::is_same<int, _U1>::value) || (! std::is_same<int, _U2>::value)), int, int>::_ImplicitlyMoveConvertiblePair<_U1, _U2>())), bool>::type <anonymous> > constexpr std::pair<_T1, _T2>::pair(std::pair<_U1, _U2>&&)'
  370 |  explicit constexpr pair(pair<_U1, _U2>&& __p)
      |                     ^~~~
/usr/include/c++/9/bits/stl_pair.h:370:21: note:   template argument deduction/substitution failed:
/usr/include/c++/9/bits/stl_pair.h:360:12: note: candidate: 'template<class _U1, class _U2, typename std::enable_if<(std::_PCC<((! std::is_same<int, _U1>::value) || (! std::is_same<int, _U2>::value)), int, int>::_MoveConstructiblePair<_U1, _U2>() && std::_PCC<((! std::is_same<int, _U1>::value) || (! std::is_same<int, _U2>::value)), int, int>::_ImplicitlyMoveConvertiblePair<_U1, _U2>()), bool>::type <anonymous> > constexpr std::pair<_T1, _T2>::pair(std::pair<_U1, _U2>&&)'
  360 |  constexpr pair(pair<_U1, _U2>&& __p)
      |            ^~~~
/usr/include/c++/9/bits/stl_pair.h:360:12: note:   template argument deduction/substitution failed:
/usr/include/c++/9/bits/stl_pair.h:350:21: note: candidate: 'template<class _U1, class _U2, typename std::enable_if<(_MoveConstructiblePair<_U1, _U2>() && (! _ImplicitlyMoveConvertiblePair<_U1, _U2>())), bool>::type <anonymous> > constexpr std::pair<_T1, _T2>::pair(_U1&&, _U2&&)'
  350 |  explicit constexpr pair(_U1&& __x, _U2&& __y)
      |                     ^~~~
/usr/inc