/*
lazy思想的运用,因为查询多种,如果全记录就太繁了,lazy就是如果该区间的每一个叶子的状态都相同就不用深入下去该值,只要暂时标记下,查询的时候也不用下去,直接计算; */
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAX_N 100005
#define mod 10007
#define ll long long
using namespace std;
struct tree
{
ll l,r,la[];
ll same,s;//s表示该区间的值都是s;
}tr[MAX_N*];
ll ans=;
void build(int rt,int l,int r)
{
tr[rt].l=l;
tr[rt].r=r;
tr[rt].same=;
tr[rt].s=;
memset(tr[rt].la,,sizeof(tr[rt].la));
tr[rt].la[]=;
if(l==r)
return ;
int mid=(l+r)/;
build(rt<<,l,mid);
build(rt<<|,mid+,r);
}
void Pushdown(int rt)
{
if(tr[rt].same==)
{
int L=rt<<,R=rt<<|;
tr[L].la[]+=tr[rt].la[];
tr[L].la[]*=tr[rt].la[];
tr[L].la[]=tr[rt].la[];
tr[L].s=tr[R].s=tr[rt].s;
tr[R].la[]+=tr[rt].la[];
tr[R].la[]*=tr[rt].la[];
tr[R].la[]=tr[rt].la[];
tr[L].same=tr[R].same=;
tr[rt].la[]=;
tr[rt].la[]=;
tr[rt].la[]=;
tr[rt].same=;
}
return;
}
void Update(int rt,int l,int r,int x,int t)
{
if(t==)
{
if(tr[rt].l==l&&tr[rt].r==r&&tr[rt].same==)
{
tr[rt].la[]+=x;//关键;
tr[rt].la[]%=mod;
tr[rt].s=tr[rt].s+x;
return ;
}
}
else if(t==)
{
if(tr[rt].l==l&&tr[rt].r==r&&tr[rt].same==)
{
tr[rt].la[]*=x;
tr[rt].la[]%=mod;
tr[rt].s=tr[rt].s*x%mod;
return ;
}
}
else
{
if(tr[rt].l==l&&tr[rt].r==r)
{
tr[rt].la[]=x;
tr[rt].s=x;
tr[rt].same=;
return;
}
}
if(tr[rt].same==)
Pushdown(rt);
int L=rt<<,R=rt<<|;
if(l<=tr[L].r)
{
if(r<=tr[L].r)
Update(L,l,r,x,t);
else
Update(L,l,tr[L].r,x,t);
}
if(r>=tr[R].l)
{
if(l>=tr[R].l)
Update(R,l,r,x,t);
else
Update(R,tr[R].l,r,x,t);
}
}
void Query(int rt,int l,int r,int x)
{
if(tr[rt].l==l&&tr[rt].r==r&&tr[rt].same==)
{
ll n=r-l+,temp=;
for(int i=;i<=x;i++)
{
temp*=tr[rt].s%mod;
temp%=mod;
}
ans+=(temp*n%mod)%mod;
return ;
}
if(tr[rt].same==)
Pushdown(rt);
int L=rt<<,R=rt<<|;
if(l<=tr[L].r)
{
if(r<=tr[L].r)
Query(L,l,r,x);
else
Query(L,l,tr[L].r,x);
}
if(r>=tr[R].l)
{
if(l>=tr[R].l)
Query(R,l,r,x);
else
Query(R,tr[R].l,r,x);
}
}
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF&&(n||m))
{
memset(tr,,sizeof(tr));
build(,,n);
for(int i=;i<m;i++)
{
int x,y,ty,c;
scanf("%d%d%d%d",&ty,&x,&y,&c);
if(ty==)
{
ans=;
Query(,x,y,c);
cout<<ans%mod<<endl;
}
else
{
Update(,x,y,c,ty);
} }
}
return ;
}

kb-07线段树--11--区间多重该值多种查询的更多相关文章

  1. FJUT3568 中二病也要敲代码(线段树维护区间连续最值)题解

    题意:有一个环,有1~N编号,m次操作,将a位置的值改为b,问你这个环当前最小连续和多少(不能全取也不能不取) 思路:用线段树维护一个区间最值连续和.我们设出两个变量Lmin,Rmin,Mmin表示区 ...

  2. 刷题向》关于线段树的区间开根号 BZOJ3211(NORMAL+)

    这是一道关于线段树的区间开根号的裸题,没什么好讲的. 值得注意的是,因为有区间开根号的性质,所以我们每一次更改操作只能把更改区间所覆盖的所有元素全部查找,当然你直接找效率明显爆炸... 能够注意到,指 ...

  3. ZOJ 2301 Color the Ball 线段树(区间更新+离散化)

    Color the Ball Time Limit: 2 Seconds      Memory Limit: 65536 KB There are infinite balls in a line ...

  4. poj 3468:A Simple Problem with Integers(线段树,区间修改求和)

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 58269   ...

  5. zoj3686(线段树的区间更新)

    对线段树的区间更新有了初步的了解... A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a ...

  6. Codeforces Round #222 (Div. 1) D. Developing Game 线段树有效区间合并

    D. Developing Game   Pavel is going to make a game of his dream. However, he knows that he can't mak ...

  7. hiho一下20周 线段树的区间修改

    线段树的区间修改 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 对于小Ho表现出的对线段树的理解,小Hi表示挺满意的,但是满意就够了么?于是小Hi将问题改了改,又出给了 ...

  8. 2016年湖南省第十二届大学生计算机程序设计竞赛---Parenthesis(线段树求区间最值)

    原题链接 http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1809 Description Bobo has a balanced parenthes ...

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

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

随机推荐

  1. codeforce Gym 100500H ICPC Quest (简单dp)

    题意:给一个nXm的矩阵,上面有一些数字,从左上角出发,每次只能往右或者往下,把沿途的数字加起来,求到达右下角的最大值是多少. 题解:简单的一个dp,设f[i][j]为到达i行j列的最大值,f[i][ ...

  2. Problem N: 求二维数组中的鞍点【数组】

    Problem N: 求二维数组中的鞍点[数组] Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 2764  Solved: 1728[Submit][S ...

  3. android上部署tensorflow

    https://www.jianshu.com/p/ddeb0400452f 按照这个博客就可以 https://github.com/CrystalChen1017/TSFOnAndroid 这个博 ...

  4. How to restrict root user to access or modify a file and directory in Linux

    Now in this article I will show you steps to prevent or restrict access of root user to access certa ...

  5. 02_5if switch分支与循环语句

    02_5if switch分支与循环语句 1.语句 1.1条件语句-根据不同条件,执行不同语句. if if ... else if ... else if if ... else if ... el ...

  6. c++ 创建路径方法

    linux.unix平台 #include "stdio.h" #include "stdlib.h" #include <sys/types.h> ...

  7. CentOS7.2 虚拟机网卡无法启动

    在开机之后,发现网卡没有启动起来,进行了如下操作1.ifup ens33Bringing up interface ens33: Error: Connection activation failed ...

  8. MySQL中CONCAT()的用法

    MySQL中CONCAT()的用法 在日常开发过程中,特别是在书写接口的时候,经常会遇到字符串拼接的情况,比如在返回图片数据时,数据库里往往存储的是相对路径,而接口里一般是存放绝对地址,这就需要字符串 ...

  9. perl-tips-1

    .pm 应该保存 Perl Module,也就是 Perl 模块.例如 Socket.pm.pl 应该保存 Perl Library,也就是 Perl 库文件.例如 perldb.pl.plx 应该保 ...

  10. hdu 6333

    Problem Description There are n apples on a tree, numbered from 1 to n.Count the number of ways to p ...