Submission #80641

# Submission time Handle Problem Language Result Execution time Memory
80641 2018-10-22T00:16:56 Z qkxwsm Seats (IOI18_seats) C++14
Compilation error
0 ms 0 KB
#include "seats.h"
#include <bits/stdc++.h>

using namespace std;

#define MP make_pair
#define fi first
#define se second
#define INF 1000000007
#define MAXN 1048577

typedef pair<int, int> pii;
typedef pair<pii, pii> ppp;
typedef pair<pii, int> ppi;

int N, M, K;
pii coor[MAXN];
vector<int> grid[MAXN];
pii lazy[2 * MAXN];
ppi stor[2 * MAXN];

ppi comb(ppi a, ppi b)
{
	ppi res = {{0, 0}, 0};
	if (a.fi <= b.fi)
	{
		res.fi = a.fi;
		res.se += a.se;
	}
	if (b.fi <= a.fi)
	{
		res.fi = b.fi;
		res.se += b.se;
	}
	return res;
}
void build(int w, int L, int R)
{
	lazy[w] = {0, 0};
	if (L == R)
	{
		stor[w] = {pref[L], 1};
		return;
	}
	int mid = (L + R) >> 1;
	build(w << 1, L, mid);
	build(w << 1 | 1, mid + 1, R);
	stor[w] = comb(stor[w << 1], stor[w << 1 | 1]);
}
void push(int w, int L, int R)
{
	stor[w].fi.fi += lazy[w].fi; stor[w].fi.se += lazy[w].se;
	if (L != R)
	{
		lazy[w << 1].fi += lazy[w].fi; lazy[w << 1].se += lazy[w].se;
		lazy[w << 1 | 1].fi += lazy[w].fi; lazy[w << 1 | 1].se += lazy[w].se;
	}
	lazy[w] = {0, 0};
}
void update(int w, int L, int R, int a, int b, pii v)
{
	push(w, L, R);
	if (b < L || R < a) return;
	if (a <= L && R <= b)
	{
		lazy[w].fi += v.fi; lazy[w].se += v.se;
		push(w, L, R);
		return;
	}
	int mid = (L + R) >> 1;
	update(w << 1, L, mid, a, b, v);
	update(w << 1 | 1, mid + 1, R, a, b, v);
	stor[w] = comb(stor[w << 1], stor[w << 1 | 1]);
}
void upd(int l, int r, pii p)
{
	r = min(r, K - 1);
	l = max(l, 0);
	if (l > r) return;
	update(1, 0, K - 1, l, r, p);
}

int sorta[4];
ppp sort4(int a, int b, int c, int d)
{
	sorta[0] = a; sorta[1] = b; sorta[2] = c; sorta[3] = d;
	sort(sorta, sorta + 4);
	return {{sorta[0], sorta[1]}, {sorta[2], sorta[3]}};
}

void give_initial_chart(int h, int w, vector<int> R, vector<int> C)
{
	N = h + 2;
	M = w + 2;
	K = w * h;
	for (int i = 0; i < N; i++)
	{
		grid[i].resize(M);
	}
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < M; j++)
		{
			if (i == 0 || i == N - 1 || j == 0 || j == M - 1)
			{
				grid[i][j] = K; K++;
			}
		}
	}
	pii pref[2 * MAXN];
	K = w * h;
	for (int i = 0; i < K; i++)
	{
		R[i]++; C[i]++;
		coor[i] = {R[i], C[i]};
		grid[R[i]][C[i]] = i;
		pref[i] = 0;
	}
	for (int i = 0; i < N - 1; i++)
	{
		for (int j = 0; j < M - 1; j++)
		{
			ppp p = sort4(grid[i][j], grid[i + 1][j], grid[i][j + 1], grid[i + 1][j + 1]);
			pref[p.se.fi].fi++;
			pref[p.se.se].fi--;
			pref[p.fi.fi].se++;
			pref[p.fi.se].se--;
		}
	}
	for (int i = 0; i < K; i++)
	{
		if (i)
		{
			pref[i].fi += pref[i - 1].fi;
			pref[i].se += pref[i - 1].se;
		}
	}
	build(1, 0, K - 1);
}
int swap_seats(int a, int b)
{
	pii p0 = coor[a], p1 = coor[b];
	for (int i = -1; i <= 0; i++)
	{
		for (int j = -1; j <= 0; j++)
		{
			int x, y; ppp p2, p3;
			x = p0.fi + i; y = p0.se + j;
			p2 = sort4(grid[x][y], grid[x + 1][y], grid[x][y + 1], grid[x + 1][y + 1]);
			grid[p0.fi][p0.se] = b;
			grid[p1.fi][p1.se] = a;
			p3 = sort4(grid[x][y], grid[x + 1][y], grid[x][y + 1], grid[x + 1][y + 1]);
			if (p2.fi != p3.fi)
			{
				upd(p2.fi.fi, p2.fi.se - 1, {0, -1});
				upd(p3.fi.fi, p3.fi.se - 1, {0, 1});
			}
			if (p2.se != p3.se)
			{
				upd(p2.se.fi, p2.se.se - 1, {-1, 0});
				upd(p3.se.fi, p3.se.se - 1, {1, 0});
			}
			grid[p0.fi][p0.se] = a;
			grid[p1.fi][p1.se] = b;
		}
	}
	for (int i = -1; i <= 0; i++)
	{
		for (int j = -1; j <= 0; j++)
		{
			int x, y; ppp p2, p3;
			x = p1.fi + i; y = p1.se + j;
			p2 = sort4(grid[x][y], grid[x + 1][y], grid[x][y + 1], grid[x + 1][y + 1]);
			grid[p0.fi][p0.se] = b;
			grid[p1.fi][p1.se] = a;
			p3 = sort4(grid[x][y], grid[x + 1][y], grid[x][y + 1], grid[x + 1][y + 1]);
			if (p2.fi != p3.fi)
			{
				upd(p2.fi.fi, p2.fi.se - 1, {0, -1});
				upd(p3.fi.fi, p3.fi.se - 1, {0, 1});
			}
			if (p2.se != p3.se)
			{
				upd(p2.se.fi, p2.se.se - 1, {-1, 0});
				upd(p3.se.fi, p3.se.se - 1, {1, 0});
			}
			grid[p0.fi][p0.se] = a;
			grid[p1.fi][p1.se] = b;
		}
	}
	grid[p0.fi][p0.se] = b;
	grid[p1.fi][p1.se] = a;
	swap(coor[a], coor[b]);
	push(1, 0, K - 1);
	return stor[1].se;
}

