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 122 123 124 125 126 127 128 129 130 131 132
| #include <bits/stdc++.h> #define rep(i, l, r) for(int i = (l), i##end = (r); i <= i##end; i++) #define per(i, r, l) for(int i = (r), i##end = (l); i >= i##end; i--) #define debug(x) cerr<<#x<<" = "<<x #define pii pair<int, int> #define mp make_pair #define pb push_back #define fi first #define se second using namespace std; typedef long long ll; const int N = 1e5+10, mod = 20060209; const double inf = 1e16; int n, m, rt, sed, tot, son[N<<1][2], siz[N<<1], num[N<<1], rnd[N<<1]; ll a[N], val[N<<1], sum[N<<1]; inline int rd() { return sed = 114514ll*sed%mod*1919810%mod; } inline void push_up(int p) { siz[p] = siz[son[p][0]]+siz[son[p][1]]+num[p]; sum[p] = sum[son[p][0]]+sum[son[p][1]]+val[p]*num[p]; } inline void spin(int &p, int s) { int t = son[p][s]; son[p][s] = son[t][s^1]; son[t][s^1] = p; push_up(p); push_up(t); p = t; } void ins(int &p, ll k) { if(!p) { p = ++tot; rnd[p] = rd(); siz[p] = num[p] = 1; val[p] = sum[p] = k; return; } if(val[p] == k) { num[p]++; siz[p]++; sum[p] += k; return; } int t = (val[p] < k); ins(son[p][t], k); if(rnd[son[p][t]] > rnd[p]) spin(p, t); push_up(p); } void del(int &p, ll k) { if(!p) return; if(val[p] == k) { if(num[p] > 1) { num[p]--; siz[p]--; sum[p] -= k; return; } if(!son[p][0] && !son[p][1]) p = 0; else if(son[p][0] && !son[p][1]) { spin(p, 0); del(son[p][1], k); } else if(!son[p][0] && son[p][1]) { spin(p, 1); del(son[p][0], k); } else { int t = (rnd[son[p][0]] < rnd[son[p][1]]); spin(p, t); del(son[p][t^1], k); } push_up(p); return; } int t = (val[p] < k); del(son[p][t], k); if(rnd[son[p][t]] > rnd[p]) spin(p, t); push_up(p); } double query(int p, ll k, ll s1, int s2) { if(!p) return inf; double t = (s1+sum[p]-sum[son[p][1]]+k)*1.0/(s2+siz[p]-siz[son[p][1]]); if(t > val[p]) return min(query(son[p][1], k, s1+sum[p]-sum[son[p][1]], s2+siz[p]-siz[son[p][1]]), t); else return query(son[p][0], k, s1, s2); } int main() { sed = time(0)%mod; scanf("%d%d", &n, &m); rep(i, 1, n) scanf("%d", &a[i]), ins(rt, a[i]); rep(i, 1, m) { int op, p; ll v; scanf("%d", &op); if(op == 1) { scanf("%d%lld", &p, &v); del(rt, a[p]); ins(rt, v); a[p] = v; } else { scanf("%lld", &v); printf("%.5lf\n", query(rt, v, 0, 0)); } } return 0; }
|