CodeForces Round #179 (295A) - Greg and Array 一个线段树做两次用
线段树的区间更新与区间求和...一颗这样的线段树用两次...
先扫描1~k...用线段树统计出每个操作执行的次数...
那么每个操作就变成了 op. l , op.r , op.c= times* op.c
清空线段树..将初始的a1,a2~~an放入..用每个操作来更新值~~
Program:
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<set>
#include <ctime>
#include<queue>
#include<algorithm>
#include<cmath>
#define oo 1000000007
#define ll long long
#define pi acos(-1.0)
#define MAXN 100005
using namespace std;
struct node
{
ll l,r,c;
}op[MAXN];
ll sum[MAXN<<2],col[MAXN<<2],a[MAXN];
int n,m,k;
void PushDown(ll len,int now)
{
if (!col[now]) return;
col[now<<1]+=col[now];
col[(now<<1)|1]+=col[now];
sum[now<<1]+=col[now]*(len-(len>>1));
sum[(now<<1)|1]+=col[now]*(len>>1);
col[now]=0;
return;
}
void update(int L,int R,ll c,int l,int r,int now)
{
if (L<=l && R>=r)
{
sum[now]+=(r-l+1)*c;
col[now]+=c;
return;
}
int mid=(l+r)/2;
PushDown(r-l+1,now);
if (L<=mid) update(L,R,c,l,mid,now<<1);
if (R>mid) update(L,R,c,mid+1,r,(now<<1)|1);
sum[now]=sum[now<<1]+sum[(now<<1)|1];
return;
}
ll query(int L,int R,int l,int r,int now)
{
ll ans=0;
if (L<=l && R>=r) return sum[now];
int mid=(l+r)/2;
PushDown(r-l+1,now);
if (L<=mid) ans+=query(L,R,l,mid,now<<1);
if (R>mid) ans+=query(L,R,mid+1,r,(now<<1)|1);
return ans;
}
int main()
{
int i;
while (~scanf("%d%d%d",&n,&m,&k))
{
memset(sum,0,sizeof(sum));
memset(col,0,sizeof(col));
for (i=1;i<=n;i++) scanf("%I64d",&a[i]);
for (i=1;i<=m;i++) scanf("%I64d%I64d%I64d",&op[i].l,&op[i].r,&op[i].c);
for (i=1;i<=k;i++)
{
int x,y;
scanf("%d%d",&x,&y);
update(x,y,1,1,m,1);
}
for (i=1;i<=m;i++)
{
ll x;
x=query(i,i,1,m,1);
op[i].c*=x;
}
memset(sum,0,sizeof(sum));
memset(col,0,sizeof(col));
for (i=1;i<=n;i++) update(i,i,a[i],1,n,1);
for (i=1;i<=m;i++) update(op[i].l,op[i].r,op[i].c,1,n,1);
for (i=1;i<=n;i++) printf("%I64d ",query(i,i,1,n,1));
printf("\n");
}
return 0;
}
CodeForces Round #179 (295A) - Greg and Array 一个线段树做两次用的更多相关文章
- CodeForces Round #179 (295A) - Greg and Array
题目链接:http://codeforces.com/problemset/problem/295/A 我的做法,两次线段树 #include <cstdio> #include < ...
- Educational Codeforces Round 6 E. New Year Tree dfs+线段树
题目链接:http://codeforces.com/contest/620/problem/E E. New Year Tree time limit per test 3 seconds memo ...
- Codeforces Round #530 (Div. 2) F (树形dp+线段树)
F. Cookies 链接:http://codeforces.com/contest/1099/problem/F 题意: 给你一棵树,树上有n个节点,每个节点上有ai块饼干,在这个节点上的每块饼干 ...
- C.Fountains(Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)+线段树+RMQ)
题目链接:http://codeforces.com/contest/799/problem/C 题目: 题意: 给你n种喷泉的价格和漂亮值,这n种喷泉题目指定用钻石或现金支付(分别用D和C表示),C ...
- Codeforces Round #603 (Div. 2) E. Editor(线段树)
链接: https://codeforces.com/contest/1263/problem/E 题意: The development of a text editor is a hard pro ...
- Codeforces 671C - Ultimate Weirdness of an Array(线段树维护+找性质)
Codeforces 题目传送门 & 洛谷题目传送门 *2800 的 DS,不过还是被我自己想出来了 u1s1 这个 D1C 比某些 D1D 不知道难到什么地方去了 首先碰到这类问题我们肯定考 ...
- 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 ...
- Codeforces Round #244 (Div. 2) B. Prison Transfer 线段树rmq
B. Prison Transfer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/pro ...
- [Codeforces Round #296 div2 D] Clique Problem 【线段树+DP】
题目链接:CF - R296 - d2 - D 题目大意 一个特殊的图,一些数轴上的点,每个点有一个坐标 X,有一个权值 W,两点 (i, j) 之间有边当且仅当 |Xi - Xj| >= Wi ...
随机推荐
- Realview MDK 中不用手动开中断的原因
startup.s启动代码文件: ; Enter Supervisor Mode and set its Stack Pointer MSR CPSR_c, #Mode_SVC:OR:I_Bit:OR ...
- css案例学习之层叠样式
代码 <html> <head> <title>层叠特性</title> <style type="text/css"> ...
- 网易云课堂_程序设计入门-C语言_第三周:循环_2数字特征值
2 数字特征值(5分) 题目内容: 对数字求特征值是常用的编码算法,奇偶特征是一种简单的特征值.对于一个整数,从个位开始对每一位数字编号,个位是1号,十位是2号,以此类推.这个整数在第n位上的数字记作 ...
- chartControl 饼状图小Demo
Short Description The Pie Chart is represented by the Pie3DSeriesView object, which belongs to P ...
- Android之ActionBar学习
关于那个问题:是关于如何生成如下图所示之ActionBar效果: 其实就在官网上就有答案,自己疏忽再加上资料繁多.寻了许久,经过指点.终于找到: To enable split action bar, ...
- input type=button设置高度不管用
<input type="button" name="calRate" id="calRate" value="查询&quo ...
- LINUX下查看CPU使用率的命令[Z]
1.top 使用权限:所有使用者 使用方式:top [-] [d delay] [q] [c] [S] [s] [i] [n] [b] 说明:即时显示process的动态 d :改变显示的更新速度,或 ...
- MJExtension
MJExtension 长话短说下面我们通过一个列子来看下怎么使用 1. 先把框架拉进去你的项目 2. 首先我这次用到的json最外层是一个字典,根据数据的模型我们可以把这个归类为字典中有数组,数组中 ...
- C++ char和string的区别
'a'是char, "a"是char string,这两者都是普通的字符和字符串,和C中没什么不同 值得注意的是后者包含两个字符,末尾有一个隐身的'\0'而:string str ...
- EC读书笔记系列之6:条款11 在operator=中处理自我赋值
记住: ★确保当对象自我赋值时operator=有良好行为.有三种方法:比较“来源对象”和“目标对象”的地址.精心周到的语句顺序.以及copy-and-swap技术 ★确定任何函数若操作一个以上对象, ...