Created
June 12, 2020 07:48
-
-
Save justiceHui/0ddffc3a98d4bbcaf0075e68b5978972 to your computer and use it in GitHub Desktop.
BOJ 2357 최솟값과 최댓값
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#include <immintrin.h> | |
#pragma GCC target("avx,avx2,fma") | |
using namespace std; | |
typedef long long ll; | |
int n, q; | |
alignas(256) int a[101010]; | |
const int inf = 1e9+7; | |
void query(int s, int e){ | |
int mx = -inf, mn = inf, i; | |
__m256i avxMax = _mm256_set1_epi32(-inf); | |
__m256i avxMin = _mm256_set1_epi32(inf); | |
for(i=s; (i&7) && i<=e; i++) mx = max(mx, a[i]), mn = min(mn, a[i]); | |
for(; i+8<e; i+=8){ | |
__m256i now = _mm256_load_si256((__m256i const *)(a+i)); | |
avxMax = _mm256_max_epi32(avxMax, now); | |
avxMin = _mm256_min_epi32(avxMin, now); | |
} | |
for(; i<=e; i++) mx = max(mx, a[i]), mn = min(mn, a[i]); | |
int t1[8], t2[8]; | |
_mm256_storeu_si256((__m256i *)t1, avxMax); | |
_mm256_storeu_si256((__m256i *)t2, avxMin); | |
for(i=0; i<8; i++) mx = max(mx, t1[i]), mn = min(mn, t2[i]); | |
cout << mn << " " << mx << "\n"; | |
} | |
int main(){ | |
ios_base::sync_with_stdio(false); cin.tie(nullptr); | |
//cin >> n >> q; | |
n = q = 100000; | |
for(int i=0; i<n; i++) a[i] = rand(); | |
for(int i=0; i<q; i++){ | |
int a, b; //cin >> a >> b; | |
a = 1 + (i & 31); | |
b = 100000 - (i & 31); | |
query(a-1, b-1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment