結果

問題 No.142 単なる配列の操作に関する実装問題
ユーザー yaoshimaxyaoshimax
提出日時 2015-04-30 23:50:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,454 ms / 5,000 ms
コード長 3,152 bytes
コンパイル時間 1,193 ms
コンパイル使用メモリ 88,388 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-19 04:47:03
合計ジャッジ時間 7,678 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 465 ms
4,380 KB
testcase_01 AC 1,194 ms
4,380 KB
testcase_02 AC 1,454 ms
4,380 KB
testcase_03 AC 431 ms
4,380 KB
testcase_04 AC 1,166 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <queue>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <bitset>
#define BITLEN 60 

using namespace std;
long long arrays[100000];
int main(){
   int N,S,X,Y,Z;
   cin>>N>>S>>X>>Y>>Z;
   long long a=S;
   arrays[1]|=a%2;
   for(int i=1;i<N;i++){
      a=(X*a+Y)%Z;
      arrays[i/BITLEN+1]|=((a%2)<<(i%BITLEN));
   }
   /*
   for( int i = 0 ; i <N ; i++ ){
      cout << (((arrays[i/BITLEN+1]&(1LL<<(i%BITLEN)))==0)?"E":"O");
   }
   cout << endl;
   */
   /*
   for( int i = 0 ; i < (N+BITLEN-1)/BITLEN; i++ ){
         cout << static_cast<std::bitset<BITLEN> >(arrays[i])<<", ";
   }
   */
   int Q;
   cin>>Q;
   for(int i=0;i<Q;i++){
      int s,t,u,v;
      cin>>s>>t>>u>>v;
      s--;t--;u--;v--;
      int sr=s%BITLEN;
      int ur=u%BITLEN;
      int dif=ur-sr;
      //cout <<"dif"<<dif<<endl;
      int len=t/BITLEN-s/BITLEN+1;
      long long tmp[len+2];
      tmp[0]=0;
      tmp[len+1]=0;
      for( int j = 1+s/BITLEN; j <= 1+t/BITLEN; j++ ){
         int ind=j-s/BITLEN;
         tmp[ind]=arrays[j];
         //cout << ind<<":"<<static_cast<std::bitset<BITLEN> >(tmp[ind])<<", ";
         if( j== 1+s/BITLEN ){
            tmp[ind]&=(1LL<<BITLEN)-(1LL<<(s%BITLEN));
         }
         if( j== 1+t/BITLEN ){
            tmp[ind]&=(1LL<<(t%BITLEN+1))-1;
         }
         //cout << ind<<":"<<static_cast<std::bitset<BITLEN> >(tmp[ind])<<", ";
      }
      //cout << endl;
      if( dif >=0 ){
         long long carry = 0;
         for( int i = 1; i <= len+1; i++ ){
            //cout << static_cast<std::bitset<BITLEN> >(tmp[i])<<endl;
            long long ncarry=tmp[i]>>(BITLEN-dif); 
            tmp[i]=((tmp[i]<<dif)+carry)&((1LL<<BITLEN)-1);
            carry=ncarry;
         }
         for( int i = 1; i <= len+1; i++ ){
            //cout << static_cast<std::bitset<BITLEN> >(arrays[t/BITLEN+i])<<"^";
            //cout << static_cast<std::bitset<BITLEN> >(tmp[i])<<endl;
            arrays[u/BITLEN+i]^=tmp[i];
         }
      }
      if( dif < 0 ){
         long long carry = 0;
         for( int i = len ; i >= 0 ; i--){
           //cout << static_cast<std::bitset<BITLEN> >(tmp[i])<<endl;
           long long ncarry = (tmp[i]&((1LL<<-dif)-1))<<(BITLEN+dif);
           tmp[i]=carry+(tmp[i]>>-dif);
           carry=ncarry;
         }
         for( int i = 0; i <= len ; i++ ){
            //cout << static_cast<std::bitset<BITLEN> >(arrays[t/BITLEN+i])<<"^";
            //cout << static_cast<std::bitset<BITLEN> >(tmp[i])<<endl;
            arrays[u/BITLEN+i]^=tmp[i];
         }
      }
    /*  
      for( int i = 0 ; i <N ; i++ ){
         cout << (((arrays[i/BITLEN+1]&(1LL<<(i%BITLEN)))==0)?"E":"O");
      }
      cout << endl;
   */
   }
      for( int i = 0 ; i <N ; i++ ){
         cout << (((arrays[i/BITLEN+1]&(1LL<<(i%BITLEN)))==0)?"E":"O");
      }
      cout<<endl;

   return 0;
}
0