cf 444C.
听说这是线段树的裸题??(看来我也就能搞个求和什么的了2333)
#include<bits/stdc++.h>
#define INF 0x7fffffff
#define LL long long
#define N 100005
using namespace std;
inline int ra()
{
int x=,f=; char ch=getchar();
while (ch<'' || ch>'') {if (ch=='-') f=-; ch=getchar();}
while (ch>='' && ch<='') {x=x*+ch-''; ch=getchar();}
return x*f;
}
LL s[N<<],del[N<<],mark[N<<];
void build(int k, int l, int r)
{
if (l==r)
{
mark[k]=l;
return;
}
int mid=(l+r)>>;
build(k<<,l,mid); build(k<<|,mid+,r);
}
LL query(int k, int l, int r, int x, int y)
{
if (y<l || x>r) return ;
if (x<=l && r<=y) return s[k];
int mid=l+r>>;
LL L=query(k<<,l,mid,x,y);
LL R=query(k<<|,mid+,r,x,y);
return L+R+max(,min(r,y)-max(l,x)+)*del[k];
}
void clear(int k, int l, int r, int val)
{
if (mark[k])
{
del[k]+=abs(mark[k]-val);
s[k]+=1LL*(r-l+)*abs(mark[k]-val);
mark[k]=;
}
else
{
if (l==r) return;
int mid=l+r>>;
clear(k<<,l,mid,val);
clear(k<<|,mid+,r,val);
s[k]=s[k<<]+s[k<<|]+1LL*(r-l+)*del[k];
}
}
void change(int k, int l, int r, int x, int y, int val)
{
if (y<l || x>r) return;
if (x<=l && r<=y)
{
clear(k,l,r,val);
mark[k]=val;
return;
}
int mid=l+r>>;
if (mark[k])
{
mark[k<<]=mark[k<<|]=mark[k];
mark[k]=;
}
change(k<<,l,mid,x,y,val);
change(k<<|,mid+,r,x,y,val);
s[k]=s[k<<]+s[k<<|]+1LL*(r-l+)*del[k];
}
int main()
{
int n=ra(),m=ra();
build(,,n);
while (m--)
{
int type=ra();
if (type==)
{
int x=ra(),y=ra(),v=ra();
change(,,n,x,y,v);
}
else
{
int x=ra(),y=ra();
printf("%I64d\n",query(,,n,x,y));
}
}
return ;
}
cf 444C.的更多相关文章
- CF 444C DZY Loves Physics(图论结论题)
题目链接: 传送门 DZY Loves Chemistry time limit per test1 second memory limit per test256 megabytes Des ...
- Cf 444C DZY Loves Colors(段树)
DZY loves colors, and he enjoys painting. On a colorful day, DZY gets a colorful ribbon, which consi ...
- CF数据结构练习
1. CF 438D The Child and Sequence 大意: n元素序列, m个操作: 1,询问区间和. 2,区间对m取模. 3,单点修改 维护最大值, 取模时暴力对所有>m的数取 ...
- ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'
凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- cf Round 613
A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...
- ARC下OC对象和CF对象之间的桥接(bridge)
在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...
- [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现
1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...
- CF memsql Start[c]UP 2.0 A
CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...
随机推荐
- IDEA spring mvc整合mybatis
准备工作 IDEA 2019.3.1 MySql 8.0.17 Tomcat 7.0.9 开始步骤 一.创建一个项目,添加Web支持 点击菜单:File->NEW->Project 选择左 ...
- Django 数据库访问性能优化
使用标准的数据库优化技术: 在进行Django数据库访问性能优化之前,首先应该使用标准的数据库技术对其进行优化,比如给字段加索引,通过使用 django.db.models.Field.db_inde ...
- ES6转换ES5
各大浏览器的最新版本,对 ES6 的支持可以查看kangax.github.io/es5-compat-table/es6/.随着时间的推移,支持度已经越来越高了,超过 90%的 ES6 语法特性都实 ...
- 十六 StudentManagerSystem的一些业务实现
1 删除学生的JSP实现: <%@ page language="java" contentType="text/html; charset=UTF-8" ...
- C++中的简单继承
Father.cpp: #include<iostream> using namespace std; class Father { protected: int width; int h ...
- Day 4 -E - Catenyms POJ - 2337
A catenym is a pair of words separated by a period such that the last letter of the first word is th ...
- 序列号导出到csv的实现
//导出到csv public function exportCsvByIds($ids){ header("Content-type:text/html;charset=utf-8&quo ...
- centos7下安装maven
步骤1:在home目录下解压apache-maven-3.5.0-bin.tar.gz安装包 [root@model ~]# -bin.tar.gz 步骤2:创建/maven目录并将解压后的文件夹移至 ...
- System.Reflection.ReflectionTypeLoadException
引用了一个第三方dll, 此dll经过混淆,但是未签名. 然后,主程序无法反射了, 取消主程序的签名后正常反射.
- NO1 ip-systemctl-fdisk
一.IP相关·man·man:show manual info 查看一个命令的帮助信息:man ip·ip命令: show device显示设备,device address显示地址,route ...