博客
关于我
codeforces 543E. Listening to Music
阅读量:252 次
发布时间:2019-03-01

本文共 1222 字,大约阅读时间需要 4 分钟。

每个线段树节点需要保存四个值,ls,rs,min,tag
由于空间不够 所以把他们压缩成一个unsinged long long
t[x] = (ls * N + rs) * T + val + tag
t[x] % T 即可得到val + tag, ls = t[x] / T / N, rs = t[x] / T % N
进行标记永久化过后可以用左右儿子的值解出自己的val,再解出tag
然后就卡着内存过去了
黑科技简直可怕
code(爆空间的)

#include
#include
#include
#include
#include
#include
using namespace std;vector
vec[200010];struct trnode{ int lc,rc,c,u;}tr[3800010];int tot=0,root[200010];void update(int &x,int l,int r,int fl,int fr,int c){ tr[++tot]=tr[x];x=tot; if(l==fl&&r==fr) { tr[x].c+=c;tr[x].u+=c;return;} int mid=(l+r)/2; if(fr<=mid) update(tr[x].lc,l,mid,fl,fr,c); else if(fl>mid) update(tr[x].rc,mid+1,r,fl,fr,c); else update(tr[x].lc,l,mid,fl,mid,c),update(tr[x].rc,mid+1,r,mid+1,fr,c); tr[x].c=min(tr[tr[x].lc].c,tr[tr[x].rc].c)+tr[x].u;}int findans(int x,int l,int r,int fl,int fr){ if(!x) return 0; if(l==fl&&r==fr) return tr[x].c; int mid=(l+r)/2; if(fr<=mid) return findans(tr[x].lc,l,mid,fl,fr)+tr[x].u; if(fl>mid) return findans(tr[x].rc,mid+1,r,fl,fr)+tr[x].u; return min(findans(tr[x].lc,l,mid,fl,mid),findans(tr[x].rc,mid+1,r,mid+1,fr))+tr[x].u;}int n,m,cnt=0,b[200010];struct node{ int a,num;}a[200010];bool cmp(node a,node b) { return a.a

转载地址:http://kmza.baihongyu.com/

你可能感兴趣的文章
MySQL之2003-Can‘t connect to MySQL server on ‘localhost‘(10038)的解决办法
查看>>
MySQL之CRUD
查看>>
MySQL之DML
查看>>
Mysql之IN 和 Exists 用法
查看>>
MYSQL之REPLACE INTO和INSERT … ON DUPLICATE KEY UPDATE用法
查看>>
MySQL之SQL语句优化步骤
查看>>
MYSQL之union和order by分析([Err] 1221 - Incorrect usage of UNION and ORDER BY)
查看>>
Mysql之主从复制
查看>>
MySQL之函数
查看>>
mysql之分组查询GROUP BY,HAVING
查看>>
mysql之分页查询
查看>>
Mysql之备份与恢复
查看>>
mysql之子查询
查看>>
MySQL之字符串函数
查看>>
mysql之常见函数
查看>>
Mysql之性能优化--索引的使用
查看>>
mysql之旅【第一篇】
查看>>
Mysql之索引选择及优化
查看>>
mysql之联合查询UNION
查看>>
mysql之连接查询,多表连接
查看>>