結果
| 問題 | No.142 単なる配列の操作に関する実装問題 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-07-23 09:00:04 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2,879 ms / 5,000 ms |
| コード長 | 2,187 bytes |
| コンパイル時間 | 2,025 ms |
| コンパイル使用メモリ | 205,540 KB |
| 実行使用メモリ | 7,712 KB |
| 最終ジャッジ日時 | 2025-07-23 09:00:18 |
| 合計ジャッジ時間 | 12,116 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 5 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N; cin >> N;
int S,X,Y,Z; cin >> S >> X >> Y >> Z;
vector<bool> B(N);
for(int i=0; i<N; i++){
if(S&1) B.at(i) = true;
S = (1LL*S*X+Y)%Z;
}
int Q; cin >> Q;
vector<tuple<int,int,int,int>> lrLR(Q);
for(auto &[l,r,L,R] : lrLR) cin >> l >> r >> L >> R;
const int mod = 60;
using ull = unsigned long long;
int n = (N+mod-1)/mod;
vector<ull> A(n),A2(n);
int pos = 0,bit = 0;
for(int i=0; i<N; i++){
if(B.at(i)) A.at(pos) += 1ULL<<bit;
bit++;
if(bit == mod) pos++,bit = 0;
}
ull maxv = numeric_limits<ull>::max();
auto move = [&](int l,int r,int L,int R) -> void {
int posl = l/mod,lmod = l%mod;
int posL = L/mod,Lmod = L%mod;
int len = r-l;
while(len >= mod){
if(lmod <= Lmod){
int movebit = mod-Lmod; len -= movebit;
ull bring = A.at(posl)&((1ULL<<(lmod+movebit))-(1ULL<<lmod));
A2.at(posL) ^= (bring>>lmod)<<Lmod;
Lmod = mod,lmod += movebit;
}
else{
int movebit = mod-lmod; len -= movebit;
ull bring = A.at(posl)&(maxv-(1ULL<<lmod)+1);
A2.at(posL) ^= (bring>>lmod)<<Lmod;
lmod = mod,Lmod += movebit;
}
if(lmod == mod) lmod = 0,posl++;
if(Lmod == mod) Lmod = 0,posL++;
}
while(len--){
if(A.at(posl)&(1ULL<<lmod)) A2.at(posL) ^= 1ULL<<Lmod;
lmod++,Lmod++;
if(lmod == mod) lmod = 0,posl++;
if(Lmod == mod) Lmod = 0,posL++;
}
int start = L/mod;
posL = min(posL,n-1);
for(int i=start; i<=posL; i++){
A.at(i) ^= A2.at(i);
A2.at(i) = 0;
}
};
for(auto [l,r,L,R] : lrLR) move(l-1,r,L-1,R);
pos = 0,bit = 0;
for(int i=0; i<N; i++){
if(A.at(pos)&(1ULL<<bit)) cout << "O";
else cout << "E";
bit++;
if(bit == mod) bit = 0,pos++;
}
cout << endl;
}