hdu 6562 Lovers (线段树)
大意: 有$n$个数字串, 初始为空, 两种操作(1)把$[l,r]$范围的所有数字串首位添加数位$d$ (2)询问$[l,r]$区间和
假设添加的数为$L$, $L$位数为$H$, $L$翻转后乘上$10^H$为$R$
假设$x$的位数为$h$, 那么$x$就会变为$R10^h+x10^H+L$
区间和$s_1$变为$R\sum 10^h+s_110^H+L(r-l+1)$.
再维护一个$s_2=\sum 10^h$即可
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head const int N = 1e5+10;
struct _ {
int s1,s2,pre,suf,h;
void upd(int H, int L, int R, int len) {
s1 = ((ll)s1*H+(ll)len*L+(ll)s2*R)%P;
s2 = (ll)s2*H%P*H%P;
pre = ((ll)pre*H+L)%P;
suf = ((ll)suf*H+(ll)R*h%P*h)%P;
h = (ll)h*H%P;
}
_ operator + (const _ &rhs) const {
_ ret;
ret.s1 = (s1+rhs.s1)%P;
ret.s2 = (s2+rhs.s2)%P;
ret.pre = ret.suf = 0;
ret.h = 1;
return ret;
}
} tr[N<<2];
void pd(int o, int l, int r) {
if (tr[o].h!=1) {
tr[lc].upd(tr[o].h,tr[o].pre,tr[o].suf,mid-l+1);
tr[rc].upd(tr[o].h,tr[o].pre,tr[o].suf,r-mid);
tr[o].h=1,tr[o].pre=tr[o].suf=0;
}
} void add(int o, int l, int r, int ql, int qr, int d) {
if (ql<=l&&r<=qr) return tr[o].upd(10,d,d*10,r-l+1);
pd(o,l,r);
if (mid>=ql) add(ls,ql,qr,d);
if (mid<qr) add(rs,ql,qr,d);
tr[o] = tr[lc]+tr[rc];
}
int query(int o, int l, int r, int ql, int qr) {
if (ql<=l&&r<=qr) return tr[o].s1;
pd(o,l,r);
int ans = 0;
if (mid>=ql) ans+=query(ls,ql,qr);
if (mid<qr) ans+=query(rs,ql,qr);
return ans%P;
} void build(int o, int l, int r) {
if (l==r) tr[o] = {0,1,0,0,1};
else build(ls),build(rs),tr[o]=tr[lc]+tr[rc];
}
int n, m; void work() {
scanf("%d%d",&n,&m);
build(1,1,n);
while (m--) {
char s[10];
int l,d,r;
scanf("%s%d%d",s,&l,&r);
if (s[0]=='w') scanf("%d",&d),add(1,1,n,l,r,d);
else printf("%d\n",query(1,1,n,l,r));
}
} int main() {
int t=rd();
REP(i,1,t) {
printf("Case %d:\n",i);
work();
}
}
hdu 6562 Lovers (线段树)的更多相关文章
- hdu 4031 attack 线段树区间更新
Attack Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)Total Subm ...
- hdu 4288 离线线段树+间隔求和
Coder Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- hdu 3016 dp+线段树
Man Down Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- HDU 6562 lovers 2018CCPC吉林H(线段树)
题意: 初始n个空串,m个操作: 1.给[l,r]的所有字符串头尾加一个‘d’,将原字符串x变为dxd 2.求[l,r]所有字符串代表的数字之和mod 1e9+7 思路: 据说是硬核线段树.. 对于线 ...
- HDU 5877 dfs+ 线段树(或+树状树组)
1.HDU 5877 Weak Pair 2.总结:有多种做法,这里写了dfs+线段树(或+树状树组),还可用主席树或平衡树,但还不会这两个 3.思路:利用dfs遍历子节点,同时对于每个子节点au, ...
- HDU 3308 LCIS (线段树区间合并)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3308 题目很好懂,就是单点更新,然后求区间的最长上升子序列. 线段树区间合并问题,注意合并的条件是a[ ...
- HDU 2795 Billboard (线段树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795 题目大意:有一块h*w的矩形广告板,要往上面贴广告; 然后给n个1*wi的广告,要求把广告贴 ...
- hdu 5480 Conturbatio 线段树 单点更新,区间查询最小值
Conturbatio Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=54 ...
- hdu 1828 Picture(线段树 || 普通hash标记)
http://acm.hdu.edu.cn/showproblem.php?pid=1828 Picture Time Limit: 6000/2000 MS (Java/Others) Mem ...
随机推荐
- 小D课堂 - 零基础入门SpringBoot2.X到实战_第9节 SpringBoot2.x整合Redis实战_40、Redis工具类封装讲解和实战
笔记 4.Redis工具类封装讲解和实战 简介:高效开发方式 Redis工具类封装讲解和实战 1.常用客户端 https://redisdesktop.com/download ...
- Remix 搭建与简单使用,并支持外部访问
Remix 搭建与简单使用,并支持外部访问 转 https://blog.csdn.net/linshenyuan1213/article/details/83444911 remix是基于浏览器的在 ...
- Leetcode: Campus Bikes II
On a campus represented as a 2D grid, there are N workers and M bikes, with N <= M. Each worker a ...
- [原]error LNK2005:"XXX已经在 XXX.obj 中定义 使用 /FORCE(强制文件输出)暴力解决
参考:https://blog.csdn.net/LG1259156776/article/details/80828720 https://blog.csdn.net/cai18381306175/ ...
- Dart 自增++自减--和循环语句
void main(){ /* ++ -- 表示自增 自减 1 在赋值运算里面 如果++ -- 写在前面 这时候先运算 再赋值,如果++ --写在后面 先赋值后运行运算 var a=10; var b ...
- VS2015 dlib编译 x64 Debug .lib生成
VS2015 dlib编译 x64 Debug >------ 已启动生成: 项目: ZERO_CHECK, 配置: Debug x64 ------ > Checking Build S ...
- OpenBLAS编译 Release x64 Win10 vs2015
>------ 已启动生成: 项目: ZERO_CHECK, 配置: Release x64 ------ > Checking Build System > CMake does ...
- 全面系统Python3入门+进阶-1-2 Python的特性
结束
- mat文件读写
一起来学演化计算-mat文件读写 觉得有用的话,欢迎一起讨论相互学习~Follow Me Matlab读取和保存mat文件数据 在matlab命令行中输入save 变量名a,将a变量保存在新生成的a. ...
- INTEL 7代CPU I5 7500 集显HD630 WIN7 64位
HD630 在WIN7 下的硬件ID (在设备管理器 - 显卡 - 属性 中查看): PCI\VEN_8086&DEV_5912&SUBSYS_D0001458&REV_04 ...