显示原始代码
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
#define spause() system("pause")
using namespace std;
typedef long long llong;
typedef unsigned long long ullong;
typedef pair<int, int> prdd;
typedef map<int, int> mpdd;
const int dinf = 0x7fffffff;
const llong llinf = 0x7fffffffffffffff;
int n, l, t;
int fa, fw, rfw;
llong dnm;
vector<int> ant[2], anss;
inline llong nmod(llong x, llong p) { return ((x % p) + p) % p; }
int main() {
scanf("%d%d%d", &n, &l, &t);
for (int i = 0; i < n; i++) {
int a, w;
scanf("%d%d", &a, &w);
ant[w].push_back(a);
if (i == 0)
fa = a, fw = w, rfw = w ^ 1;
}
for (int i = 0; i < ant[rfw].size(); i++) {
int iant = ant[rfw][i], tp = 2 * t, fmt = nmod((iant - fa) * (1 - fw * 2), l);
if (fmt <= tp)
dnm += 1, tp -= fmt;
dnm += tp / l;
}
for (int w = 0; w < 2; w++)
for (int i = 0; i < ant[w].size(); i++) anss.push_back(nmod(t * (1 - w * 2) + ant[w][i], l));
sort(anss.begin(), anss.end());
int ftp = nmod(fa + t * (1 - fw * 2), l), i = lower_bound(anss.begin(), anss.end(), ftp) - anss.begin();
if (anss[nmod(i - fw * 2 + 1, n)] == anss[i])
i = nmod(i - fw * 2 + 1, n);
for (llong j = 0; j < n; j++) printf("%lld\n", anss[nmod(j + i - dnm * (1 - fw * 2), n)]);
spause();
return 0;
}