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 ...
随机推荐
- 500多条Linux信息
http://www.cnblogs.com/zgqjymx/myposts.html?page=77 http://www.cnblogs.com/zgqjymx/tag/%E5%8E%9F%E5% ...
- mysql 插入前 锁表问题
$dbh = DBI->connect("dbi:mysql:database=$db_name;host=$ip;port=3306",$user,$passwd,{ Ra ...
- Recover a file when you use git reset head by mistake.
$ git init Initialized empty Git repository in .git/ $ echo "testing reset" > file1 $ g ...
- Android UI SurfaceView的使用-绘制组合图型,并使其移动
绘制容器类: //图形绘制容器 public class Contanier { private List<Contanier> list; private float x=0,y=0; ...
- .CN根域名被攻击至瘫痪,谁之过?【转】
2013年8月25日凌晨,.CN域名凌晨出现大范围解析故障,经分析.CN的根域授权DNS全线故障,导致大面积.CN域名无法解析.事故造成大量以.cn和.com.cn结尾的域名无法访问.直到当日凌晨4点 ...
- SQL Server:SQL Like 通配符特殊用法:Escape 【转】
SQL中escape的主要用途 1.使用 ESCAPE 关键字定义转义符.在模式中,当转义符置于通配符之前时,该通配符就解释为普通字符.例如,要搜索在任意位置包含字符串 5% 的字符串 ...
- C#获取单个字符的拼音声母
public class ConvertToPinYing { /// <summary> /// 汉字转拼音缩写 /// < ...
- android handler机制和Timer采用
Timer主要用于创建一个任务来定期运行. 创建继承Task该任务等级.即任务每次跑. private class MyTask extends TimerTask { @Override publi ...
- 根据自己的需要适度使用Web开发框架
软件系统发展到今天已经很复杂了,特别是服务器端软件,涉及到的知识,内容,问题太多.Web开发框架能够帮我们大大减少工作量,但是我们应该如何正确看待Web开发框架,并且如何去使用他们呢? 对框架的依赖 ...
- 第四课 Grid Control实验 GC Agent安装(第一台机器部署) 及卸载
3.GC Agent安装(第一台机器部署) 安装Agent 拷贝agent,现在ocm2机器上查找agent.linux 查找文件的方法: find ./ -name agent*linux 把ag ...