結果
問題 | No.142 単なる配列の操作に関する実装問題 |
ユーザー | eQe |
提出日時 | 2024-10-11 04:26:30 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,267 ms / 5,000 ms |
コード長 | 5,504 bytes |
コンパイル時間 | 5,760 ms |
コンパイル使用メモリ | 313,960 KB |
実行使用メモリ | 8,312 KB |
最終ジャッジ日時 | 2024-10-11 04:26:41 |
合計ジャッジ時間 | 10,967 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 300 ms
7,908 KB |
testcase_01 | AC | 1,029 ms
7,332 KB |
testcase_02 | AC | 1,267 ms
8,312 KB |
testcase_03 | AC | 282 ms
7,960 KB |
testcase_04 | AC | 1,015 ms
7,992 KB |
ソースコード
#include<bits/stdc++.h> #include<atcoder/all> namespace my{ void main(); void solve(); } int main(){my::main();} namespace my{ #define eb emplace_back #define LL(...) ll __VA_ARGS__;lin(__VA_ARGS__) #define FO(n) for(ll ij=n;ij--;) #define FOR(i,...) for(auto[i,i##stop,i##step]=range(0,__VA_ARGS__);i<i##stop;i+=i##step) #define fo(i,...) FO##__VA_OPT__(R)(i __VA_OPT__(,__VA_ARGS__)) #define fe(a,i,...) for(auto&&__VA_OPT__([)i __VA_OPT__(,__VA_ARGS__]):a) using namespace std; using ll=int64_t; auto range(bool s,ll a,ll b=1e18,ll c=1){if(b==1e18)b=a,(s?b:a)=0;return array{a-s,b,c};} constexpr char nl=10; constexpr char sp=32; constexpr ll log2_floor(auto x){x|=1;ll r=0;while(x>1)x>>=1,++r;return r;} auto ceil(auto x,auto y){if(y<0)x=-x,y=-y;return x<=0?x/y:(x-1)/y+1;} template<class V>concept vectorial=is_base_of_v<vector<typename V::value_type>,V>; template<class V>istream&operator>>(istream&i,vector<V>&v){fe(v,e)i>>e;return i;} template<class V>ostream&operator<<(ostream&o,const vector<V>&v){fe(v,e)o<<e<<string(&e!=&v.back(),vectorial<V>?nl:sp);return o;} template<class V>struct vec:vector<V>{ using vector<V>::vector; vec(const vector<V>&v){this->reserve(v.size());fe(v,e)this->eb(e);} vec&operator+=(const vec&u){vec&v=*this;fo(i,v.size())v[i]+=u[i];return v;} vec&operator-=(const vec&u){vec&v=*this;fo(i,v.size())v[i]-=u[i];return v;} vec&operator^=(const vec&u){this->insert(this->end(),u.begin(),u.end());return*this;} vec operator+(const vec&u)const{return vec{*this}+=u;} vec operator-(const vec&u)const{return vec{*this}-=u;} vec operator^(const vec&u)const{return vec{*this}^=u;} vec&operator++(){fe(*this,e)++e;return*this;} vec&operator--(){fe(*this,e)--e;return*this;} vec operator-()const{vec v=*this;fe(v,e)e=-e;return v;} vec slice(ll l,ll r)const{return vec(this->begin()+l,this->begin()+r);} }; void io(){cin.tie(nullptr)->sync_with_stdio(0);cout<<fixed<<setprecision(15);} void lin(auto&...a){(cin>>...>>a);} template<char c=sp>void pp(const auto&...a){ll n=sizeof...(a);((cout<<a<<string(--n>0,c)),...);cout<<nl;} template<unsigned_integral T=uint64_t>struct dynamic_bitset{ static constexpr size_t block_size=sizeof(T)*CHAR_BIT; static constexpr size_t block_index(size_t i){return i>>log2_floor(block_size);} static constexpr size_t bit_index(size_t i){return i&(block_size-1);} vec<T>bits; size_t n; size_t size()const{return n;} dynamic_bitset(size_t n):n(n),bits(ceil(n,block_size)){} dynamic_bitset(const string&s):n(s.size()),bits(ceil(s.size(),block_size)){fo(i,n)bits[block_index(i)]|=T(s[i]-'0')<<bit_index(i);} struct proxy{ vec<T>&bits_proxy; size_t I; proxy(vec<T>&bits_proxy,size_t I):bits_proxy(bits_proxy),I(I){} auto&operator=(bool f){ bits_proxy[block_index(I)]&=~(T(1)<<bit_index(I)); bits_proxy[block_index(I)]|=T(f)<<bit_index(I); return*this; } template<integral X>auto&operator=(X x){return this->operator=(static_cast<bool>(x&1));} auto&operator=(const proxy&p){return this->operator=(static_cast<bool>(p));} operator bool()const{return bits_proxy[block_index(I)]>>bit_index(I)&1;} }; decltype(auto)operator[](size_t i){return proxy{bits,i};} decltype(auto)operator[](size_t i)const{return bits[block_index(i)]>>bit_index(i)&1;} auto&operator&=(const dynamic_bitset&b){fo(i,bits.size())bits[i]&=b.bits[i];return*this;} auto&operator|=(const dynamic_bitset&b){fo(i,bits.size())bits[i]|=b.bits[i];return*this;} auto&operator^=(const dynamic_bitset&b){fo(i,bits.size())bits[i]^=b.bits[i];return*this;} auto operator&(const dynamic_bitset&b)const{return dynamic_bitset{*this}&=b;} auto operator|(const dynamic_bitset&b)const{return dynamic_bitset{*this}|=b;} auto operator^(const dynamic_bitset&b)const{return dynamic_bitset{*this}^=b;} auto slice(ll l,ll r)const{ dynamic_bitset res(r-l); fo(bit_index(r-l)){ res[r-l-1]=(*this)[r-1]; --r; } ll upper_shift=bit_index(l); ll lower_shift=block_size-upper_shift; ll n=block_index(r-l); ll offset=block_index(l); fo(i,n){ if(upper_shift==0)res.bits[i]=bits[offset+i]; else res.bits[i]=(bits[offset+i]>>upper_shift)|(bits[offset+i+1]<<lower_shift); } return res; } auto&range_bit_operation(const auto&op,ll l,const dynamic_bitset&p){ ll r=l+p.size(); fo(bit_index(r-l)){ (*this)[r-1]=op((*this)[r-1],p[r-l-1]); --r; } ll lower_shift=bit_index(l); ll upper_shift=block_size-lower_shift; ll n=block_index(r-l); ll offset=block_index(l); fo(i,n){ if(lower_shift==0)bits[offset+i]=op(bits[offset+i],p.bits[i]); else{ bits[offset+i]=op(bits[offset+i],p.bits[i]<<lower_shift); bits[offset+i+1]=op(bits[offset+i+1],p.bits[i]>>upper_shift); } } return*this; } auto&range_xor(ll l,const dynamic_bitset&p){ return range_bit_operation(bit_xor<>{},l,p); } string to_string()const{string s{};fo(i,size())s+=(*this)[i]+'0';return s;} friend istream&operator>>(istream&i,dynamic_bitset&db){string s;i>>s;db=s;return i;} friend ostream&operator<<(ostream&o,const dynamic_bitset&db){return o<<db.to_string();} }; void main(){io();ll T=1;fo(T)solve();} void solve(){ LL(N,S,X,Y,Z); dynamic_bitset a(N); a[0]=S; ll cu=S; fo(i,1,N){ cu=(cu*X+Y)%Z; a[i]=cu; } LL(Q); fo(Q){ LL(s,t,u,v);--s,--u; a.range_xor(u,a.slice(s,t)); } string res{}; fo(i,N)res+=(a[i]?'O':'E'); pp(res); }}