1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
| #pragma GCC target("avx2") #include <immintrin.h> #include <stdio.h>
__attribute__((aligned(32))) unsigned arr[70005]; __attribute__((aligned(32))) unsigned rr[8];
char ibf[10000005]; unsigned li = 0; unsigned qread() { unsigned res = 0; char ch; while((ch = ibf[li++]) < '0' || ch > '9'); do { res = res * 10 + (ch - '0'); } while((ch = ibf[li++]) >= '0' && ch <= '9'); return res; }
unsigned calc(unsigned x, unsigned y, unsigned mid) { __m256i cmp_mask = _mm256_set1_epi32(mid + 1); __m256i cnts1 = _mm256_setzero_si256(), cnts2 = _mm256_setzero_si256(), cnts3 = _mm256_setzero_si256(), cnts4 = _mm256_setzero_si256(); unsigned cntv = 0; unsigned i = x; for(;i%8&&i<=y;i++) if(arr[i] <= mid) cntv++; for(;i+31<=y;i+=32) { __m256i a1 = _mm256_load_si256((__m256i *)(arr + i)); __m256i a2 = _mm256_load_si256((__m256i *)(arr + i + 8)); __m256i a3 = _mm256_load_si256((__m256i *)(arr + i + 16)); __m256i a4 = _mm256_load_si256((__m256i *)(arr + i + 24)); a1 = _mm256_cmpgt_epi32(cmp_mask, a1); a2 = _mm256_cmpgt_epi32(cmp_mask, a2); a3 = _mm256_cmpgt_epi32(cmp_mask, a3); a4 = _mm256_cmpgt_epi32(cmp_mask, a4); cnts1 = _mm256_add_epi32(cnts1, a1); cnts2 = _mm256_add_epi32(cnts2, a2); cnts3 = _mm256_add_epi32(cnts3, a3); cnts4 = _mm256_add_epi32(cnts4, a4); } for(; i + 7 <= y; i += 8) { cnts1 = _mm256_add_epi32(cnts1, _mm256_cmpgt_epi32(cmp_mask, _mm256_load_si256((__m256i *)(arr + i)))); } for(;i<=y;i++) if(arr[i] <= mid) cntv++; unsigned cnt = cntv; _mm256_store_si256((__m256i *)rr, cnts1); cnt = cnt - rr[0] - rr[1] - rr[2] - rr[3] - rr[4] - rr[5] - rr[6] - rr[7]; _mm256_store_si256((__m256i *)rr, cnts2); cnt = cnt - rr[0] - rr[1] - rr[2] - rr[3] - rr[4] - rr[5] - rr[6] - rr[7]; _mm256_store_si256((__m256i *)rr, cnts3); cnt = cnt - rr[0] - rr[1] - rr[2] - rr[3] - rr[4] - rr[5] - rr[6] - rr[7]; _mm256_store_si256((__m256i *)rr, cnts4); cnt = cnt - rr[0] - rr[1] - rr[2] - rr[3] - rr[4] - rr[5] - rr[6] - rr[7]; return cnt; }
unsigned min(unsigned x, unsigned y) { return x < y ? x : y; } unsigned max(unsigned x, unsigned y) { return x > y ? x : y; }
int main() { #ifdef LB_IS_TESTING freopen("P4278.in", "r", stdin); freopen("P4278.out", "w", stdout); #endif fread(ibf, 1, sizeof ibf, stdin); unsigned n; n = qread(); for(unsigned i=1;i<=n;i++) { arr[i] = qread(); } unsigned q; q = qread(); unsigned lstans = 0; while(q--) { char op = ibf[li++]; if(op == '\n') op = ibf[li++]; if(op == 'Q') { unsigned x, y, k; x = qread(); y = qread(); k = qread(); x ^= lstans; y ^= lstans; k ^= lstans; unsigned l = 0, r = 70000; unsigned kl = 70000ull * (k > 5 ? k - 5 : 0) / (y - x + 1), kr = min(70000, 70000ull * (k + 5) / (y - x + 1)); if(calc(x, y, kl) < k) l = kl; if(calc(x, y, kr) >= k) r = kr; while(l < r) { unsigned mid = (l + r) / 2; if(calc(x, y, mid) >= k) r = mid; else l = mid + 1; } printf("%u\n", lstans = l); } else if(op == 'M') { unsigned x, val; x = qread(); val = qread(); x ^= lstans; val ^= lstans; arr[x] = val; } else { unsigned x, val; x = qread(); val = qread(); x ^= lstans; val ^= lstans; for(unsigned i=++n;i>=x+1;i--) arr[i] = arr[i-1]; arr[x] = val; } } return 0; }
|