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 ...
随机推荐
- ApiDemos示例学习(2)——App->Activity->Animation
现在介绍一下com.example.android.app包下的Animation示例. 关键类及函数: ActivityOption overridePendingTransition() make ...
- 可爱的 Python : Python中函数式编程,第二部分
英文原文:Charming Python: Functional programming in Python, Part 2,翻译:开源中国 摘要: 本专栏继续让David对Python中的函数式编 ...
- Linux内核源代码解析——用户发送数据包的起源之sendto
本文原创为freas_1990,转载请标明出处:http://blog.csdn.net/freas_1990/article/details/10162853 Jack:我想知道用户如何把数据发送到 ...
- 怎样调通微信支付及微信发货通知接口(Js API)
怎样调通微信支付及微信发货通知接口(Js API) 微信支付提供了一个支付測试页面,微信支付正式使用须要測通支付.发货通知接口 .告警接口.维权接口.告警接口.维权接口非常easy.支付界面调通也相对 ...
- java 泛型深入之Set有用工具 各种集合泛型深入使用演示样例,匿名内部类、内部类应用于泛型探讨
java 泛型深入之Set有用工具 各种集合泛型深入使用演示样例,匿名内部类.内部类应用于泛型探讨 //Sets.java package org.rui.generics.set; import j ...
- SQL中的去重操作
if not object_id('Tempdb..#T') is null drop table #T Go Create table #T([ID] ),[Memo] nvarchar()) In ...
- 获取xml文件
<?xml version="1.0" encoding="utf-8" ?><ArrayOfSystemRool xmlns:xsi=&qu ...
- svn代码版本管理
1.0开发,做dev1.0的branch此时的目录结构svn://proj/ +trunk/ (不负担开发任务) +branches/ ...
- java.lang.NoClassDefFoundError: Could not initialize class net.sf.json.util.JSONUtils
页面报错: root: java.lang.NoClassDefFoundError: Could not initialize class net.sf.json.util.JSONUtils 出错 ...
- EBS-利用form个性化 调用报表【Z】
1.在工具中添加调用报表的功能 条件: 触发器事件:WHEN-NEW-FORM-INSTANCE 活动: 类型为:菜单 菜单项:specialn n为1..6 菜单标签:打印xx报表 2.对speci ...