提交记录 21995


用户 题目 状态 得分 用时 内存 语言 代码长度
Kiharatouma 1001b. 测测你的排序3 Accepted 100 1.367 s 914952 KB C++ 1.42 KB
提交时间 评测时间
2024-07-26 11:29:07 2024-07-26 11:29:13
#pragma GCC optimize("Ofast,inline,unroll-loops")
#include <bits/stdc++.h>
#include <immintrin.h>
#include <algorithm>

using namespace std;

    uint  b[1<<27];
template<int n>
struct foo {

template<class T>
static void F(uint* __restrict__ buc, uint* __restrict__ a, uint* __restrict__ b, T lambda) {
    for (int i = 0; i < n; i += 16) {
        _mm_prefetch(&a[i + 256], _MM_HINT_NTA);
        #pragma GCC unroll 16
        for (int j = 0; j < 16; j++)
            b[buc[lambda(a[i + j])]++] = a[i + j];
    }
}
static void sort(uint* a, int) {
    uint buc[4][256] = {};
    for (int i = 0; i < n; i++) {
        buc[0][a[i] & 255]++;
        buc[1][a[i] >> 8 & 255]++;
        buc[2][a[i] >> 16 & 255]++;
        buc[3][(a[i] >> 16) >> 8 & 255]++;
    }
    for (int k = 0; k < 4; k++) {
        uint32_t offset = 0;
        for (int i = 0; i < 256; i++)
            swap(buc[k][i], offset), offset += buc[k][i];
    }
    F(buc[0], a, b, [](uint x) { return x & 255; });
    F(buc[1], b, a, [](uint x) { return x >> 8 & 255; });
    F(buc[2], a, b, [](uint x) { return x >> 16 & 255; });
    F(buc[3], b, n==34217728?b+34217728:a, [](uint x) { return x >> 24; });
}
};
void sort(uint* a, int __n) {
    // nth_element(a, a+34217728, a+134217728);
    foo<100000000>::sort(a+34217728,100000000);
    foo<34217728>::sort(a, 34217728);
    int p = 0, q = 34217728, r = 34217728; 
    while (p!=r) a[p++] = r==134217728||b[q]<a[r]?b[q++]:a[r++];
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #11.367 s893 MB + 520 KBAcceptedScore: 100


Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 10:05:48 | Loaded in 0 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