假的,假的,都是假的。

题意是最大点独立集还要算贡献,写个网络流岂不是GG?

其实这个也就是奇偶不能选而已……所以无外乎这么四种情况:

  1. 左开右闭
  2. 左闭右开
  3. 都闭
  4. 都开

线段树按照套路维护一下就好了。

#include<bits/stdc++.h>
#define N 50010
#define lson (o<<1)
#define rson (o<<1|1)
using namespace std;
typedef long long ll;
int f[N<<][],n,m;
ll ans=;
inline int read(){
int f=,x=;char ch;
do{ch=getchar();if(ch=='-')f=-;}while(ch<''||ch>'');
do{x=x*+ch-'';ch=getchar();}while(ch>=''&&ch<='');
return f*x;
}
inline int max(int a,int b,int c){return max(max(a,b),c);}
inline int max(int a,int b,int c,int d){return max(max(a,b),max(c,d));}
inline void pushup(int o){
for(int i=;i<;i++)
f[o][i]=max(f[lson][i&]+f[rson][+(i&)],f[lson][(i&)+]+f[rson][i&],f[lson][(i&)+]+f[rson][i&]);
}
void build(int o,int l,int r){
if(l==r){f[o][]=read();return;}
int mid=(l+r)>>;
build(lson,l,mid);build(rson,mid+,r);
pushup(o);
}
void change(int o,int l,int r,int q,int v){
if(l==r){f[o][]=v;return;}
int mid=(l+r)>>;
if(q<=mid)change(lson,l,mid,q,v);
else change(rson,mid+,r,q,v);
pushup(o);
}
int main(){
n=read();m=read();
build(,,n);
while(m--){
int x=read(),y=read();
change(,,n,x,y);
ans+=max(f[][],f[][],f[][],f[][]);
}
cout<<ans<<endl;
}

【bzoj4094】【洛谷3097】Optimal Milking的更多相关文章

  1. 【BZOJ4094】[Usaco2013 Dec]Optimal Milking 线段树

    [BZOJ4094][Usaco2013 Dec]Optimal Milking Description Farmer John最近购买了N(1 <= N <= 40000)台挤奶机,编号 ...

  2. [P3097] [USACO13DEC] [BZOJ4094] 最优挤奶Optimal Milking 解题报告(线段树+DP)

    题目链接:https://www.luogu.org/problemnew/show/P3097#sub 题目描述 Farmer John has recently purchased a new b ...

  3. 【洛谷P2889】Milking Time

    很容易想到以结束时间加上R从小到大排序 之后怎样呢? 我们按层考虑,f[i]表示前i个时间段嫩得到的最大价值 每次枚举其之前的状态,如果其ed<当前i的st,那么取max即可 #include& ...

  4. 洛谷P3097 - [USACO13DEC]最优挤奶Optimal Milking

    Portal Description 给出一个\(n(n\leq4\times10^4)\)个数的数列\(\{a_n\}(a_i\geq1)\).一个数列的最大贡献定义为其中若干个不相邻的数的和的最大 ...

  5. 洛谷 P3370 【模板】字符串哈希

    洛谷 P3370 [模板]字符串哈希 题目描述 如题,给定N个字符串(第i个字符串长度为Mi,字符串内包含数字.大小写字母,大小写敏感),请求出N个字符串中共有多少个不同的字符串. 友情提醒:如果真的 ...

  6. 洛谷——P1821 [USACO07FEB]银牛派对Silver Cow Party

    P1821 [USACO07FEB]银牛派对Silver Cow Party 题目描述 One cow from each of N farms (1 ≤ N ≤ 1000) conveniently ...

  7. 【洛谷】P2880 [USACO07JAN]平衡的阵容Balanced Lineup(st表)

    题目背景 题目描述: 每天,农夫 John 的N(1 <= N <= 50,000)头牛总是按同一序列排队. 有一天, John 决定让一些牛们玩一场飞盘比赛. 他准备找一群在对列中为置连 ...

  8. 洛谷 P3659 [USACO17FEB]Why Did the Cow Cross the Road I G

    //神题目(题目一开始就理解错了)... 题目描述 Why did the cow cross the road? Well, one reason is that Farmer John's far ...

  9. [洛谷P3460] [POI2007]TET-Tetris Attack

    洛谷题目链接:[POI2007]TET-Tetris Attack 题目描述 A puzzle called "Tetris Attack" has lately become a ...

随机推荐

  1. linux备忘录-shell脚本

    知识 shell执行方式 shell执行方式有 通过source或. 在现在的bash环境中执行脚本 变量等会保持 通过bash shell.sh或sh shell.sh 使用一个新的bash环境执行 ...

  2. 最短路径——Bellman-Ford算法

    一.相关定义 最短路径:求源点到某特定点的最短距离 特点:Bellman-Ford算法主要是针对有负权值的图,来判断该图中是否有负权回路或者存在最短路径的点 局限性:算法效率不高,不如SPFA算法 时 ...

  3. Linux SPI总线和设备驱动架构之一:系统概述

    SPI是"Serial Peripheral Interface" 的缩写,是一种四线制的同步串行通信接口,用来连接微控制器.传感器.存储设备,SPI设备分为主设备和从设备两种,用 ...

  4. WebStorm中配置ExtJS

    原文链接:http://zhidao.baidu.com/link?url=yX0wDWrL-b2P8k3JNNI38Fb6keuAgm0j9E-QBL1KfWXrZgLZ88grAOVJvat6dJ ...

  5. html前端插件 ZenCoding 更名为Emmet

    eclipse下的使用方法   http://www.educity.cn/develop/651853.html visualstudio下的使用方式 http://www.johnpapa.net ...

  6. Nginx代理实现跨域

    #user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #erro ...

  7. 【EasyNetQ】- 发布确认

    默认的AMQP发布不是事务性的,并不保证您的消息实际到达代理.AMQP确实指定了事务发布,但是使用RabbitMQ它非常慢,我们还没有通过EasyNetQ API支持它.对于高性能保证交付,建议您使用 ...

  8. 使用Kibana

    Kibana基本使用 https://www.elastic.co/guide/en/kibana/6.x/tutorial-load-dataset.html https://www.elastic ...

  9. 在C/C++函数中使用可变参数

    原文链接地址:http://blog.csdn.net/djinglan/article/details/8425768 下面介绍在C/C++里面使用的可变参数函数. 先说明可变参数是什么,先回顾一下 ...

  10. BZOJ4869 [Shoi2017]相逢是问候 【扩展欧拉定理 + 线段树】

    题目链接 BZOJ4869 题解 这题调得我怀疑人生,,结果就是因为某些地方\(sb\)地忘了取模 前置题目:BZOJ3884 扩展欧拉定理: \[c^a \equiv c^{a \mod \varp ...