Submission #35369546


Source Code Expand

#include <bits/stdc++.h>
#define R(i, a, b) for (auto i = (a); i < (b); ++i)
#define L(i, a, b) for (auto i = (b) - 1; i >= (a); --i)
#define N(a) int((a).size())
#define V(a) (a).begin(), (a).end()
#define P make_pair
#define spc << ' '
#define ntr << '\n'
#define X(a) cerr << #a << " = " << a
#define T() cerr << "TIME = " << double(clock() - T0) / CLOCKS_PER_SEC
using namespace std;
using i64 = long long;
clock_t T0 = clock();
template<typename tp>
ostream &operator<<(ostream &ost, const pair<tp, tp> &a) {
	for (tp i = a.first; i != a.second; ++i) ost << setw(3) << *i;
	return ost;
}
constexpr int xN = 300000 + 7, xX = 1000000 + 7;
int N, M;
int mx, X[xN], D[xN];
template<typename tp>
struct iarr {
	tp a[xX * 2], *b = a + xX;
	tp &operator[](int i) {
		return b[i];
	}
	const tp operator[](int i) const {
		return b[i];
	}
};
template<typename tp>
ostream &operator<<(ostream &ost, const iarr<tp> &a) {
	R(i, -mx, mx + 1) ost << setw(3) << a[i];
	return ost;
}
iarr<bool> zer;
iarr<int> te, tur;
int fr(int u) {
	return u == te[u] ? u : te[u] = fr(te[u]);
}
struct seg {
	int l, r, p;
	int size() const {
		return r + 1 - l;
	}
	bool inl(int i) {
		return l <= i and i <= r;
	}
	bool inp(int i) {
		return p <= i and i < p + size();
	}
	int fp(int i) {
		assert(inl(i));
		return p + (i - l);
	}
	int fl(int i) {
		assert(inp(i));
		return l + (i - p);
	}
	void check_zero(int i, int m) {
		if (inl(m)) {
			zer[fp(m)] = zer[-fp(m)] = true;
			tur[fp(m)] = tur[-fp(m)] = i;
		}
	}
	seg shift(int i) {
		int m = D[i];
		if (m < l) return {l - m, r - m, p};
		if (m * 2 <= l + r) {
			R(i, 0, m - l) {
				te[fr(fp(l + i))] = fr(-fp(m + m - l - i));
				te[fr(-fp(l + i))] = fr(fp(m + m - l - i));
			}
			check_zero(i, m);
			if (1 > r - m) return {-1, -1, -1};
			return {1, r - m, fp(m + 1)};
		}
		if (m > r) return {m - r, m - l, -fp(r)};
		R(i, 0, r - m) {
			te[fr(fp(r - i))] = fr(-fp(m + m - r + i));
			te[fr(-fp(r - i))] = fr(fp(m + m - r + i));
		}
		check_zero(i, m);
		if (1 > m - l) return {-1, -1, -1};
		return {1, m - l, -fp(m - 1)};
	}
	int pos(int i) {
		if (inp(i)) return fl(i);
		return -fl(-i);
	}
};
int main() {
	cerr << fixed << setprecision(3);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> N >> M;
	R(i, 0, N) cin >> X[i];
	R(i, 0, M) cin >> D[i];
	mx = *max_element(X, X + N);
	R(i, -mx, mx + 1) te[i] = i;
	seg s = {1, mx, 1};
	R(i, 0, M) if (!~(s = s.shift(i)).l) break;
	R(i, 0, N) {
		int u = fr(X[i]);
		if (zer[u]) cout << "Yes" spc << tur[u] + 1 ntr;
		else cout << "No" spc << s.pos(u) ntr;
	}
}

Submission Info

Submission Time
Task D - Simultaneous Sugoroku
User George1123
Language C++ (GCC 9.2.1)
Score 700
Code Size 2662 Byte
Status AC
Exec Time 103 ms
Memory 23548 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 1
AC × 33
Set Name Test Cases
Sample 01_sample_01.txt
All 01_sample_01.txt, 02_small_01.txt, 02_small_02.txt, 02_small_03.txt, 02_small_04.txt, 02_small_05.txt, 02_small_06.txt, 02_small_07.txt, 02_small_08.txt, 02_small_09.txt, 02_small_10.txt, 03_rand_01.txt, 03_rand_02.txt, 03_rand_03.txt, 03_rand_04.txt, 03_rand_05.txt, 03_rand_06.txt, 03_rand_07.txt, 03_rand_08.txt, 03_rand_09.txt, 03_rand_10.txt, 04_small_d_01.txt, 04_small_d_02.txt, 04_small_d_03.txt, 04_small_d_04.txt, 04_small_d_05.txt, 05_large_d_01.txt, 05_large_d_02.txt, 05_large_d_03.txt, 05_large_d_04.txt, 05_large_d_05.txt, 06_handmade_01.txt, 06_handmade_02.txt
Case Name Status Exec Time Memory
01_sample_01.txt AC 7 ms 3552 KiB
02_small_01.txt AC 2 ms 3580 KiB
02_small_02.txt AC 7 ms 3584 KiB
02_small_03.txt AC 3 ms 3644 KiB
02_small_04.txt AC 2 ms 3584 KiB
02_small_05.txt AC 3 ms 3576 KiB
02_small_06.txt AC 2 ms 3680 KiB
02_small_07.txt AC 2 ms 3696 KiB
02_small_08.txt AC 3 ms 3672 KiB
02_small_09.txt AC 3 ms 3576 KiB
02_small_10.txt AC 2 ms 3608 KiB
03_rand_01.txt AC 98 ms 14184 KiB
03_rand_02.txt AC 97 ms 14008 KiB
03_rand_03.txt AC 97 ms 14116 KiB
03_rand_04.txt AC 103 ms 14108 KiB
03_rand_05.txt AC 93 ms 14088 KiB
03_rand_06.txt AC 97 ms 14068 KiB
03_rand_07.txt AC 96 ms 14032 KiB
03_rand_08.txt AC 102 ms 14088 KiB
03_rand_09.txt AC 98 ms 14052 KiB
03_rand_10.txt AC 96 ms 14156 KiB
04_small_d_01.txt AC 99 ms 23492 KiB
04_small_d_02.txt AC 98 ms 23408 KiB
04_small_d_03.txt AC 97 ms 23548 KiB
04_small_d_04.txt AC 96 ms 23448 KiB
04_small_d_05.txt AC 99 ms 23544 KiB
05_large_d_01.txt AC 83 ms 13920 KiB
05_large_d_02.txt AC 88 ms 14108 KiB
05_large_d_03.txt AC 81 ms 13904 KiB
05_large_d_04.txt AC 85 ms 14076 KiB
05_large_d_05.txt AC 83 ms 13864 KiB
06_handmade_01.txt AC 79 ms 16592 KiB
06_handmade_02.txt AC 82 ms 13728 KiB