結果

問題 No.142 単なる配列の操作に関する実装問題
ユーザー maine_honzukimaine_honzuki
提出日時 2020-05-21 11:02:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,394 bytes
コンパイル時間 1,245 ms
コンパイル使用メモリ 75,780 KB
実行使用メモリ 29,592 KB
最終ジャッジ日時 2023-07-25 05:36:26
合計ジャッジ時間 14,187 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ull = unsigned long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, S, X, Y, Z;
    cin >> N >> S >> X >> Y >> Z;

    vector<ull> A(N);
    A[0] = S;
    for (int i = 1; i < N; i++) {
        (A[i] = (X * A[i - 1] + Y)) %= Z;
    }

    ull bit[40010] = {}, mask[40010] = {};
    for (int i = 0; i < N; i++) {
        bit[i / 64] |= (A[i] % 2) << (i % 64);
    }

    int Q;
    cin >> Q;


    while (Q--) {
        int S, T, U, V;
        cin >> S >> T >> U >> V;
        S--;
        T--;
        U--;
        V--;

        //mask.reset();
        //mask >>= (len - (T - S + 1));
        //mask <<= S - 1;
        string ans;
        for (int i = 0; i < N; i++) {
            ans.push_back(char(bit[i / 64] & (1ll << (i % 64)) ? 'O' : 'E'));
        }

        int z = U - S;

        if (z >= 0) {
            for (int i = U / 64; i <= V / 64; i++) {
                ull tmp = bit[i - z / 64] << (z % 64);
                if (i - z / 64 - 1 >= 0)
                    tmp |= bit[i - z / 64 - 1] >> (64 - z % 64);

                if (i == U / 64) {
                    for (int x = 0; x < U % 64; x++) {
                        tmp &= ~(1ull << x);
                    }
                }
                if (i == V / 64) {
                    for (int x = 63; x > V % 64; x--) {
                        tmp &= ~(1ull << x);
                    }
                }
                bit[i] ^= tmp;
            }
        } else {
            z = abs(z);
            for (int i = U / 64; i <= V / 64; i++) {
                ull tmp = bit[i - z / 64] >> (z % 64);
                tmp |= bit[i - z / 64 + 1] << (64 - z % 64);

                if (i == U / 64) {
                    for (int x = 0; x < U % 64; x++) {
                        tmp &= ~(1ull << x);
                    }
                }
                if (i == V / 64) {
                    for (int x = 63; x > V % 64; x--) {
                        tmp &= ~(1ull << x);
                    }
                }
                bit[i] ^= tmp;
            }
        }
    }

    string ans;
    for (int i = 0; i < N; i++) {
        ans.push_back(char(bit[i / 64] & (1ll << (i % 64)) ? 'O' : 'E'));
    }

    reverse(ans.begin(), ans.end());

    cout << ans << endl;
}
0