This is a tree of interval segment tree nesting weights. It seems to be more troublesome than writing in reverse. SAD.
In order to save memory. The segment tree of the inner layer should be opened dynamically.
/* I'll wait for you */#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #i Nclude <ctime> #include <algorithm> #include <iostream> #include <fstream> #include <vector > #include <queue> #include <deque> #include <set> #include <map> #include <string># Define make Make_pair#define fi first#define se second using namespace std; typedef long Long Ll;typedef unsigned long long ull;typedef pair<int, int> pii;typedef map<int, int> Mii; const int MAXN = 100010;const int MAXM = 1010;const int maxs = 26;const int inf = 0x3f3f3f3f;const int P = 1000000007;cons T double eps = 1e-6; inline ll read () {ll x = 0, f = 1; char ch = getchar (); while (Ch < ' 0 ' | | ch > ' 9 ') f = (ch = = '-'? -1:1), ch = getchar (); while (Ch >= ' 0 ' && ch <= ' 9 ') x = x * + ch-' 0 ', ch = getchar (); return x * f;} struct tree{int sum; Tree *ls, *rs;} *null, *_a[4* MAXN], *_c[4 * MAXN]; vector<pair<tree*, int> > _vector; int n, m; void init () {null = new Tree (), null, sum = 0; NULL, ls = null, rs = null; for (int i = 1; I <= n << 2; i++) _a[i] = _c[i] = null;} Tree *_insert (tree *o, int l, int r, int cnt, int num) {if (o = = null) o = new Tree (), *o = *null; if (L = r) {int mid = (L + r) >> 1; if (num <= mid) o-ls = _insert (o-LS, L, Mid, CNT, NUM); Else O-rs = _insert (O-RS, mid + 1, R, CNT, NUM); } o-sum + = cnt; return o;} void Insert (int o, int l, int r, int x, int y, int num) {if (x = = L && y = = r) _c[o] = _insert (_c[o], 1, N, 1, num); else {int mid = (L + r) >> 1; _a[o] = _insert (_a[o], 1, N, (y-x + 1), num); if (x <= mid) Insert (2 * o, L, Mid, X, Min (Mid, y), num); if (Y > mid) InseRT (2 * o + 1, mid + 1, R, Max (mid + 1, x), y, num); }} void _query (int o, int l, int r, int x, int y) {_vector.push_back (Make (_c[o], y-x + 1)); if (L = = x && r = = y) _vector.push_back (Make (_a[o], 1)); else {int mid = (L + r) >> 1; if (x <= mid) _query (2 * o, L, Mid, X, Min (Mid, y)); if (Y > Mid) _query (2 * o + 1, mid + 1, R, Max (mid + 1, x), y); }} int query (int l, int r, int k) {_vector.clear (), _query (1, 1, N, L, R); int size = _vector.size (), _l = 1, _r = n; while (_l! = _r) {int tmp = 0, Mid = (_l + _r)/2; for (int i = 0; i < size; i++) {Tree *_tree = _vector[i].fi; int mul = _vector[i].se; TMP + = Mul * _tree-RS---sum; } for (int i = 0; i < size; i++) {Tree *&_tree = _vector[i].fi; if (k <= tmp) _tree = _tree, rs, _l = mid + 1; else _tree = _tree-ls, _r = mid; } if (K > tmp) K-= tmp; } return (_l + _r) >> 1;} int main () {n = read (), M = Read (), Init (); for (int i = 1; I <= m; i++) {int t = read (), a = read (); int b = Read (), C = Read (); if (t = = 1) Insert (1, 1, N, a, b, c); if (t = = 2) printf ("%d\n", query (a, B, c)); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
BZOJ3110 "segment Tree"