Compilation message

seats.cpp: In function 'void build(int, int, int)':
seats.cpp:42:14: error: 'pref' was not declared in this scope
   stor[w] = {pref[L], 1};
              ^~~~
seats.cpp:42:14: note: suggested alternative: 'dremf'
   stor[w] = {pref[L], 1};
              ^~~~
              dremf
seats.cpp:42:24: error: no match for 'operator=' (operand types are 'ppi {aka std::pair<std::pair<int, int>, int>}' and '<brace-enclosed initializer list>')
   stor[w] = {pref[L], 1};
                        ^
In file included from /usr/include/c++/7/bits/stl_algobase.h:64:0,
                 from /usr/include/c++/7/vector:60,
                 from seats.h:3,
                 from seats.cpp:1:
/usr/include/c++/7/bits/stl_pair.h:367:7: note: candidate: std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(typename std::conditional<std::__and_<std::is_copy_assignable<_Tp>, std::is_copy_assignable<_T2> >::value, const std::pair<_T1, _T2>&, const std::__nonesuch_no_braces&>::type) [with _T1 = std::pair<int, int>; _T2 = int; typename std::conditional<std::__and_<std::is_copy_assignable<_Tp>, std::is_copy_assignable<_T2> >::value, const std::pair<_T1, _T2>&, const std::__nonesuch_no_braces&>::type = const std::pair<std::pair<int, int>, int>&]
       operator=(typename conditional<
       ^~~~~~~~
/usr/include/c++/7/bits/stl_pair.h:367:7: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::conditional<true, const std::pair<std::pair<int, int>, int>&, const std::__nonesuch_no_braces&>::type {aka const std::pair<std::pair<int, int>, int>&}'
/usr/include/c++/7/bits/stl_pair.h:384:7: note: candidate: std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(typename std::conditional<std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value, std::pair<_T1, _T2>&&, std::__nonesuch_no_braces&&>::type) [with _T1 = std::pair<int, int>; _T2 = int; typename std::conditional<std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value, std::pair<_T1, _T2>&&, std::__nonesuch_no_braces&&>::type = std::pair<std::pair<int, int>, int>&&]
       operator=(typename conditional<
       ^~~~~~~~
/usr/include/c++/7/bits/stl_pair.h:384:7: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::conditional<true, std::pair<std::pair<int, int>, int>&&, std::__nonesuch_no_braces&&>::type {aka std::pair<std::pair<int, int>, int>&&}'
/usr/include/c++/7/bits/stl_pair.h:400:2: note: candidate: template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<_T1&, const _U1&>, std::is_assignable<_T2&, const _U2&> >::value, std::pair<_T1, _T2>&>::type std::pair<_T1, _T2>::operator=(const std::pair<_U1, _U2>&) [with _U1 = _U1; _U2 = _U2; _T1 = std::pair<int, int>; _T2 = int]
  operator=(const pair<_U1, _U2>& __p)
  ^~~~~~~~
/usr/include/c++/7/bits/stl_pair.h:400:2: note:   template argument deduction/substitution failed:
seats.cpp:42:24: note:   couldn't deduce template parameter '_U1'
   stor[w] = {pref[L], 1};
                        ^
In file included from /usr/include/c++/7/bits/stl_algobase.h:64:0,
                 from /usr/include/c++/7/vector:60,
                 from seats.h:3,
                 from seats.cpp:1:
/usr/include/c++/7/bits/stl_pair.h:411:2: note: candidate: template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<_T1&, _U1&&>, std::is_assignable<_T2&, _U2&&> >::value, std::pair<_T1, _T2>&>::type std::pair<_T1, _T2>::operator=(std::pair<_U1, _U2>&&) [with _U1 = _U1; _U2 = _U2; _T1 = std::pair<int, int>; _T2 = int]
  operator=(pair<_U1, _U2>&& __p)
  ^~~~~~~~
/usr/include/c++/7/bits/stl_pair.h:411:2: note:   template argument deduction/substitution failed:
seats.cpp:42:24: note:   couldn't deduce template parameter '_U1'
   stor[w] = {pref[L], 1};
                        ^
seats.cpp: In function 'void give_initial_chart(int, int, std::vector<int>, std::vector<int>)':
seats.cpp:117:13: error: no match for 'operator=' (operand types are 'pii {aka std::pair<int, int>}' and 'int')
   pref[i] = 0;
             ^
In file included from /usr/include/c++/7/bits/stl_algobase.h:64:0,
                 from /usr/include/c++/7/vector:60,
                 from seats.h:3,
                 from seats.cpp:1:
/usr/include/c++/7/bits/stl_pair.h:367:7: note: candidate: std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(typename std::conditional<std::__and_<std::is_copy_assignable<_Tp>, std::is_copy_assignable<_T2> >::value, const std::pair<_T1, _T2>&, const std::__nonesuch_no_braces&>::type) [with _T1 = int; _T2 = int; typename std::conditional<std::__and_<std::is_copy_assignable<_Tp>, std::is_copy_assignable<_T2> >::value, const std::pair<_T1, _T2>&, const std::__nonesuch_no_braces&>::type = const std::pair<int, int>&]
       operator=(typename conditional<
       ^~~~~~~~
/usr/include/c++/7/bits/stl_pair.h:367:7: note:   no known conversion for argument 1 from 'int' to 'std::conditional<true, const std::pair<int, int>&, const std::__nonesuch_no_braces&>::type {aka const std::pair<int, int>&}'
/usr/include/c++/7/bits/stl_pair.h:384:7: note: candidate: std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(typename std::conditional<std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value, std::pair<_T1, _T2>&&, std::__nonesuch_no_braces&&>::type) [with _T1 = int; _T2 = int; typename std::conditional<std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value, std::pair<_T1, _T2>&&, std::__nonesuch_no_braces&&>::type = std::pair<int, int>&&]
       operator=(typename conditional<
       ^~~~~~~~
/usr/include/c++/7/bits/stl_pair.h:384:7: note:   no known conversion for argument 1 from 'int' to 'std::conditional<true, std::pair<int, int>&&, std::__nonesuch_no_braces&&>::type {aka std::pair<int, int>&&}'
/usr/include/c++/7/bits/stl_pair.h:400:2: note: candidate: template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<_T1&, const _U1&>, std::is_assignable<_T2&, const _U2&> >::value, std::pair<_T1, _T2>&>::type std::pair<_T1, _T2>::operator=(const std::pair<_U1, _U2>&) [with _U1 = _U1; _U2 = _U2; _T1 = int; _T2 = int]
  operator=(const pair<_U1, _U2>& __p)
  ^~~~~~~~
/usr/include/c++/7/bits/stl_pair.h:400:2: note:   template argument deduction/substitution failed:
seats.cpp:117:13: note:   mismatched types 'const std::pair<_T1, _T2>' and 'int'
   pref[i] = 0;
             ^
In file included from /usr/include/c++/7/bits/stl_algobase.h:64:0,
                 from /usr/include/c++/7/vector:60,
                 from seats.h:3,
                 from seats.cpp:1:
/usr/include/c++/7/bits/stl_pair.h:411:2: note: candidate: template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<_T1&, _U1&&>, std::is_assignable<_T2&, _U2&&> >::value, std::pair<_T1, _T2>&>::type std::pair<_T1, _T2>::operator=(std::pair<_U1, _U2>&&) [with _U1 = _U1; _U2 = _U2; _T1 = int; _T2 = int]
  operator=(pair<_U1, _U2>&& __p)
  ^~~~~~~~
/usr/include/c++/7/bits/stl_pair.h:411:2: note:   template argument deduction/substitution failed:
seats.cpp:117:13: note:   mismatched types 'std::pair<_T1, _T2>' and 'int'
   pref[i] = 0;
             ^