Language: C++

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

std::pair<bool, int> x0_pos(int64_t n, int64_t l, int64_t t, int64_t *x, int64_t *w) { // true if it's forwarding
	t *= 2;
	// assume w[0] = true
	// first collision of x[0] ahead
	int first_col;
	int first_col_dist = 1000000001;
	for (int i = 1; i < n; i++) {
		if (w[i]) continue;
		int dist = (x[i] - x[0] + l) % l;
		if (dist < first_col_dist) first_col_dist = dist, first_col = i;
	}
	std::cerr << "dist:" << first_col_dist << " i:" << first_col << std::endl;
	if (t <= first_col_dist) return {true, x[0]};
	t -= first_col_dist;
	std::vector<int> inv;
	std::vector<int> ahead;
	for (int i = 0; i < n; i++) if (!w[i]) inv.push_back(x[i]); else ahead.push_back(x[i]);
	std::sort(inv.begin(), inv.end()); //******************//
	std::sort(ahead.begin(), ahead.end()); // *************** //
	std::vector<int64_t> interval_ahead;
	std::vector<int64_t> interval_inv;
	if (ahead.size() > 1) {
		for (int i = ahead.size() - 1; i >= 0; i--) {
			int64_t x2 = ahead[(i + 1) % ahead.size()];
			int64_t x1 = ahead[i];
			int64_t dist = (x2 - x1 + l) % l;
			interval_ahead.push_back(dist);
		}
		assert(std::accumulate(interval_ahead.begin(), interval_ahead.end(), 0LL) == l);
	} else interval_ahead.push_back(l);
	if (inv.size() > 1) {
		int first_col_comp = -1;
		for (int i = 0; i < (int) inv.size(); i++) if (inv[i] == x[first_col]) first_col_comp = i;
		assert(first_col_comp != -=1);
		for (int i = 0; i < (int) inv.size(); i++) {
			// first_col, first_col + 1
			int64_t x2 = inv[(i + first_col_comp + 1) % inv.size()];
			int64_t x1 = inv[(i + first_col_comp) % inv.size()];
			int64_t dist = (x2 - x1 + l) % l;
			interval_inv.push_back(dist);
		}
		assert(std::accumulate(interval_inv.begin(), interval_inv.end(), 0LL) == l);
	} else interval_inv.push_back(l);
	for (auto i : interval_inv) std::cerr << i << " ";
	std::cerr << std::endl;
	for (auto i : interval_ahead) std::cerr << i << " ";
	std::cerr << std::endl;
	int64_t ll = -1;
	int64_t rr = 1000000001;
	while (rr - ll > 1) {
		int64_t m = ll + (rr - ll) / 2;
		// m times
		int64_t r0 = (int64_t) m / interval_ahead.size() * l;
		for (int i = 0; i < m % interval_ahead.size(); i++) r0 += interval_ahead[i];
		int64_t r1 = (int64_t) m / interval_inv.size() * l;
		for (int i = 0; i < m % interval_inv.size(); i++) r1 += interval_inv[i];
		if (r0 + r1 > t) rr = m;
		else ll = m;
	}
	std::cerr << "ll:" << ll << std::endl;
	int64_t r0 = ll / interval_ahead.size() * l;
	for (int i = 0; i < ll % interval_ahead.size(); i++) r0 += interval_ahead[i];
	int64_t r1 = ll / interval_inv.size() * l;
	for (int i = 0; i < ll % interval_inv.size(); i++) r1 += interval_inv[i];
	int64_t res = 0;
	res -= r0;
	t -= r0 + r1;
	// l ~ r
	std::cerr << "t-tt:" << t - (r0 + r1) << " int_ahead:" << interval_ahead[ll % interval_ahead.size()] << std::endl;
	res -= std::min<int64_t>(t, interval_ahead[ll % interval_ahead.size()]);
	bool dir;
	if (!t) dir = true;
	else if (t == interval_ahead[ll % interval_ahead.size()]) dir = false;
	else dir = true; // nothing
	return {dir, (res % l + x[0] + l) % l};
}

int main() {
	int n = ri(), l = ri(), t = ri();
	int64_t x[n], w[n];
	for (int i = 0; i < n; i++) x[i] = ri(), w[i] = !(ri() - 1); // 1 => +
	bool same = true;
	for (int i = 0; i + 1 < n; i++) if (w[i] != w[i + 1]) same = false;
	if (same) {
		for (int i = 0; i < n; i++) {
			std::cout << ((x[i] + t * (w[i] ? 1 : -1)) % l + l) % l  << std::endl;
		}
		return 0;
	}
	bool inversed = false;
	if (!w[0]) {
		for (int i = 0; i < n; i++) w[i] = !w[i], x[i] = (l - x[i]) % l;
		inversed = true;
	}
	auto res = x0_pos(n, l, t, x, w);
	int64_t pos = res.second;
	bool dir = res.first;
	std::cerr << pos << ":" << dir << std::endl;
	pos += t;
	pos %= l;
	if (inversed) pos = (l - pos) % l, dir = !dir;
	std::cerr << pos << std::endl;
	std::set<std::pair<int64_t, bool> > st;
	for (int i = 0; i < n; i++) {
		if (inversed) st.insert({((t * (!w[i] ? 1 : -1) - x[i]) % l + l) % l, !w[i]});
		else st.insert({((x[i] + t * (w[i] ? 1 : -1)) % l + l) % l, w[i]});
	}
	assert(st.size() == n);
	for (auto i : st) std::cerr << "pos:" << i.first << " dir:" << i.second << std::endl;
	auto itr = st.lower_bound({pos, false});
	assert(itr != st.end() && itr->first == pos);
	if (std::next(itr) != st.end() && std::next(itr)->first == itr->first && itr->second != dir) {
		itr++;
		exit(0);
		assert(itr->second == dir);
	}
	for (auto i = itr; i != st.end(); i++) std::cout << i->first << " ";
	for (auto i = st.begin(); i != itr; i++) std::cout << i->first << " ";
	std::cout << std::endl;
	return 0;
}


Compiler output:
In file included from /usr/include/c++/14/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:106,
                 from a.cc:1:
a.cc: In function 'std::pair<bool, int> x0_pos(int64_t, int64_t, int64_t, int64_t*, int64_t*)':
a.cc:42:42: error: expected primary-expression before '-=' token
   42 |                 assert(first_col_comp != -=1);
      |                                          ^~