Build a tree of weights line ... Even discretization is not necessary ...
Without reading into the optimization of the tle, plus a drop off ... And it's fast approaching 1/4 ....
------------------------------------------------------------------------------------------
#include <bits/stdc++.h>#define REP (i, n) for (int i = 0; i < n; i++)#define CLR (x, C) memset (x, C, sizeof (x))#define M (L, R) (((L) + (R)) >> 1)using namespace std; const int MAXN = 1000009;struct Node {Node *l, *r;bool S;Node () {s = false;}inline void Update () {s = l->s | | r->s;}} POOL[MAXN << 1], *pt = Pool, *root;void Build (node* t, int l, int r) {if (R > L) {int m = m (l, R);Build (T->l = pt++, L, m);Build (T->r = pt++, M + 1, R);}}int N, v, type;void Modify (node* t, int l, int r) {if (L = = r) {if (type = = 1 &&!t->s) T->s = true;if (type = = 2 && t->s) T->s = false;} else {int m = m (l, R);v <= m Modify (T->l, L, m): Modify (T->r, M + 1, R);t->update ();}}int query (node* t, int l, int r) {if (!t->s) return 0;if (L = = r) return l;int m = m (l, R);return type = = 3? (t->l->s. Query (T->l, L, m): query (T->r, M + 1, R)):(t->r->s. Query (T->r, M + 1, R): Query (T->l, L, M));}int succ (node* t, int l, int r) {if (!t->s) return 0;if (L = = r) return l <= v 0:l;int m = m (l, R);if (v >= m) return succ (T->r, M + 1, R);int ans = succ (t->l, L, m);return ans ans:succ (t->r, M + 1, R);}int pred (node* t, int l, int r) {if (!t->s) return 0;if (L = = r) return l >= v 0:l;int m = m (l, R);if (m + 1 >= v) return pred (T->l, L, m);int ans = pred (t->r, M + 1, R);return ans ans:pred (t->l, L, m);}int Find (node* t, int l, int r) {if (!t->s) return-1;if (L = = r) return 1;int m = m (l, R);return v <= m? Find (T->l, L, m): Find (T->r, M + 1, R);}inline void Read (int &t) {t = 0;char C = getchar ();For (;!isdigit (c); c = GetChar ());For (; IsDigit (c); c = GetChar ())t = T * + C-' 0 ';}int main () {freopen ("test.in", "R", stdin);freopen ("Test.out", "w", stdout);int m;cin >> n >> m;n++;Build (Root = pt++, 1, n);While (m--) {read (type);switch (type) {Case 1:read (v); v++; modify (root, 1, n);Case 2:read (v); v++; modify (root, 1, n);Case 3:printf ("%d\n", Query (root, 1, N)-1);Case 4:printf ("%d\n", Query (root, 1, N)-1);Case 5:read (v); v++; printf ("%d\n", pred (root, 1, N)-1);Case 6:read (v); v++; printf ("%d\n", succ (root, 1, N)-1);Case 7:read (v); v++; printf ("%d\n", find (root, 1, n));Default:break;}}return 0;}
------------------------------------------------------------------------------------------
3685: General van Emde Boas tree Time Limit:9 Sec Memory Limit:MB
Submit:616 Solved:216
[Submit] [Status] [Discuss] Description
Design data structure Support:
1 x If x does not exist, insert X
2 x if x exists, delete x
3 Output Current minimum value, if no output-1
4 output Current maximum value, if no output-1
5 x Output x precursor, if no output-1
6 x Output x successor, if not present output-1
7 x If x exists, output 1, otherwise output-1
Input
The first line gives the range and number of actions that N,M represents the number of occurrences
The next M-line gives the operation
N<=10^6,m<=2*10^6,0<=x<n
Outputsample Input 10 11
1 1
1 2
1 3
7 1
7 4
2 1
3
2 3
4
5 3
6 2
Sample Output 1
-1
2
2
2
-1
HINT
Source
by Zky
Bzoj 3685: Ordinary van Emde Boas tree (line segment tree)