Submission #347417

# Submission time Handle Problem Language Result Execution time Memory
347417 2021-01-13T02:22:41 Z guka415 Long Mansion (JOI17_long_mansion) C++14
Compilation error
0 ms 0 KB
#define _CRT_SECURE_NO_WARNINGS
#define fast ios::sync_with_stdio(false); cin.tie(0)
#define foru(i, k, n) for (int i = k; i < n; i++)
#define ford(i, k, n) for (int i = k; i >= n; i--)
#define pb push_back
#define ff first
#define ss second
 
#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
#include <queue>
#include <unordered_set>
#include <set>
 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int sz = 5e5 + 5;
int n, m, c[sz], nc[sz];
vector<int> a[sz], na[sz], adj[sz];
int lfinal[sz], rfinal[sz], closestL[sz], closestR[sz], lmn[sz], rmx[sz];
short connectedTo[sz];
vector<pii> comps;
vector<int> top;
vector<int> st[sz];
 
void input() {
	scanf("%d", &n);
	foru(i, 0, n - 1) {
		scanf("%d", &c[i]); c[i]--;
	}
	foru(i, 0, n) {
		int tmp, xx;
		scanf("%d", &tmp);
		while (tmp--) {
			scanf("%d", &xx);
			a[i].pb(--xx);
		}
	}
}
 
void computeConnectedTo() {
	foru(i, 0, n) {
      	st[i].push_back(-1);
		bool found = 0;
		if (i != 0) {
			for (int x : a[i]) {
				if (x == c[i - 1]) {
					connectedTo[i] = -1;
					found = 1;
					break;
				}
			}
			if (found)continue;
		}
		if (i != n - 1) {
			for (int x : a[i]) {
				if (x == c[i]) {
					connectedTo[i] = 1;
					found = 1;
					break;
				}
			}
			if (found)continue;
		}
	}
}
 
void computeComps() {
	int prvStart = 0;
	foru(i, 0, n) {
		if (i == n - 1 || connectedTo[i] != 1 || connectedTo[i + 1] != -1) {
			comps.pb({ prvStart,i });
			prvStart = i + 1;
		}
	}
	m = comps.size();
	unordered_set<int> mem;
	foru(i, 0, m) {
		mem.clear();
		foru(j, comps[i].ff, comps[i].ss + 1) {
			for (int x : a[j])mem.insert(x);
		}
		for (int x : mem) {
			na[i].pb(x);
			st[x].insert(i);
		}
		if (connectedTo[comps[i].ff] == -1)adj[i - 1].pb(i);
		if (connectedTo[comps[i].ss] == 1)adj[i + 1].pb(i);
		if (i != m - 1)nc[i] = c[comps[i].ss];
		lfinal[i] = rfinal[i] = i;
	}
}
 
void topoSort() {
	vector<int> indeg(m, 0);
	foru(i, 0, m) {
		for (int x : adj[i])indeg[x]++;
	}
	queue<int> q;
	foru(i, 0, m) {
		if (indeg[i] == 0)q.push(i);
	}
	while (!q.empty()) {
		int x = q.front(); q.pop();
		top.pb(x);
		for (int y : adj[x]) {
			indeg[y]--;
			if (indeg[y] == 0)q.push(y);
		}
	}
}
 
void computeClosest() {
	for (int i = 0; i < n; i++) {
		st[i].push_back(m + 1);
	}
	for (int i = 0; i < m - 1; i++) {
		auto it = st[nc[i]].upper_bound(st[nc[i]].begin(),st[nc[i]].end(),i);
		closestR[i] = (*it);
		--it;
		closestL[i] = (*it);
	}
}
 
void computeRanges() {
	int src;
	foru(i, 0, m) {
		src = top[i];
		if (connectedTo[comps[src].ff] == 0 && connectedTo[comps[src].ss] == 0)continue;
		else if (connectedTo[comps[src].ss] == 1) {
			if (lfinal[src + 1] <= src) {
				lfinal[src] = lfinal[src + 1];
				rfinal[src] = rfinal[src + 1];
				continue;
			}
			lfinal[src] = min(lfinal[src], lfinal[src + 1]);
			rfinal[src] = max(rfinal[src], rfinal[src + 1]);
		}
		else if (connectedTo[comps[src].ff] == -1) {
			if (rfinal[src - 1] >= src) {
				lfinal[src] = lfinal[src - 1];
				rfinal[src] = rfinal[src - 1];
				continue;
			}
			lfinal[src] = min(lfinal[src], lfinal[src - 1]);
			rfinal[src] = max(rfinal[src], rfinal[src - 1]);
		}
		while (true) {
			if (rfinal[src] != m - 1 && closestL[rfinal[src]] >= lfinal[src]) rfinal[src]++;
			else if (lfinal[src] != 0 && closestR[lfinal[src] - 1] <= rfinal[src]) lfinal[src]--;
			else break;
		}
	}
}
 
