結果

問題 No.142 単なる配列の操作に関する実装問題
ユーザー codershifthcodershifth
提出日時 2015-12-15 00:19:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2,974 ms / 5,000 ms
コード長 3,121 bytes
コンパイル時間 3,361 ms
コンパイル使用メモリ 150,388 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-13 16:52:20
合計ジャッジ時間 13,588 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 502 ms
4,352 KB
testcase_01 AC 2,331 ms
4,348 KB
testcase_02 AC 2,974 ms
4,348 KB
testcase_03 AC 491 ms
4,348 KB
testcase_04 AC 2,318 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#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 ull;
    const int Block = 64;

    pair<int,int> i2b(int idx)
    {
            return make_pair(idx/Block, idx%Block);
    }
    ull shift(const array<ull,3> &arry, int move)
    {
            if ( move == 0 )
                return arry[1];
            if ( move > 0 )
            {
                return (arry[1]<<move)|(arry[0]>>(Block-move));
            }
            else
            {
                move *= -1;
                return (arry[1]>>move)|(arry[2]<<(Block-move));
            }
    }
    void solve(void)
    {
            int N,S,X,Y,Z;
            int Q;
            cin>>N>>S>>X>>Y>>Z;
            cin>>Q;

            vector<ull> A(N/Block+1, 0);
            vector<ull> B(N/Block+1, 0);
            ull a;

            a = S;
            REP(i,N)
            {
                int p,b;
                tie(b,p) = i2b(i);
                if ( a%2 == 1 )
                    A[b] |= (1ULL<<p);
                a = (X*a+Y) % Z;
            }
            while (Q--)
            {
                int S,T,U,V;
                int sb,tb,ub,vb;
                int sp,tp,up,vp;

                cin>>S>>T>>U>>V;
                --S,--T,--U,--V;
                tie(sb,sp) = i2b(S);
                tie(tb,tp) = i2b(T);
                tie(ub,up) = i2b(U);
                tie(vb,vp) = i2b(V);

                // B=A[S,T]
                // A[k] = A[k] + B[k-U] (U<=k<=V)
                int move = up-sp;
                for (int k = 0, j = sb; k <= vb-ub; ++k, ++j)
                {
                    array<ull,3> C{0,0,0};

                    // 一旦そのまま copy
                    // 変換対象 block A[j] が C[1] にくるようにする。
                    for (int i = -1; i <= 1; ++i)
                    {   // 範囲チェック
                        if ( sb <= i+j && i+j <= tb )
                            C[i+1] = A[i+j];
                        // 頭の不要な部分は削る
                        if ( i+j == sb )
                            C[i+1] &= ~((1ULL<<sp)-1);
                        // 末尾の不要な部分は削る
                        if ( i+j == tb )
                            C[i+1] &= ((1ULL<<tp)|((1ULL<<tp)-1));
                    }
                    // bit shift
                    B[k] = shift(C, move);
                }
                for (int k = ub; k <= vb; ++k)
                    A[k] ^= B[k-ub];
            }
            REP(i,N)
            {
                int p,b;
                tie(b,p) = i2b(i);
                if ( A[b] & (1ULL<<p) )
                    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