http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3154

  题意是,要求求出区间中小于某个值的数有多少个,然后利用这个个数来更新某个点的值。

  直接树套树解决问题,不过这题时间卡的比较紧。留心观察可以发现,询问的数目其实是比较小的,可是总的个数多大30W。如果是O(n*logn*logn)的复杂度建树就会超时,估计这里就是卡这一个了。其余的都不难,不过就是开始的时候没有看出可以卡时间卡这么紧,没有建树的经验,所以直接暴力插点,一直TLE。中间的时候sbt又写错了,为了debug个RE又搞了半天。

代码如下:

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <ctime>
#include <set>
#include <cctype>
#include <cmath> using namespace std; #define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define root 1, n, 1 const int N = ;
typedef long long LL; struct Node {
Node *c[];
int ky, sz;
void init(int k = ) {
ky = k;
sz = ;
c[] = c[] = NULL;
}
} node[N * ];
int ttnd; void init() { ttnd = ;} struct Treap {
Node *RT;
void init() { RT = NULL;}
int size() { return RT->sz;}
void make(int *arr, int l, int r, Node *&rt) {
if (l > r) return ;
if (l == r) {
rt = node + ttnd++;
rt->init(arr[l]);
return ;
}
int m = l + r >> ;
rt = node + ttnd++;
rt->init(arr[m]);
make(arr, l, m - , rt->c[]);
make(arr, m + , r, rt->c[]);
rt->sz = (rt->c[] ? rt->c[]->sz : ) + (rt->c[] ? rt->c[]->sz : ) + ;
}
void make(int *arr, int l, int r) {
init();
make(arr, l, r, RT);
}
void rotate(Node *&rt, bool l) {
bool r = !l;
Node *p = rt->c[l];
rt->c[l] = p->c[r];
p->c[r] = rt;
p->sz = rt->sz;
rt->sz = (rt->c[] ? rt->c[]->sz : ) + (rt->c[] ? rt->c[]->sz : ) + ;
rt = p;
}
void maintain(Node *&rt, bool r) {
if (!rt || !rt->c[r]) return ;
bool l = !r;
int ls = rt->c[l] ? rt->c[l]->sz : ;
if (rt->c[r]->c[r] && rt->c[r]->c[r]->sz > ls) {
rotate(rt, r);
} else if (rt->c[r]->c[l] && rt->c[r]->c[l]->sz > ls) {
rotate(rt->c[r], l), rotate(rt, r);
} else return ;
maintain(rt->c[], false);
maintain(rt->c[], true);
maintain(rt, false);
maintain(rt, true);
}
void insert(Node *&rt, Node *x) {
if (!rt) {
rt = x;
return ;
}
rt->sz++;
if (x->ky < rt->ky) insert(rt->c[], x);
else insert(rt->c[], x);
maintain(rt, x->ky >= rt->ky);
}
void insert(int k) {
Node *tmp = node + ttnd++;
tmp->init(k);
insert(RT, tmp);
}
void erase(Node *&rt, int k) {
if (!rt) return ;
rt->sz--;
if (k < rt->ky) erase(rt->c[], k);
else if (k > rt->ky) erase(rt->c[], k);
else {
if (!rt->c[] && !rt->c[]) rt = NULL;
else if (!rt->c[]) rt = rt->c[];
else if (!rt->c[]) rt = rt->c[];
else {
Node *t = rt->c[];
while (t->c[]) t = t->c[];
rt->ky = t->ky;
erase(rt->c[], t->ky);
}
}
if (rt) rt->sz = (rt->c[] ? rt->c[]->sz : ) + (rt->c[] ? rt->c[]->sz : ) + ;
}
void pre(Node *x) {
if (!x) return ;
cout << x << ' ' << x->c[] << ' ' << x->c[] << ' ' << x->ky << ' ' << x->sz << endl;
pre(x->c[]);
pre(x->c[]);
}
void erase(int k) { erase(RT, k);}
int find(Node *rt, int k) {
if (!rt) return ;
int ret = ;
if (k > rt->ky) ret = (rt->c[] ? rt->c[]->sz : ) + find(rt->c[], k) + ;
else ret = find(rt->c[], k);
return ret;
}
int lower_bound(int k) { return find(RT, k);}
} trp[N << ]; int pos[N], rec[N], ori[N];
void build(int l, int r, int rt) {
if (l == r) {
trp[rt].make(rec, l, r);
pos[l] = rt;
return ;
}
int m = l + r >> ;
build(lson);
build(rson);
sort(rec + l, rec + r + );
trp[rt].make(rec, l, r);
} void insert(int p, int x, int d) {
if (p <= ) return ;
trp[p].erase(d);
trp[p].insert(x);
insert(p >> , x, d);
} int query(int L, int R, int x, int l, int r, int rt) {
if (L <= l && r <= R) return trp[rt].lower_bound(x);
int m = l + r >> , ret = ;
if (L <= m) ret += query(L, R, x, lson);
if (m < R) ret += query(L, R, x, rson);
return ret;
} void scan(int &x) {
char ch;
while (!isdigit(ch = getchar())) ;
x = ch - '';
while (isdigit(ch = getchar())) x = x * + ch - '';
} int main() {
//freopen("in", "r", stdin);
int n, m, u;
while (~scanf("%d%d%d", &n, &m, &u)) {
init();
for (int i = ; i <= n; i++) {
scan(rec[i]);
ori[i] = rec[i];
}
build(root);
int L, R, v, p;
while (m--) {
scan(L), scan(R), scan(v), scan(p);
int k = query(L, R, v, root);
k = (LL) u * k / (R - L + );
insert(pos[p], k, ori[p]);
ori[p] = k;
}
for (int i = ; i <= n; i++) printf("%d\n", ori[i]);
}
return ;
}

