結果

問題 No.142 単なる配列の操作に関する実装問題
ユーザー codershifthcodershifth
提出日時 2015-11-18 01:49:12
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 3,268 bytes
コンパイル時間 1,499 ms
コンパイル使用メモリ 150,328 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-11 17:56:28
合計ジャッジ時間 8,469 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int (i)=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define RANGE(vec) (vec).begin(),(vec).end()


using namespace std;
class ArrayImplementationSimply {
public:
    typedef unsigned long long int uint64;
    std::pair<int,int> i2b(int index) {
            return make_pair(index/64, index%64);
    }
    //
    //  l      r
    // 01110 01100
    // [11001] 11000
    uint64 shiftL(uint64 l, uint64 r, int offset) {
            return ((l<<offset)|(r>>(63-offset)));
    }
    //
    //  l      r
    // 01110 01100
    // 00011 [10011]
    uint64 shiftR(uint64 l, uint64 r, int offset) {
            return ((l<<(63-offset))|(r>>offset));
    }
    uint64 set(uint64 bit, int pos) {
            return (bit | (1ULL<<(63-pos)));
    }
    //    pos
    // 11110000
    uint64 all(int pos) {
            if (pos <= 0 || 63 < pos)
                return 0ULL;
            pos = 63-pos;
            return ~((1ULL<<pos)|((1ULL<<pos)-1));
    }
    uint64 clearL(uint64 bit, int pos) {
            return bit & ~all(pos);
    }
    // clear [pos,)
    uint64 clearR(uint64 bit, int pos) {
            return bit & all(pos-1);
    }
    void solve(void) {
            int N,S0,X,Y,Z;
            cin>>N>>S0>>X>>Y>>Z;

            vector<uint64> A(N/64+2,0);
            int Q;

            cin>>Q;
            uint64 a = S0;
            // 乱数生成
            REP(i,N)
            {
                int j,k;
                tie(j,k) = i2b(i);
                if ( a % 2 == 1 )
                    A[j] = set(A[j], k);
                a = (a * X + Y) % Z;
            }
            // O(Q*(T-S)/64) <= 2*10^5*10^5/64 = 312500000
            REP(_,Q)
            {
                int S,T,U,V;
                cin>>S>>T>>U>>V;
                --S, --T, --U, --V;

                int s,t,si,ti;
                tie(s,si) = i2b(S);
                tie(t,ti) = i2b(T);

                vector<uint64> B(t-s+3,0);
                REP(i,t-s+1)
                {
                    // 前方に詰めて copy
                    B[i] = shiftL(A[i],A[i+1],si);

                    if (i == t-s) // 不要な末尾部を削除
                        B[i] = clearR(B[i], ti-si+2);
                }
                int u,v,ui,vi;
                tie(u,ui) = i2b(U);
                tie(v,vi) = i2b(V);

                // add
                REP(i,v-u+1)
                {
                    uint64 add = 0;
                    // 後方に詰めてビットを取得
                    if ( i > 0)
                        add = shiftR(B[i-1],B[i],ui);
                    else
                        add = shiftR(0ULL,B[i],ui);

                    A[u+i] ^= add;
                }
            }
            REP(i,N)
            {
                int j,k;
                tie(j,k) = i2b(i);
                if ( A[j] & (1ULL<<(63-k)) )
                    cout<<"O";
                else
                    cout<<"E";
            }
            cout<<endl;

    }
};

#if 1
int main(int argc, char *argv[])
{
        ios::sync_with_stdio(false);
        auto obj = new ArrayImplementationSimply();
        obj->solve();
        delete obj;
        return 0;
}
#endif
0