#if 0 想定TLE 愚直解 O(Q N lg N) #endif #define ONLINE // includes {{{ #include #include #include #include #include #include #include #include #include #include #include #include #include #include // #include // #include // #include // #include // }}} using namespace std; using ll = long long; constexpr ll inf = 1ll << 40; int n, q; int main() { std::ios::sync_with_stdio(false), std::cin.tie(0); cin >> n >> q; assert(1 <= n && n < (1 << 16)); assert(1 <= q && q < (1 << 16)); vector med(q), smaller(q), bigger(q); vector v(n); for(auto &e: v) { cin >> e; assert(0 <= e && e < inf); } vector t(q), l(q), r(q); for(int i = 0; i < q; i++) cin >> t[i] >> l[i] >> r[i]; ll sum16 = 0, sum40 = 0; for(int i = 0; i < q; i++) { if(t[i] == 1) { // update #ifdef ONLINE l[i] ^= sum16; r[i] ^= sum40; #endif assert(1 <= l[i] && l[i] <= n); assert(0 <= r[i] && r[i] < inf); l[i]--; v[l[i]] = r[i]; } else { // query #ifdef ONLINE l[i] ^= sum16; r[i] ^= sum16; #endif assert(1 <= l[i] && l[i] <= n); assert(1 <= r[i] && r[i] <= n); if(l[i] > r[i]) swap(l[i], r[i]); l[i]--; vector w(v.begin() + l[i], v.begin() + r[i]); sort(begin(w), end(w)); ll a = w[(int(w.size()) - 1)/2]; ll b = 0; for(auto e : w) b += abs(e - a); sum16 ^= b % (1 << 16); sum40 ^= b % (1ll << 40); cout << b << "\n"; cout << flush; } } return 0; }