Submission #3150345


Source Code Expand

#include <bits/stdc++.h>
#include <tmmintrin.h>
using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second

template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

constexpr int BLOCK = 4;

__attribute__((aligned(16)))
int as[100010];
__attribute__((aligned(16)))
int lacc[100010];
__attribute__((aligned(16)))
int racc[100010];
__attribute__((aligned(16)))
int lacc_b[100010/BLOCK];
__attribute__((aligned(16)))
int tmp[4];

inline int iceil(int a, int b){
  return (a + b - 1) / b;
}

__attribute__((always_inline))
inline __m128i my_mm_max_epi32(__m128i a, __m128i b){
  __asm("pmaxsd %1, %0" : "+x" (a) : "xm" (b));
  return a;
}

#define USE_SSE

int main(){
  int N, Q;
  scanf("%d%d", &N, &Q);
  REP(i,N) scanf("%d", &as[i]);
  for(int i=0;i+BLOCK<=N;i+=BLOCK){
	lacc[i] = as[i];
	FOR(j,1,BLOCK)
	  lacc[i+j] = lacc[i+j-1] & as[i+j];

	lacc_b[i/BLOCK] = lacc[i+BLOCK-1];
  }

  racc[0] = as[0];
  FOR(i,1,N)
	racc[i] = racc[i-1] ^ as[i];

  int ans;
  int l, r;
  scanf("%d%d", &l, &r);

  --l;
  REP(q,Q){
	ans = 1<<31;
	int a = ~0;
	const int bb = l/BLOCK;
	const int be = (r-1)/BLOCK;
	const int  R = racc[r-1];
		
	if(bb == be){
	  for(int i=l;i<r-1;++i){
		a &= as[i];
		maxi(ans, a - (R ^ racc[i]));
	  }
	}
	else{
	  FOR(i,l,(bb+1)*BLOCK){
		a &= as[i];
		maxi(ans, a - (R ^ racc[i]));
	  }
	  
#ifdef USE_SSE
	  auto X = _mm_set1_epi32(R);
	  auto maxs = _mm_set1_epi32(ans);

	  int ix = (bb+1)*BLOCK;
	  for(;ix+BLOCK<r;ix+=BLOCK){
		//for(int b=bb+1;b<be;++b){
		//const int ix = b * BLOCK;
		auto a_dup = _mm_set1_epi32(a);
		auto aa = _mm_load_si128((__m128i const*)&lacc[ix]);
		auto ands = _mm_and_si128(a_dup, aa);
		auto xx = _mm_load_si128((__m128i const*)&racc[ix]);
		auto xss = _mm_xor_si128(X, xx);
		auto res = _mm_sub_epi32(ands, xss);
		maxs = my_mm_max_epi32(maxs, res);

		a &= lacc_b[ix/4];
	  }

	  _mm_store_si128((__m128i*)tmp, maxs);
	  ans = max(max(tmp[0], tmp[1]), max(tmp[2], tmp[3]));

	  for(;ix<r-1;++ix){
		a &= as[ix];
		maxi(ans, a - (R ^ racc[ix]));
	  }
#else
	  for(int b=bb+1;b<be;++b){
		for(int d=0;d<BLOCK;++d){
		  const int ix = b * BLOCK + d;
		  int a_ = a & lacc[ix];
		  int x_ = R ^ racc[ix];
		  maxi(ans, a_ - x_);
		}
		a &= lacc_b[b];
	  }
#endif
	  /*
	  for(int i=be*BLOCK;i<r-1;++i){
		a &= as[i];
		maxi(ans, a - (R ^ racc[i]));
	  }
	  */
	}

	printf("%d\n", ans);
	ans = abs(ans);

	if(q < Q-1){
	  scanf("%d%d", &l, &r);
	  l = ((LL)l + ans) % N + 1;
	  r = ((LL)r + ans) % N + 1;
	  --l;
	}
  }

  return 0;
}

Submission Info

Submission Time
Task J - XORAND
User okaduki
Language C++14 (GCC 5.4.1)
Score 0
Code Size 3060 Byte
Status TLE
Exec Time 4203 ms
Memory 2560 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:61:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &N, &Q);
                        ^
./Main.cpp:62:31: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   REP(i,N) scanf("%d", &as[i]);
                               ^
./Main.cpp:77:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &l, &r);
                        ^
./Main.cpp:148:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d%d", &l, &r);
                         ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 100
Status
AC × 2
AC × 15
TLE × 4
Set Name Test Cases
Sample subtask0_sample_01.txt, subtask0_sample_02.txt
All subtask0_sample_01.txt, subtask0_sample_02.txt, subtask1_pow2_01_mini.txt, subtask1_pow2_02_mini.txt, subtask1_pow2_03_OnlyOneLargeSeg.txt, subtask1_pow2_04_UniqueLargeSegs_BitChangesEverytime.txt, subtask1_pow2_05_UniqueLargeSegs.txt, subtask1_pow2_06_randomSegs.txt, subtask1_pow2_07_randomSegs.txt, subtask1_pow2_08_randomSegs.txt, subtask1_pow2_09_x_to_N-x_SegsOnly.txt, subtask1_pow2_10_x_to_N_SegsOnly.txt, subtask1_pow2_11_length_1_3_7_15_31_etc_SegsOnly_BitChangesEverytime.txt, subtask1_pow2_12_1_3_7_15_31_etc_lengthSegsPlusAlpha_BitChangesEverytime.txt, subtask1_random_01.txt, subtask1_random_02.txt, subtask1_result_minmax_01.txt, subtask1_result_minmax_02.txt, subtask1_result_minmax_03.txt
Case Name Status Exec Time Memory
subtask0_sample_01.txt AC 1 ms 256 KB
subtask0_sample_02.txt AC 1 ms 256 KB
subtask1_pow2_01_mini.txt AC 2 ms 256 KB
subtask1_pow2_02_mini.txt AC 2 ms 256 KB
subtask1_pow2_03_OnlyOneLargeSeg.txt TLE 4203 ms 2304 KB
subtask1_pow2_04_UniqueLargeSegs_BitChangesEverytime.txt TLE 4203 ms 2176 KB
subtask1_pow2_05_UniqueLargeSegs.txt TLE 4203 ms 2304 KB
subtask1_pow2_06_randomSegs.txt AC 1857 ms 2560 KB
subtask1_pow2_07_randomSegs.txt AC 1856 ms 2560 KB
subtask1_pow2_08_randomSegs.txt AC 1856 ms 2560 KB
subtask1_pow2_09_x_to_N-x_SegsOnly.txt AC 2753 ms 2560 KB
subtask1_pow2_10_x_to_N_SegsOnly.txt AC 2752 ms 2560 KB
subtask1_pow2_11_length_1_3_7_15_31_etc_SegsOnly_BitChangesEverytime.txt AC 2433 ms 2432 KB
subtask1_pow2_12_1_3_7_15_31_etc_lengthSegsPlusAlpha_BitChangesEverytime.txt TLE 4203 ms 2176 KB
subtask1_random_01.txt AC 1845 ms 1664 KB
subtask1_random_02.txt AC 1838 ms 1664 KB
subtask1_result_minmax_01.txt AC 1 ms 256 KB
subtask1_result_minmax_02.txt AC 1 ms 256 KB
subtask1_result_minmax_03.txt AC 1 ms 256 KB