题意:

初始n个空串,m个操作:

1.给[l,r]的所有字符串头尾加一个‘d’,将原字符串x变为dxd

2.求[l,r]所有字符串代表的数字之和mod 1e9+7

思路:

据说是硬核线段树。。

对于线段树我们要先找出来对于一个区间改变的时候对要询问的区间(sum)造成的变化

对于一个数x,如果对他操作了一次(头尾加一个c),那么它将变成$10x+c+c*10^{n_i+1}$,其中$n_i$表示x的实际长度(位数)

那么对当前区间操作时,当前区间的sum会变成$10sum+(r-l+1)*c+c*sumlen$,其中$sumlen=\sum_{i=l}^{r}10^{n_i+1}$

这个东西是应该写在要打懒惰标记的地方的

上式显然是有先后操作顺序的,我们只需要将操作系列$d_3d_2d_1xd_1d_2d_3$分成$d_3d_2d_1$和$d_1d_2d_3$(用两个数保存),用两个懒惰标记addl和addr分别保存

不过在pushdown的时候要注意,懒惰标记存在于已经操作过的最后一个节点里,所以要注意次序与操作的对象

在pushdown中,如果只是下传到一个节点(比如是lc),

那么$sum[lc]=addr[root]+sum[lc]*addlen[root]+addl[root]*addlen[root]*10^{n_i+1}/10$

所以对整个lc区间,$sum[lc]=\sum addr[root]+sum[lc]*addlen[root]+addl[root]+addl[root]*addlen[root]*sumlen[root]/10$

其他的都是常规操作了,注意乘的时候别溢出了

代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map> #define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
#define lowbit(x) ((x)&(-x)) using namespace std; typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL; const db eps = 1e-;
const int mod = 1e9+;
const int maxn = 2e6+;
const int maxm = 2e6+;
const int inf = 0x3f3f3f3f;
const db pi = acos(-1.0); ll fp(ll a, ll n){
ll ans = ;
while(n){
if(n & ) ans *= a;
a *= a;
a %= mod;
n >>= ;
ans %= mod;
}
return ans;
}
ll div10;
ll sum[maxn];
ll sumlen[maxn];
ll addl[maxn],addr[maxn],addlen[maxn];
int t;
int n, m;
void build(int l, int r, int root){
int mid = (l+r)>>;
addl[root]=addr[root]=;
addlen[root]=;
if(l==r){
sum[root] = ;
sumlen[root] = ;
return;
}
build(lson);
build(rson);
sum[root]=;
sumlen[root]=sumlen[lc]+sumlen[rc];
sumlen[root]%=mod;
return;
}
void pushdown(int l, int r, int root){
int mid = (l+r)>>;
if(addlen[root]>){
addl[lc]=(addl[root]*addlen[lc]%mod+addl[lc])%mod;
addl[rc]=(addl[root]*addlen[rc]%mod+addl[rc])%mod;
addr[lc]=(addr[lc]*addlen[root]%mod+addr[root])%mod;
addr[rc]=(addr[rc]*addlen[root]%mod+addr[root])%mod;
addlen[lc]=addlen[lc]*addlen[root]%mod;
addlen[rc]=addlen[rc]*addlen[root]%mod; sum[lc]=(addr[root]*(mid-l+)%mod+sum[lc]*addlen[root]%mod+addl[root]*addlen[root]%mod*sumlen[lc]%mod*div10%mod)%mod;
sum[rc]=(addr[root]*(r-mid)%mod+sum[rc]*addlen[root]%mod+addl[root]*addlen[root]%mod*sumlen[rc]%mod*div10%mod)%mod; sumlen[lc]=(sumlen[lc]*addlen[root]%mod*addlen[root]%mod)%mod;
sumlen[rc]=(sumlen[rc]*addlen[root]%mod*addlen[root]%mod)%mod; addl[root]=addr[root]=;
addlen[root]=;
}
}
void update(int ql, int qr, ll val, int l, int r, int root){
int mid = (l+r)>>;
if(ql<=l&&r<=qr){
sum[root]=(*sum[root]%mod+(r-l+)*val%mod+val*sumlen[root]%mod)%mod;
sumlen[root]=sumlen[root]*%mod;
addl[root]=(addl[root]+val*addlen[root])%mod;
addr[root]=(addr[root]*+val)%mod;
addlen[root]=(addlen[root]*)%mod;
return;
}
pushdown(l,r,root);
if(ql<=mid)update(ql,qr,val,lson);
if(qr>mid)update(ql,qr,val,rson);
sum[root]=(sum[lc]+sum[rc])%mod;
sumlen[root]=(sumlen[lc]+sumlen[rc])%mod;
return;
}
ll query(int ql, int qr, int l, int r, int root){
int mid = (l+r)>>;
if(ql<=l&&r<=qr)return sum[root]%mod;
ll ans = ;
pushdown(l,r,root);
if(ql<=mid)ans+=query(ql,qr,lson);
if(qr>mid)ans+=query(ql,qr,rson);
return ans%mod;
}
char op[];
int main(){
scanf("%d", &t);
div10=fp(,mod-)%mod;
for(int ncase = ; ncase <= t; ncase++){
scanf("%d %d", &n, &m);
build(,n,);
printf("Case %d:\n",ncase);
while(m--){
ll w;
int x, y;
scanf("%s",op+);
scanf("%d %d", &x, &y);
if(op[]=='w'){
scanf("%lld", &w);
update(x, y, w, , n, );
}
else{
printf("%lld\n",query(x,y,,n,)%mod);
}
} } return ;
}
/*
2
3 3
wrap 1 3 1
wrap 2 4 3
query 1 2
4 4
wrap 1 3 0
wrap 2 4 3
query 1 4
query 2 3 1
4 4
wrap 1 3 0
wrap 2 4 3 3
4 4
wrap 1 4 2
wrap 1 4 3
wrap 1 4 1
wrap 2 4 6
3 2
wrap 1 3 0
wrap 2 2 1
5 3
wrap 1 5 1
wrap 2 6 0
wrap 3 5 2
*/

