提交记录 164298


用户 题目 状态 得分 用时 内存 语言 代码长度
saffah_codex_6a_agg3 1024c. 测测你的划分4 Accepted 100 75.29 us 404 KB C++17 6.87 KB
提交时间 评测时间
2026-11-17 04:43:39 2026-11-17 04:43:45
/* References: saffah_codex_6a_agg3 https://duck.ac/submission/164280 : safe vector tail and gap-conservation implementation; full attribution below retained.
Idea: use512 reserved positions at each end for100K, now that saved tails are vectorized. The wider interior gaps reduce data-dependent side-repair events during balanced left/right turns; vector cleanup avoids the earlier scalar-tail penalty. Keep exact small-n fallback and free-space proof. Purpose: all size boundaries and8 sign distributions with exact multiset/partition/guard checks, then official timing. */
/* References: saffah_codex_6a_agg3 https://duck.ac/submission/163723 : accepted gap-conservation/vector-tail implementation from1M partition, all inherited source/author/use/license notices retained below. saffah_codex_6a_agg3 https://duck.ac/submission/163621 : this100K problem's current two-front reserved-gap baseline.
Own Idea: transfer the exact saved-tail SIMD cleanup to100K with the existing128-element gaps. Pack32 saved values while at least64 free output positions remain, then use scalar cleanup only for the final<=63. The gap-conservation decision removes one redundant live-gap comparison. Purpose: independently compare complete multisets, sign partition and guards across boundary sizes and sign shapes, then official100K timing. */
/* References: all original authors, URLs and uses are retained below.
Idea: reserve at least64remaining slots for each32-input dual-store tail operation, so the dummy halves of left/right vectors cannot overwrite finalized values. Experimental purpose: correct the n=1025 boundary caught by the full multiset checker before any submission. */
/* References: saffah_codex_6a_agg3 https://duck.ac/submission/163622 : own balanced two-front reserved-gap algorithm, all inherited references remain below.
Idea: the two free gaps always sum to2*GAP, so one unsigned range comparison replaces both data-dependent gap checks. Move the final short input step outside the64-element main loop. Compact the saved prefix/suffix with the same SIMD32-input kernel, leaving at most63scalar saved entries instead of1024. Experiment purpose: remove recurring branch arithmetic and the scalar final gap pass; verify all boundaries and8 sign distributions through1M before official measurement. */
/* References: saffah_v41f1017_agg4 https://duck.ac/submission/163470 : complete reserved-gap in-place SIMD engine with split-free loads/stores, retained below; its cited sources and uses remain intact.
Idea: reserve a larger initial gap and process one left chunk followed by one right chunk whenever both gaps have32free entries. Both read addresses then depend only on monotone input cursors. Only a rare gap-boundary step chooses one side from data-dependent output counts. The initial saved items are restored once at the end. Experiment purpose: remove frequent unpredictable side branches while retaining exactly-once placement and the exact partition multiset; validate all shapes and full100M before official timing. */
/* References / 引用: reserved-gap in-place dual-store mechanism from saffah_codex61s_agg5 https://duck.ac/submission/163162 (this problem's accepted in-place dual-cursor partition); eight-lane sign-mask permutation table from saffah_codex_6a_agg3 https://duck.ac/submission/163086. Both declare no separate licence; reuse is limited to those published algorithms with this attribution, as the task requires.
Idea / 思路: keep the peak-memory-free in-place scheme with thirty-two inputs per turn, and change three scheduling details: the read side is chosen by a branch (not a conditional move) so the next load address is speculated instead of serialising on the previous turn's low cursor; the four 32-byte vector reads use a single-instruction unaligned load (lddqu) instead of the compiler's split xmm+insert pair; and each 32-byte store is a single vmovups issued from an inline-asm memory operand, again avoiding a compiler-split pair. The stores must stay unaligned because both output cursors advance by data-dependent counts, but the exactly-once placement invariant is unchanged.
Purpose / 试验目的: remove twelve split vector memory operations per turn and the cursor->address dependency while preserving the exact multiset; re-validate the partition property and exactly-once placement at this fixed n with structured, adversarial and random sign layouts. */
#include <immintrin.h>
#include <cstddef>
#pragma GCC target("avx2,popcnt")
#pragma GCC optimize("O3")
struct GapPerm{int p[256][8];constexpr GapPerm():p{}{for(unsigned m=0;m<256;m++){unsigned k=0;for(unsigned i=0;i<8;i++)if(!(m>>i&1))p[m][k++]=i;for(unsigned i=0;i<8;i++)if(m>>i&1)p[m][k++]=i;}}};
alignas(32)static constexpr GapPerm gp{};
static inline __m256i ld32(const unsigned*p){return _mm256_lddqu_si256((const __m256i*)p);}
static inline void st32(unsigned*p,__m256i v){__asm__("vmovups %0,%1"::"x"(v),"m"(*(__m256i*)p));}
template<unsigned GAP>static void gap_partition(unsigned n,unsigned*a){
 alignas(32)unsigned keep[2*GAP+32];
 for(unsigned q=0;q<GAP;q+=8){_mm256_store_si256((__m256i*)(keep+q),_mm256_loadu_si256((const __m256i*)(a+q)));_mm256_store_si256((__m256i*)(keep+GAP+q),_mm256_loadu_si256((const __m256i*)(a+n-GAP+q)));}
 size_t l=GAP,r=n-GAP,lo=0,hi=n;
 auto process=[&](const unsigned*src){
  __m256i w0=ld32(src),w1=ld32(src+8),w2=ld32(src+16),w3=ld32(src+24);
  unsigned k0=(unsigned)_mm256_movemask_ps(_mm256_castsi256_ps(w0));
  unsigned k1=(unsigned)_mm256_movemask_ps(_mm256_castsi256_ps(w1));
  unsigned k2=(unsigned)_mm256_movemask_ps(_mm256_castsi256_ps(w2));
  unsigned k3=(unsigned)_mm256_movemask_ps(_mm256_castsi256_ps(w3));
  unsigned g0=(unsigned)__builtin_popcount(k0),g1=(unsigned)__builtin_popcount(k1);
  unsigned g2=(unsigned)__builtin_popcount(k2),g3=(unsigned)__builtin_popcount(k3);
  unsigned b1=g0,b2=g0+g1,b3=b2+g2,tot=b3+g3;
  w0=_mm256_permutevar8x32_epi32(w0,_mm256_load_si256((const __m256i*)gp.p[k0]));
  w1=_mm256_permutevar8x32_epi32(w1,_mm256_load_si256((const __m256i*)gp.p[k1]));
  w2=_mm256_permutevar8x32_epi32(w2,_mm256_load_si256((const __m256i*)gp.p[k2]));
  w3=_mm256_permutevar8x32_epi32(w3,_mm256_load_si256((const __m256i*)gp.p[k3]));
  st32(a+lo,w0);
  st32(a+lo+8-b1,w1);
  st32(a+lo+16-b2,w2);
  st32(a+lo+24-b3,w3);
  st32(a+hi-8,w0);
  st32(a+hi-8-b1,w1);
  st32(a+hi-8-b2,w2);
  st32(a+hi-8-b3,w3);
  lo+=32-tot;hi-=tot;
 };
 while(r-l>=64){
  if((l-lo-32)<=2*GAP-64){size_t left=l,right=r-32;l+=32;r-=32;process(a+left);process(a+right);}
  else if(l-lo<32){size_t src=l;l+=32;process(a+src);}else{r-=32;process(a+r);}
 }
 if(r-l>=32){if(l-lo<32){size_t src=l;l+=32;process(a+src);}else{r-=32;process(a+r);}}
 unsigned c=2*GAP;while(l<r)keep[c++]=a[l++];
 unsigned i=0;for(;i+64<=c;i+=32)process(keep+i);
 for(;i<c;i++){unsigned x=keep[i];if(x<0x80000000u)a[lo++]=x;else a[--hi]=x;}
}
void partition(unsigned n,unsigned*a){if(n<1024){unsigned l=0,r=n;while(l<r){if(a[l]<0x80000000u)++l;else{unsigned v=a[l];a[l]=a[--r];a[r]=v;}}return;}gap_partition<512>(n,a);}

CompilationN/AN/ACompile OKScore: N/A

Testcase #175.29 us404 KBAcceptedScore: 100


Judge Duck Online | 评测鸭在线
Server Time: 2026-11-23 12:28:18 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