제출 #1235030

#제출 시각아이디문제언어결과실행 시간메모리
1235030colossal_pepe자리 배치 (IOI18_seats)C++20
5 / 100
1034 ms86580 KiB
#include "seats.h"
#include <bits/stdc++.h>
using namespace std;

const int INF = 1e9;

struct Node {
	int r_min, r_max, c_min, c_max;
	Node(int r, int c) : r_min(r), r_max(r), c_min(c), c_max(c) { }
	Node(int _r_min, int _r_max, int _c_min, int _c_max) : r_min(_r_min), r_max(_r_max), c_min(_c_min), c_max(_c_max) { }
};

struct SGT {
	int sz;
	const Node null_val = Node(INF, -1, INF, -1);
	vector<Node> t;

	SGT(int _sz) : sz(_sz) {
		t.resize(4 * sz, null_val);
	}

	Node merge(Node a, Node b) {
		return Node(min(a.r_min, b.r_min), max(a.r_max, b.r_max), min(a.c_min, b.c_min), max(a.c_max, b.c_max));
	}

	void update(int v, int l, int r, int i, Node x) {
		if (l == r) t[v] = x;
		else {
			int mid = (l + r) / 2;
			if (i <= mid) update(2 * v, l, mid, i, x);
			else update(2 * v + 1, mid + 1, r, i, x);
			t[v] = merge(t[2 * v], t[2 * v + 1]);
		}
	}
	void update(int i, int r, int c) { update(1, 0, sz - 1, i, Node(r, c)); }

	Node query(int v, int l, int r, int L, int R) {
		if (r < L or R < l) return null_val;
		else if (L <= l and r <= R) return t[v];
		else {
			int mid = (l + r) / 2;
			return merge(query(2 * v, l, mid, L, R), query(2 * v + 1, mid + 1, r, L, R));
		}
	}
	Node query(int l, int r) { return query(1, 0, sz - 1, l, r); }
};

int n, h, w;
vector<int> r, c;
SGT *sgt;

int area(int i) {
	Node rect = sgt->query(0, i);
	return (rect.r_max - rect.r_min + 1) * (rect.c_max - rect.c_min + 1);
}

void give_initial_chart(int H, int W, vector<int> R, vector<int> C) {
	h = H, w = W, n = H * W;
	r = R, c = C;
	if (n > 10000 or h + w > 2000) cout << "parumna" << endl;
	sgt = new SGT(n);
	for (int i = 0; i < n; i++) {
		sgt->update(i, r[i], c[i]);
	}
}

int swap_seats(int a, int b) {
	sgt->update(a, r[b], c[b]);
	sgt->update(b, r[a], c[a]);
	swap(r[a], r[b]);
	swap(c[a], c[b]);
	int ans = 0, i = 0;
	while (i < n) {
		int a = area(i);
		ans += (a == i + 1);
		i = (a == i + 1 ? i + 1 : a - 1);
	}
	return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...