线段树的区间更新与区间求和...一颗这样的线段树用两次...

先扫描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 一个线段树做两次用的更多相关文章

  1. CodeForces Round #179 (295A) - Greg and Array

    题目链接:http://codeforces.com/problemset/problem/295/A 我的做法,两次线段树 #include <cstdio> #include < ...

  2. 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 ...

  3. Codeforces Round #530 (Div. 2) F (树形dp+线段树)

    F. Cookies 链接:http://codeforces.com/contest/1099/problem/F 题意: 给你一棵树,树上有n个节点,每个节点上有ai块饼干,在这个节点上的每块饼干 ...

  4. 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 ...

  5. Codeforces Round #603 (Div. 2) E. Editor(线段树)

    链接: https://codeforces.com/contest/1263/problem/E 题意: The development of a text editor is a hard pro ...

  6. Codeforces 671C - Ultimate Weirdness of an Array(线段树维护+找性质)

    Codeforces 题目传送门 & 洛谷题目传送门 *2800 的 DS,不过还是被我自己想出来了 u1s1 这个 D1C 比某些 D1D 不知道难到什么地方去了 首先碰到这类问题我们肯定考 ...

  7. 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 ...

  8. 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 ...

  9. [Codeforces Round #296 div2 D] Clique Problem 【线段树+DP】

    题目链接:CF - R296 - d2 - D 题目大意 一个特殊的图,一些数轴上的点,每个点有一个坐标 X,有一个权值 W,两点 (i, j) 之间有边当且仅当 |Xi - Xj| >= Wi ...

随机推荐

  1. Epipe

    http://www.cnblogs.com/carekee/articles/2904603.html http://blog.chinaunix.net/uid-10716167-id-30805 ...

  2. WPF学习:绑定

    原文 http://www.cnblogs.com/SouthAurora/archive/2010/06/30/1768464.html 一.绑定到元素对象 1.元素和元素(XAML.代码) 1.1 ...

  3. Buffer Cache(缓冲区缓存)篇:keep缓冲区池(保留池)

    Buffer  Cache可以有三个池 默认缓冲区池 keep缓冲区池 recycling缓冲区池 --保留池和回收池可以独立于sga中的其他缓存分配内存.创建表的时候可以在storage子句中使用b ...

  4. poj3100---求根问题

    题意:a的n方=b,a这个整数与b开n方的值相近,分别向上取整和向下取整,同时n方,b一定介于这两个整数之间,然后比较这两个数与b的距离,取最近的 收获:c++的cei和floor函数在c中的向上取整 ...

  5. Neutron数据库同步错误 NotImplementedError: No support for ALTER of constraints in SQLite dialect

    错误信息 root@controller:~# su -s /bin/sh -c "neutron-db-manage --config-file /etc/neutron/neutron. ...

  6. poj3267--The Cow Lexicon(dp:字符串组合)

    The Cow Lexicon Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8211   Accepted: 3864 D ...

  7. split 函数自己实现

    要求自己实现split函数 def mySplit(str,delimiter): result = [] start = 0 pos = str.find(delimiter, start) whi ...

  8. getElementByID、getElementsByName、getElementsByTagName实例详解

    getElementByID.getElementsByName.getElementsByTagName实例详解 本文通过实例,详细介绍了getElementByID.getElementsByNa ...

  9. OpenGL绘制环形渐变

    开始看计算机图形学和OpenGL,挺有意思就自己随便写了一些效果. 以中间点坐标为圆心,计算每一点和圆心距离,根据距离算出一个RGB值,于是整体便呈现环形分布. 代码如下: #include < ...

  10. 获取IP地址(简单实现)

    #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/socket ...