显示原始代码
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
struct node {
ll x, tb;
} h, rs, ls, tp;
ll l, ans[100005], cnt = 0, uv, tot = 0, att, f, n, i, a[100005], b[100005], res, dir[100005], t;
node operator+(node a, node b) {
node c;
c.x = a.x + b.x;
c.tb = a.tb + b.tb;
if (c.tb == 2)
c.x++, c.tb = 0;
return c;
}
node operator-(node a, node b) {
node c;
c.x = a.x - b.x;
c.tb = a.tb - b.tb;
if (c.tb == -1)
c.x--, c.tb = 1;
return c;
}
node operator/(node a, node b) {
ll u, v;
node c;
u = 2LL * a.x + a.tb;
v = 2LL * b.x + b.tb;
c.x = u / v;
c.tb = 0;
return c;
}
node div(node a) {
if (a.x % 2)
return (node){ a.x / 2LL, 1LL };
else
return (node){ a.x / 2LL, 0LL };
}
ll ad(ll p) {
if (p == n)
return 1;
return p + 1;
}
int main() {
scanf("%lld%lld%lld", &n, &l, &t);
if (n == 1) {
ll x, y;
scanf("%lld%lld", &x, &y);
if (y == 1)
printf("%lld\n", (x + t) % l);
else
printf("%lld\n", (x - t % l + l) % l);
return 0;
}
for (i = 1; i <= n; i++) scanf("%lld%lld", &a[i], &dir[i]);
for (i = 2; i <= n; i++) {
if (dir[i] == dir[1])
continue;
if (dir[1] == 0) {
if (a[i] > a[1])
res = a[i] - a[1];
else
res = l - a[1] + a[i];
} else {
if (a[i] > a[1])
res = a[1] + l - a[i];
else
res = a[1] - a[i];
}
rs.x = res;
rs.tb = 0;
tot = 0;
tp.x = t;
tp.tb = 0;
ls.x = l;
ls.tb = 0;
rs = div(rs);
if ((tp / rs).x == 0)
continue;
tot = 1;
tp = tp - rs;
ls = div(ls);
tot += (tp / ls).x;
cnt += tot;
}
if (dir[1] == 0)
att = 1;
else
att = 0, cnt = -cnt;
for (i = 1; i <= n; i++) {
if (dir[i] == 0)
b[i] = (a[i] + t) % l;
else
b[i] = (a[i] - t % l + l) % l;
}
uv = b[1];
sort(b + 1, b + n + 1);
for (i = 1; i <= n; i++) {
if (b[i] == uv) {
if (b[ad(i)] != uv)
break;
else {
if (att == 0)
break;
else {
i = ad(i);
break;
}
}
}
}
f = (1 + cnt % n + n) % n;
for (; ans[f] == 0; ans[f] = b[i], f = ad(f), i = ad(i))
;
for (i = 1; i <= n; i++) printf("%lld\n", ans[i]);
return 0;
}