Language: C++

#include <iostream>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

ll l, t;

ll round(ll a, ll b){
    return t * a / (l * (a + b));
}

int main()
{
    ll n;
    cin >> n >> l >> t;
    ll x[100002];
    int w[100002];
    ll ans[100002];
    P left[100002], right[100002];
    ll le = 0, ri = 0;
    for(ll i = 0; i < n; i++){
        cin >> x[i] >> w[i];
        if(w[i] == 1){
            ans[i] = (x[i] + t) % l;
            right[ri] = P(x[i], i);
            ri++;
        }
        else{
            ans[i] = (x[i] + l * t - t) % l;
            left[le] = P(x[i], i);
            le++;
        }
    }
    ll ant;
    ll rl;
    t *= 2;
    if(w[0] == 1){
        if(le == 0){
            ant = 0;
            rl = 1;
        }
        else{
            ll nowt = left[0].first - right[0].first + round(le, ri) * l + round(le, ri) * ri / le;
            ll nowl = 0;
            for(ll i = 0; i < round(le, ri) * ri % le; i++){
                nowt += (left[(nowl + 1) % le].first + l - left[nowl].first - 1) % l + 1;
                nowl = (nowl + 1) % le;
            }
            ll nowr = 0;
            bool ifr = true;
            while(t > nowt){
                if(ifr){
                    nowt += (right[nowr].first + l - right[(nowr + ri - 1) % ri].first - 1) % l + 1;
                    nowr = (nowr + ri - 1) % ri;
                    ifr = false;
                }
                else{
                    nowt += (left[(nowl + 1) % le].first + l - left[nowl].first - 1) % l + 1;
                    nowl = (nowl + 1) % le;
                    ifr = true;
                }
            }
            if(!ifr){
                ant = left[nowl % le].second;
                rl = 0;
            }
            else{
                ant = right[nowr % ri].second;
                rl = 1;
            }
        }
    }
    if(w[0] == 2){
        if(ri == 0){
            ant = 0;
            rl = 0;
        }
        else{
            ll nowt = left[0].first + l - right[ri - 1].first + round(ri, le) * l + round(ri, le) * le / ri;
            ll nowr = (ri - 1) % ri;
            for(ll i = 0; i < round(ri, le) * le % ri; i++){
                    nowt += (right[nowr].first + l - right[(nowr + ri - 1) % ri].first - 1) % l + 1;
                    nowr = (nowr + ri - 1) % ri;
            }
            ll nowl = 0;
            bool ifr = false;
            while(t > nowt){
                if(ifr){
                    nowt += (right[nowr].first + l - right[(nowr + ri - 1) % ri].first - 1) % l + 1;
                    nowr = (nowr + ri - 1) % ri;
                    ifr = false;
                }
                else{
                    nowt += (left[(nowl + 1) % le].first + l - left[nowl].first - 1) % l + 1;
                    nowl = (nowl + 1) % le;
                    ifr = true;
                }
            }
            if(!ifr){
                ant = left[nowl % le].second;
                rl = 0;
            }
            else{
                ant = right[nowr % ri].second;
                rl = 1;
            }
        }
    }
    ll pant = ans[ant];
    sort(ans, ans + n);
    ll want = lower_bound(ans, ans + n, pant) - ans;
    if(ans[want] == ans[(want + 1) % n]){
        if(rl == 0) want++;
    }
    for(ll i = 0; i < n; i++){
        cout << ans[(want + i) % n] << endl;
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:111:5: error: 'sort' was not declared in this scope; did you mean 'short'?
  111 |     sort(ans, ans + n);
      |     ^~~~
      |     short