——written by Lyon

uva 12003 Array Transformer (线段树套平衡树)的更多相关文章

  1. bzoj 2120 线段树套平衡树

    先吐下槽,改了快一个小时,最后发现是SBT的delete写错了,顿时就有想死的心..... 首先对于这道题,我们应该先做一下他的小问题,bzoj1878,虽然和这道题几乎一点关系没有, 但是能给我们一 ...

  2. 【BZOJ-3196】二逼平衡树 线段树 + Splay (线段树套平衡树)

    3196: Tyvj 1730 二逼平衡树 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2271  Solved: 935[Submit][Stat ...

  3. CF 19D - Points 线段树套平衡树

    题目在这: 给出三种操作: 1.增加点(x,y) 2.删除点(x,y) 3.询问在点(x,y)右上方的点,如果有相同,输出最左边的,如果还有相同,输出最低的那个点 分析: 线段树套平衡树. 我们先离散 ...

  4. BZOJ3196二逼平衡树——线段树套平衡树(treap)

    此为平衡树系列最后一道:二逼平衡树您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作: 1.查询k在区间内的排名2.查询区间内排名为k的值3.修改某一位值上的数值4.查询 ...

  5. P3380 【模板】二逼平衡树(树套树)(线段树套平衡树)

    P3380 [模板]二逼平衡树(树套树) 前置芝士 P3369 [模板]普通平衡树 线段树套平衡树 这里写的是线段树+splay(不吸氧竟然卡过了) 对线段树的每个节点都维护一颗平衡树 每次把给定区间 ...

  6. bzoj 3196/ Tyvj 1730 二逼平衡树 (线段树套平衡树)

    3196: Tyvj 1730 二逼平衡树 Time Limit: 10 Sec  Memory Limit: 128 MB[Submit][Status][Discuss] Description ...

  7. [BZOJ1146][CTSC2008]网络管理Network(二分+树链剖分+线段树套平衡树)

    题意:树上单点修改,询问链上k大值. 思路: 1.DFS序+树状数组套主席树 首先按照套路,关于k大值的问题,肯定要上主席树,每个点维护一棵权值线段树记录它到根的信息. 关于询问,就是Que(u)+Q ...

  8. P3380 【模板】二逼平衡树(树套树) 线段树套平衡树

    \(\color{#0066ff}{ 题目描述 }\) 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作: 查询k在区间内的排名 查询区间内排名为k的值 修改某一位值上 ...

  9. 树套树Day1线段树套平衡树bzoj3196

    您需要写一种数据结构,来维护一个有序数列,其中需要提供以下操作:1.查询k在区间内的排名2.查询区间内排名为k的值3.修改某一位值上的数值4.查询k在区间内的前驱(前驱定义为小于x,且最大的数)5.查 ...

随机推荐

  1. springmvc报404错误No mapping found for HTTP request with URI [/mavenSpringmvc/requesttest] in DispatcherServlet with name 'spring'

    问题404错误的原因有很多种 有这种,后边不带url的 这种一般就是没有进入到controller中 可以在toncat中看到信息 十一月 12, 2018 12:21:25 下午 org.sprin ...

  2. python基础--线程、进程

    并发编程: 操作系统:(基于单核研究) 多道技术: 1.空间上的复用 多个程序共用一个计算机 2.时间上的复用 切换+保存状态 例如:洗衣 烧水 做饭 切换: 1.程序遇到IO操作系统会立刻剥夺着CP ...

  3. linux文件系统配置文件

    文件系统 内核提供了一个接口,用来显示一些它的数据结构,这些数据结构对于决定诸如使用的中断.初始化的设备和内存统计信息之类的系统参数可能很有用.这个接口是作为一个独立但虚拟的文件系统提供的,称为 /p ...

  4. hdu 1296 Polynomial Problem(多项式模拟)

    Problem Description We have learned how to obtain the value of a polynomial when we were a middle sc ...

  5. 关于layui部分表单不显示的问题(Select, checkBox)

    原因: 没有使用JS进行初始化 官方说明: https://www.layui.com/doc/base/faq.html layui.use('form', function(){ var form ...

  6. loj #10001. 「一本通 1.1 例 2」种树

    题面 解题思路 贪心,首先按右端点排序,然后从小往大扫,因为要求树最少,所以要尽量放在右端点.然后开个bool数组判断是否种过树即可. 代码 #include<iostream> #inc ...

  7. 【JZOJ3295】【SDOI2013】泉(spring)

    ╰( ̄▽ ̄)╭ 济南市"泉历史研究小组"依据济南特有的泉脉关系将济南的泉水分为六个区域,分别是市中区.历下区.天桥区.槐荫区.历城区.长清区. 作为光荣的济南泉历史研究小组中的一员 ...

  8. TRS OM error

    http://192.168.1.1/ http://tplogin.cn/admin888 wddqaz123456789 package="com.trs.om.bean" m ...

  9. U盘安装win7 raid设置

    需要先安装驱动!  大白菜U盘安装界面有一个选择驱动的选项,选择驱动即可.Intel_ESRT2_Windows_signed_DRV_v16.03.2014.1127

  10. Hdu 1800 字符串hash

    题目链接 题意: 给出n(n<=3000)个字符串(长度<30,数字组成,肯能存在前导0), 问该序列最少可以分成多少个单调序列.可以转化成求相同字符串的个数的最大值 附上代码: /*** ...