假的,假的,都是假的。

题意是最大点独立集还要算贡献,写个网络流岂不是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. const char and static const char

    部分内容摘自:https://blog.csdn.net/ranhui_xia/article/details/32696669 The version with const char * will ...

  2. Visual Studio 2013安装包

    点击下载

  3. 项目启动报错: No naming context bound to this class loader

    发步项目到本地tomcat,启动后,一直包错:  警告: Failed to retrieve JNDI naming context for container [StandardEngine[Ca ...

  4. lubuntu 使用USB摄像头

    http://liangbing8612.blog.51cto.com/2633208/598762 Most of the camera driver has integrated in the k ...

  5. javascript中判断变量是否存在的正确方式

    在Javascript中,我们通常判断一个变量是否存在(即不为null或者undefined),往往是这样判断的 if(tomy){ console.log(obj.name); } 这种写法在大部分 ...

  6. Dubbo 的 Helloworld

    前提条件 安装好了 ZooKeeper 作为注册中心 服务端 <?xml version="1.0" encoding="UTF-8"?> < ...

  7. Netscaler GSLB的主备数据中心解决方案

    Netscaler GSLB的主备数据中心解决方案 http://blog.51cto.com/caojin/1898182 GSLB的主.备数据中心解决方案思路: 其实这只是多数据中心的一个特例而已 ...

  8. HDU 6194 string string string(后缀数组+RMQ)

    string string string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  9. 【题解】NOI2009管道取珠

    又是艰难想题的一晚,又是做不出来的一题 (:д:) 好想哭啊…… 这题最关键的一点还是提供一种全新的想法.看到平方和这种东西,真的不好dp.然而我一直陷在化式子的泥潭中出不来.平方能够联想到什么?原本 ...

  10. [Leetcode] Convert sorted list to binary search tree 将排好的链表转成二叉搜索树

    ---恢复内容开始--- Given a singly linked list where elements are sorted in ascending order, convert it to ...