HDU 6562 lovers 2018CCPC吉林H(线段树)的更多相关文章

  1. HDU 3074.Multiply game-区间乘法-线段树(单点更新、区间查询),上推标记取模

    Multiply game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  2. hdu 5274 Dylans loves tree(LCA + 线段树)

    Dylans loves tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Othe ...

  3. HDU 1394 Minimum Inversion Number(线段树求最小逆序数对)

    HDU 1394 Minimum Inversion Number(线段树求最小逆序数对) ACM 题目地址:HDU 1394 Minimum Inversion Number 题意:  给一个序列由 ...

  4. HDU 5875 Function (2016年大连网络赛 H 线段树+gcd)

    很简单的一个题的,结果后台数据有误,自己又太傻卡了3个小时... 题意:给你一串数a再给你一些区间(lef,rig),求出a[lef]%a[lef+1]...%a[rig] 题解:我们可以发现数字a对 ...

  5. hdu 1556:Color the ball(线段树,区间更新,经典题)

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  6. hdu 1255 覆盖的面积(线段树 面积 交) (待整理)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1255 Description 给定平面上若干矩形,求出被这些矩形覆盖过至少两次的区域的面积.   In ...

  7. HDU 1828 / POJ 1177 Picture (线段树扫描线,求矩阵并的周长,经典题)

    做这道题之前,建议先做POJ 1151  Atlantis,经典的扫描线求矩阵的面积并 参考连接: http://www.cnblogs.com/scau20110726/archive/2013/0 ...

  8. hdu 1754 I Hate It (模板线段树)

    http://acm.hdu.edu.cn/showproblem.php?pid=1754 I Hate It Time Limit: 9000/3000 MS (Java/Others)    M ...

  9. HDU 1166 敌兵布阵(线段树 单点更新)

     点我看题目  题意 :HDU的中文题也不常见....这道题我就不详述了..... 思路 :这个题用线段树用树状数组都可以,用线段树的时候要注意输入那个地方,输入一个字符串的时候不要紧接着输入两个数字 ...

随机推荐

  1. Scala:用于Java的轻量级函数式编程

    Scala为Java开发提供了轻量级的代码选项,但是学习过程可能会很艰难.了解有关Scala的知识以及是否值得采用. 基于Java的语言通常涉及冗长的语法和特定于领域的语言,用于测试,解析和数值计算过 ...

  2. html 贪吃蛇代码

    最近在搞自己的网站,维护的时候准备放个贪吃蛇上去,顶一下原有的页面. 这个贪吃蛇有一点毒.原来设定了100级:100级刚开局就挂了.后来改掉了选项菜单,修复了. 还有什么bug,欢迎点击侧边的QQ按钮 ...

  3. 第一篇博客-- 走上IT路

    首先介绍一下本人,我是一名在校大学生,在一次学长分享学习经验时了解到,写博客可以帮助复习.所以这就是我要写博客的原因. 我是非常喜欢网络安全技术,因此我选择了我这个专业.在接下来的一段时间我会在这里记 ...

  4. kafka 中 zookeeper 具体是做什么的?

    zookeeper 是 kafka 不可分割的一部分,可见其重要程度,所以我们有必要了解一下 zookeeper 在 kafka 中的具体工作内容. 而且,这也是面试时经常问的. zookeeper ...

  5. http的异步请求

    需要用到的包(包版本应该可能不同): httpcore-4.1.4.jar httpsayncclient-4.0-alpha3.jar httpcore-nio-4.2-alpha3.jar /** ...

  6. PythonI/O进阶学习笔记_11.python的多进程

    content: 1. 为什么要多进程编程?和多线程有什么区别? 2. python 多进程编程 3. 进程间通信 =======================================   ...

  7. 个人第四次作业——Alpha项目测试

    一.格式描述 这个作业属于哪个课程 https://edu.cnblogs.com/campus/xnsy/GeographicInformationScience/ 这个作业要求在哪里 https: ...

  8. XSS Challenges学习笔记 Stage#1~ Stage#19

    开门见山 Stage #1 http://xss-quiz.int21h.jp/?sid=2a75ff06e0147586b7ceb0fe68ee443b86a6e7b9 这一道题发现我们写入的内容直 ...

  9. Windows 64 位 mysql 5.7以上版本包解压中没有data目录和my-default.ini和my.ini文件以及服务无法启动的解决办法以及修改初始密码的方法

    下载解压mysql文件之后,中间出现了一些问题,终于解决,希望能帮助到需要的朋友. mysql官网下载地址:https://dev.mysql.com/downloads/mysql/点击打开链接 以 ...

  10. Python PID

    import time class PID: """PID Controller """ def __init__(self, P=0.2, ...