HDU1754 Splay 区间维护
来源:互联网 发布:中国网络菜市场首页 编辑:程序博客网 时间:2024/04/29 22:15
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <iostream>#include <algorithm>#include <set>#include <map>#include <stack>#include <queue>#include <string>#include <vector>using namespace std;#define REP(i, a, b) for (int i = (a), _end_ = (b); i <= _end_; ++i)#define debug(...) fprintf(stderr, __VA_ARGS__)#define mp make_pair#define x first#define y second#define pb push_back#define SZ(x) (int((x).size()))#define ALL(x) (x).begin(), (x).end()template<typename T> inline bool chkmin(T &a, const T &b){ return a > b ? a = b, 1 : 0; }template<typename T> inline bool chkmax(T &a, const T &b){ return a < b ? a = b, 1 : 0; }typedef long long LL;const int dmax = 300100, oo = 0x3f3f3f3f;int n, m;#define L ch[0]#define R ch[1]struct node{ int x, val, max, size; node *f, *ch[2]; node() { x = val = max = size = 0; f = L = R = NULL; }};node *Null = new node;inline node *new_node(int k, int val){ node *tmp = new node; tmp->x = k; tmp->size = 1; tmp->val = tmp->max = val; tmp->f = tmp->L = tmp->R = Null; return tmp;}struct Splay{ node *root; node *c[dmax]; inline bool is_root(node *t){ return t == root; } inline int Max(node *t){ return t == Null ? -oo : t->max; } inline int size(node *t){ return t == Null ? 0 : t->size; } inline void push_up(node *t) { int T = max(Max(t->L), Max(t->R)); t->max = max(T, t->val); t->size = size(t->L) + size(t->R) + 1; } inline void rotate(node *x) { node *y = x->f; if (is_root(y)) root = x; else{ if (y == y->f->L) y->f->L = x; else y->f->R = x; } x->f = y->f; int k = x == y->R; y->ch[k] = x->ch[!k]; x->ch[!k]->f = y; x->ch[!k] = y; y->f = x; push_up(y); push_up(x); } inline void splay(node *x, node *t) { while (x->f != t) { node *y = x->f; if (y->f == t) rotate(x); else{ node *z = y->f; if (x == z->L->L || x == z->R->R) rotate(y); else rotate(x); rotate(x); } } } inline void push(node *t, int k, int val) { int T = k >= t->x; c[k] = t->ch[T] = new_node(k, val); t->ch[T]->f = t; t = t->ch[T]; node *tmp = t; while (tmp != Null) { push_up(tmp); tmp = tmp->f; } splay(t, Null); } void insert(int k, int val, node *t) { int T = k >= t->x; if (t->ch[T] != Null) insert(k, val, t->ch[T]); else push(t, k, val); } inline void access(int x, int y) { splay(c[x - 1], Null); splay(c[y + 1], root); } inline int query(int x, int y) { access(x, y); return c[y + 1]->L->max; } void update(int k, int s, node *t) { if (k == t->x) { t->val = s; push_up(t); } int T = k > t->x; if (t->ch[T] != Null) update(k, s, t->ch[T]); push_up(t); } void dfs(node *t) { if (t == Null || t == NULL) return; dfs(t->L); dfs(t->R); delete t; }}t;int main(){#ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);#endif while (scanf("%d%d", &n, &m) != EOF) { t.dfs(t.root); t.root = t.c[0] = new_node(0, -oo); REP(i, 1, n) { int k; scanf("%d", &k); t.insert(i, k, t.root); } t.insert(n + 1, -oo, t.root); getchar(); while (m--) { int c = getchar(), x, y; scanf("%d%d", &x, &y); if (c == 'Q') printf("%d\n", t.query(x, y)); else t.update(x, y, t.root); getchar(); } } return 0;}
0 0
- HDU1754 Splay 区间维护
- Splay维护区间
- Splay 区间维护模板
- hdu1754线段树维护区间最大值
- 线段树维护区间最大值hdu1754
- hdu1754(线段数维护区间最大值)
- POJ 3580 SuperMemo Splay 区间维护
- HDU 3487 splay区间维护问题
- POJ3468--Splay维护区间加标记
- [SPLAY维护区间][BZOJ 3223][TYVJ 1729]文艺平衡树
- POJ 3580 SuperMemo Splay/可持久化Treap 维护区间
- Splay 区间信息的维护与查询 静态模板
- BZOJ 1552 浅谈SPLAY维护区间最值
- HDU1754 I Hate It (Splay)
- hdu1754 I hate it【splay树】
- ZOJ Monthly, March 2014,3765 Lights (Splay 基本操作,并维护区间上的信息 * 模板)
- POJ 3468 A simple problem with integers Splay 区间维护模板题
- POJ 3580 较复杂的Splay区间维护题解题报告
- android沉浸状态栏和顶部状态栏背景色的设置
- 结构体互为成员
- 我的第一篇博客
- 以投影的方式看傅里叶变换&L&Z
- C#判断字母大小写
- HDU1754 Splay 区间维护
- Homework-RandomInArrayLis
- C++中insert iterator/iostream iterator的使用方法(详细)
- Spring 多数据库 配置
- SNMP北向配置(trap)
- Java String中理解起来模糊的东西,我来给我扫扫盲。(String类的intern() 、equal()、 == )
- 双目测距(二)--双目标定与矫正
- Java去除字符串中的空格、回车、换行符、制表符 及 常用正则表达式
- emmc/sd驱动代码预览