Submission #3696927

Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

#define NDEBUG
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

template <typename T>
inline T mod(T a, T m) {
    T res = a % m;
    if (res < 0) res += m;
    return res;
}


class Solver {
    int N, L, T;
    vi x, dir;

    vi cw, ccw;
    int CW, CCW;
public:
    Solver() {
        scanf("%d%d%d", &N, &L, &T);
        x.resize(N); dir.resize(N);
        rep(i,N) {
            int w;
            scanf("%d%d", &x[i], &w);
            dir[i] = (w == 1) ? 1 : -1;
        }

        init();
        rep(i,N) printf("%d\n", mod(solve1(x[i], dir[i], T), L));
    }
private:
    void init() {
        cw.reserve(N*2); ccw.reserve(N*2);
        rep(i,N){
            if (dir[i] == 1) {
                cw.pb(x[i]);
            } else {
                ccw.pb(x[i]);
            }
        }
        CW = cw.size(); CCW = ccw.size();

        cw.resize(CW*2);
        rep(i,CW) cw[CW+i] = cw[i] + L;
        ccw.resize(CCW*2);
        rep(i,CCW) ccw[CCW+i] = ccw[i] + L;
    }
    ll cw_d(int i, int m){
        int q = m / CW, r = m % CW;
        ll ans = (ll)L * q + (cw[CW+i] - cw[CW+i-r]);
        return ans;
    }
    ll ccw_d(int j, int m){
        int q = m / CCW, r = m % CCW;
        ll ans = (ll)L * q + (ccw[j+r] - ccw[j]);
        return ans;
    }
    int sub(int i, int j, int dir, int T2) {
        int lo=0, hi=1e9;
        while (lo+1 < hi) {
            int m = mid(lo, hi);
            ll d0 = cw_d(i, m) + ccw_d(j, m);
            if (d0 <= T2) {
                lo = m;
            } else {
                hi = m;
            }
        }
        ll dx0 = cw_d(i, lo), dx1 = cw_d(i, lo+1);
        ll dy0 = ccw_d(j, lo), dy1 = ccw_d(j, lo+1);

        ll d0 = dx0 + dy0, d2 = dx1 + dy1;
        ll dx, dy;
        if (dir == -1) {
            ll d1 = dx1 + dy0;

            if (IN(T2, d0, d1-1)) {
                dy = dy0;
                dx = dx0 + (T2 - d0);
            } else if (IN(T2, d1, d2-1)) {
                dy = dy0 + (T2 - d1);
                dx = dx1;
            }
        } else {
            ll d1 = dx0 + dy1;
            if (IN(T2, d0, d1-1)) {
                dy = dy0 + (T2 - d0);
                dx = dx0;
            } else if (IN(T2, d1, d2-1)) {
                dy = dy1;
                dx = dx0 + (T2 - d1);
            }
        }
        return dy - dx;
    }
    int solve1(int x, int dir, int T) {
        if (CW == 0) return x-T;
        else if (CCW == 0) return x+T;

        assert(CW > 0 && CCW > 0);

        if (dir == 1) {
            int me = lower_bound(ALL(cw), x) - cw.begin();
            int ix = mod((int)(lower_bound(ALL(ccw), x) - ccw.begin()), CCW);
            int dx = ccw[ix] - x;
            assert(IN(dx, -(L-1), L-1));
            if (dx < 0) dx += L;
            if (T <= dx/2) {
                return x+T;
            } else {
                ll s = dx + sub(me, ix, -dir, T*2 - dx);
                return x + s/2;
            }
        } else {
            int me = lower_bound(ALL(ccw), x) - ccw.begin();
            int ix = mod((int)(lower_bound(ALL(cw), x) - cw.begin()) - 1, CW);
            int dx = x - cw[ix];
            assert(IN(dx, -(L-1), L-1));
            if (dx < 0) dx += L;
            if (T <= dx/2) {
                return x-T;
            } else {
                ll s = -dx + sub(ix, me, -dir, T*2 - dx);
                return x + s/2;
            }

        }
        return 0;
    }
};

int main() {
    Solver *s = new Solver();
    delete s;
    return 0;
}

Submission Info

Submission Time
Task C - Ants on a Circle
User naoya_t
Language C++14 (GCC 5.4.1)
Score 700
Code Size 4697 Byte
Status
Exec Time 71 ms
Memory 2816 KB

Compile Error

./Main.cpp: In constructor ‘Solver::Solver()’:
./Main.cpp:54:36: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &N, &L, &T);
                                    ^
./Main.cpp:58:37: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d%d", &x[i], &w);
                                     ^

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01.txt, sample_02.txt
All 700 / 700 sample_01.txt, sample_02.txt, sample_01.txt, sample_02.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt, subtask_1_14.txt, subtask_1_15.txt, subtask_1_16.txt
Case Name Status Exec Time Memory
sample_01.txt 1 ms 256 KB
sample_02.txt 1 ms 256 KB
subtask_1_01.txt 44 ms 1792 KB
subtask_1_02.txt 34 ms 1408 KB
subtask_1_03.txt 71 ms 2816 KB
subtask_1_04.txt 71 ms 2816 KB
subtask_1_05.txt 12 ms 640 KB
subtask_1_06.txt 17 ms 768 KB
subtask_1_07.txt 66 ms 2432 KB
subtask_1_08.txt 67 ms 2432 KB
subtask_1_09.txt 44 ms 1664 KB
subtask_1_10.txt 39 ms 1408 KB
subtask_1_11.txt 5 ms 556 KB
subtask_1_12.txt 25 ms 2432 KB
subtask_1_13.txt 26 ms 1920 KB
subtask_1_14.txt 23 ms 1792 KB
subtask_1_15.txt 1 ms 256 KB
subtask_1_16.txt 1 ms 256 KB