void computeFinal() {
	foru(i, 0, m) {
		foru(j, comps[i].ff, comps[i].ss + 1) {
			lmn[j] = comps[lfinal[i]].ff;
			rmx[j] = comps[rfinal[i]].ss;
		}
	}
}
 
int main() {
	fast;
	input();
	computeConnectedTo();
	computeComps();
	topoSort();
	computeClosest();
	computeRanges();
	computeFinal();
	int q, x, y;
	scanf("%d", &q);
	while (q--) {
		scanf("%d %d", &x, &y);
		x--; y--;
		if (y >= lmn[x] && y <= rmx[x])printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

Compilation message

long_mansion.cpp: In function 'void computeComps()':
long_mansion.cpp:91:18: error: no matching function for call to 'std::vector<int>::insert(int&)'
   91 |    st[x].insert(i);
      |                  ^
In file included from /usr/include/c++/9/vector:72,
                 from long_mansion.cpp:10:
/usr/include/c++/9/bits/vector.tcc:130:5: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; typename std::_Vector_base<_Tp, _Alloc>::pointer = int*; std::vector<_Tp, _Alloc>::const_iterator = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >; typename __gnu_cxx::__alloc_traits<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type>::const_pointer = const int*; std::vector<_Tp, _Alloc>::value_type = int]'
  130 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/9/bits/vector.tcc:130:5: note:   candidate expects 2 arguments, 1 provided
In file included from /usr/include/c++/9/vector:67,
                 from long_mansion.cpp:10:
/usr/include/c++/9/bits/stl_vector.h:1290:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; typename std::_Vector_base<_Tp, _Alloc>::pointer = int*; std::vector<_Tp, _Alloc>::const_iterator = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >; typename __gnu_cxx::__alloc_traits<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type>::const_pointer = const int*; std::vector<_Tp, _Alloc>::value_type = int]'
 1290 |       insert(const_iterator __position, value_type&& __x)
      |       ^~~~~~
/usr/include/c++/9/bits/stl_vector.h:1290:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/9/bits/stl_vector.h:1307:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; typename std::_Vector_base<_Tp, _Alloc>::pointer = int*; std::vector<_Tp, _Alloc>::const_iterator = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >; typename __gnu_cxx::__alloc_traits<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type>::const_pointer = const int*]'
 1307 |       insert(const_iterator __position, initializer_list<value_type> __l)
      |       ^~~~~~
/usr/include/c++/9/bits/stl_vector.h:1307:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/9/bits/stl_vector.h:1332:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, std::vector<_Tp, _Alloc>::size_type, const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; typename std::_Vector_base<_Tp, _Alloc>::pointer = int*; std::vector<_Tp, _Alloc>::const_iterator = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >; typename __gnu_cxx::__alloc_traits<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type>::const_pointer = const int*; std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp, _Alloc>::value_type = int]'
 1332 |       insert(const_iterator __position, size_type __n, const value_type& __x)
      |       ^~~~~~
/usr/include/c++/9/bits/stl_vector.h:1332:7: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/9/bits/stl_vector.h:1376:2: note: candidate: 'template<class _InputIterator, class> std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, _InputIterator, _InputIterator) [with _InputIterator = _InputIterator; <template-parameter-2-2> = <template-parameter-1-2>; _Tp = int; _Alloc = std::allocator<int>]'
 1376 |  insert(const_iterator __position, _InputIterator __first,
      |  ^~~~~~
/usr/include/c++/9/bits/stl_vector.h:1376:2: note:   template argument deduction/substitution failed:
long_mansion.cpp:91:18: note:   candidate expects 3 arguments, 1 provided
   91 |    st[x].insert(i);
      |                  ^
long_mansion.cpp: In function 'void computeClosest()':
long_mansion.cpp:124:23: error: 'class std::vector<int>' has no member named 'upper_bound'
  124 |   auto it = st[nc[i]].upper_bound(st[nc[i]].begin(),st[nc[i]].end(),i);
      |                       ^~~~~~~~~~~
long_mansion.cpp: In function 'void input()':
long_mansion.cpp:33:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   33 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
long_mansion.cpp:35:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   35 |   scanf("%d", &c[i]); c[i]--;
      |   ~~~~~^~~~~~~~~~~~~
long_mansion.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   39 |   scanf("%d", &tmp);
      |   ~~~~~^~~~~~~~~~~~
long_mansion.cpp:41:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   41 |    scanf("%d", &xx);
      |    ~~~~~^~~~~~~~~~~
long_mansion.cpp: In function 'int main()':
long_mansion.cpp:181:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  181 |  scanf("%d", &q);
      |  ~~~~~^~~~~~~~~~
long_mansion.cpp:183:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  183 |   scanf("%d %d", &x, &y);
      |   ~~~~~^~~~~~~~~~~~~~~~~