Submission #768464

#TimeUsernameProblemLanguageResultExecution timeMemory
768464SanguineChameleonSeats (IOI18_seats)C++17
Compilation error
0 ms0 KiB
#include "seats.h"
#include <bits/stdc++.h>
using namespace std;

const int maxN = 1e6 + 20;
pair<int, int> tree[maxN * 4];
int lazy[maxN * 4];
int R[maxN];
int C[maxN];
vector<vector<int>> seats;
int N;

void build_tree(int id, int lt, int rt) {
	if (lt == rt) {
		tree[id] = make_pair(0, 1);
		return;
	}
	int mt = (lt + rt) >> 1;
	build_tree(id << 1, lt, mt);
	build_tree(id << 1 | 1, mt + 1, rt);
	tree[id] = make_pair(0, rt - lt + 1);
}

void update_tree(int id, int lt, int rt, int ql, int qr, int add) {
	if (lt == ql && rt == qr) {
		tree[id].first += add;
		lazy[id] += add;
		return;
	}
	tree[id << 1].first += lazy[id];
	lazy[id << 1] += lazy[id];
	tree[id << 1 | 1].first += lazy[id];
	lazy[id << 1 | 1] += lazy[id];
	lazy[id] = 0;
	int mt = (lt + rt) >> 1;
	if (qr <= mt) {
		update_tree(id << 1, lt, mt, ql, qr, add);
	}
	else if (ql >= mt + 1) {
		update_tree(id << 1 | 1, mt + 1, rt, ql, qr, add);
	}
	else {
		update_tree(id << 1, lt, mt, ql, mt, add);
		update_tree(id << 1 | 1, mt + 1, rt, mt + 1, qr, add);
	}
	tree[id].first = min(tree[id << 1].first, tree[id << 1 | 1].first);
	tree[id].second = (tree[id << 1].first == tree[id].first ? tree[id << 1].second : 0) + (tree[id << 1 | 1].first == tree[id].first ? tree[id << 1 | 1].second : 0);
}

void update_square(int i, int j) {
	//vector<int> vals = {seats[i][j], seats[i][j + 1], seats[i + 1][j], seats[i + 1][j + 1]};
	//sort(vals.begin(), vals.end());
	if (vals[0] < vals[1]) {
		update_tree(1, 1, N, vals[0], vals[1] - 1, add);
	}
	if (vals[2] < vals[3]) {
		update_tree(1, 1, N, vals[2], vals[3] - 1, add);
	}
}

void update_pos(int i, int j, int val) {
	update_square(i - 1, j - 1, -1);
	update_square(i - 1, j, -1);
	update_square(i, j - 1, -1);
	update_square(i, j, -1);
	seats[i][j] = val;
	update_square(i - 1, j - 1, 1);
	update_square(i - 1, j, 1);
	update_square(i, j - 1, 1);
	update_square(i, j, 1);
}

void give_initial_chart(int H, int W, vector<int> _R, vector<int> _C) {
	H = H;
	W = W;
	N = H * W;
	seats.resize(H + 2, vector<int>(W + 2, N + 1));
	build_tree(1, 1, N);
	for (int i = 1; i <= N; i++) {
		R[i] = _R[i - 1] + 1;
		C[i] = _C[i - 1] + 1;
		update_pos(R[i], C[i], i);
	}
}

int swap_seats(int a, int b) {
	a++;
	b++;
	update_pos(R[a], C[a], b);
	update_pos(R[b], C[b], a);
	swap(R[a], R[b]);
	swap(C[a], C[b]);
	return tree[1].second;
}

Compilation message (stderr)

seats.cpp: In function 'void update_square(int, int)':
seats.cpp:53:6: error: 'vals' was not declared in this scope
   53 |  if (vals[0] < vals[1]) {
      |      ^~~~
seats.cpp:54:46: error: 'add' was not declared in this scope; did you mean 'std::filesystem::perm_options::add'?
   54 |   update_tree(1, 1, N, vals[0], vals[1] - 1, add);
      |                                              ^~~
      |                                              std::filesystem::perm_options::add
In file included from /usr/include/c++/10/filesystem:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from seats.cpp:2:
/usr/include/c++/10/bits/fs_fwd.h:202:7: note: 'std::filesystem::perm_options::add' declared here
  202 |       add = 0x2,
      |       ^~~
seats.cpp:56:6: error: 'vals' was not declared in this scope
   56 |  if (vals[2] < vals[3]) {
      |      ^~~~
seats.cpp:57:46: error: 'add' was not declared in this scope; did you mean 'std::filesystem::perm_options::add'?
   57 |   update_tree(1, 1, N, vals[2], vals[3] - 1, add);
      |                                              ^~~
      |                                              std::filesystem::perm_options::add
In file included from /usr/include/c++/10/filesystem:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from seats.cpp:2:
/usr/include/c++/10/bits/fs_fwd.h:202:7: note: 'std::filesystem::perm_options::add' declared here
  202 |       add = 0x2,
      |       ^~~
seats.cpp: In function 'void update_pos(int, int, int)':
seats.cpp:62:32: error: too many arguments to function 'void update_square(int, int)'
   62 |  update_square(i - 1, j - 1, -1);
      |                                ^
seats.cpp:50:6: note: declared here
   50 | void update_square(int i, int j) {
      |      ^~~~~~~~~~~~~
seats.cpp:63:28: error: too many arguments to function 'void update_square(int, int)'
   63 |  update_square(i - 1, j, -1);
      |                            ^
seats.cpp:50:6: note: declared here
   50 | void update_square(int i, int j) {
      |      ^~~~~~~~~~~~~
seats.cpp:64:28: error: too many arguments to function 'void update_square(int, int)'
   64 |  update_square(i, j - 1, -1);
      |                            ^
seats.cpp:50:6: note: declared here
   50 | void update_square(int i, int j) {
      |      ^~~~~~~~~~~~~
seats.cpp:65:24: error: too many arguments to function 'void update_square(int, int)'
   65 |  update_square(i, j, -1);
      |                        ^
seats.cpp:50:6: note: declared here
   50 | void update_square(int i, int j) {
      |      ^~~~~~~~~~~~~
seats.cpp:67:31: error: too many arguments to function 'void update_square(int, int)'
   67 |  update_square(i - 1, j - 1, 1);
      |                               ^
seats.cpp:50:6: note: declared here
   50 | void update_square(int i, int j) {
      |      ^~~~~~~~~~~~~
seats.cpp:68:27: error: too many arguments to function 'void update_square(int, int)'
   68 |  update_square(i - 1, j, 1);
      |                           ^
seats.cpp:50:6: note: declared here
   50 | void update_square(int i, int j) {
      |      ^~~~~~~~~~~~~
seats.cpp:69:27: error: too many arguments to function 'void update_square(int, int)'
   69 |  update_square(i, j - 1, 1);
      |                           ^
seats.cpp:50:6: note: declared here
   50 | void update_square(int i, int j) {
      |      ^~~~~~~~~~~~~
seats.cpp:70:23: error: too many arguments to function 'void update_square(int, int)'
   70 |  update_square(i, j, 1);
      |                       ^
seats.cpp:50:6: note: declared here
   50 | void update_square(int i, int j) {
      |      ^~~~~~~~~~~~~