\(\mathcal{Description}\)

  Link.

  给定 \(n\) 个函数,第 \(i\) 个有 \(f_i(x)=a_ix^3+b_ix^2+cx_i+d~(x\in[l_i,r_i]\cap\mathbb Z)\),还有 \(m\) 条形如 \(x_u\le x_v+d\) 的限制,请最大化 \(\sum_{i=1}^nf_i(x_i)\) 或声明无解。

  \(n,|l_i|,|r_i|\le 100\)。

\(\mathcal{Solution}\)

  很久没遇到了,压根儿没往网络流方面想 qwq。

  对于每个 \(f_i\),拉一条代表 \(f_i(l_i..r_i)\) 的链,边权就是某个 \(f\) 的值的相反数;限制条件方便转化为最小割,之后直接跑最小割即可。

  \(\mathcal O(\operatorname{Dinic}(\sum(r-l),m\sum(r-l)))\)。

\(\mathcal{Code}\)

/*~Rainybunny~*/

#include <queue>
#include <cstdio> #define rep( i, l, r ) for ( int i = l, rep##i = r; i <= rep##i; ++i )
#define per( i, r, l ) for ( int i = r, per##i = l; i >= per##i; --i ) #define int long long inline int imin( const int a, const int b ) { return a < b ? a : b; } const int MAXN = 100, IINF = 1ll << 50, BASE = 7e6;
int n, m, lid[MAXN + 5]; struct Function {
int a, b, c, d, l, r;
inline void read() {
scanf( "%lld %lld %lld %lld %lld %lld" , &a, &b, &c, &d, &l, &r );
}
inline int operator () ( const int x ) const {
return d + x * ( c + x * ( b + x * a ) );
}
} fc[MAXN + 5]; struct FlowGraph {
static const int MAXND = 2e4 + 10, MAXEG = 2e5;
int ecnt, bound, S, T, head[MAXND];
struct Edge { int to, flw, nxt; } graph[MAXEG * 2];
int ds[MAXND], curh[MAXND]; FlowGraph(): ecnt( 1 ) {} inline void clear() {
ecnt = 1;
rep ( i, 0, bound ) head[i] = 0;
} inline void operator () ( const int s, const int t, const int f ) {
graph[++ecnt] = { t, f, head[s] }, head[s] = ecnt;
graph[++ecnt] = { s, 0, head[t] }, head[t] = ecnt;
} inline bool bfs() {
static std::queue<int> que;
rep ( i, 0, bound ) ds[i] = IINF;
que.push( S ), ds[S] = 0;
while ( !que.empty() ) {
int u = que.front(); que.pop();
for ( int i = head[u], v; i; i = graph[i].nxt ) {
if ( graph[i].flw && ds[u] + 1 < ds[v = graph[i].to] ) {
ds[v] = ds[u] + 1, que.push( v );
}
}
}
return ds[T] != IINF;
} inline int dfs( const int u, int iflw ) {
if ( u == T ) return iflw;
int oflw = 0;
for ( int& i = curh[u], v; i; i = graph[i].nxt ) {
if ( graph[i].flw && ds[u] + 1 == ds[v = graph[i].to] ) {
int tmp = dfs( v, imin( iflw - oflw, graph[i].flw ) );
oflw += tmp, graph[i].flw -= tmp, graph[i ^ 1].flw += tmp;
if ( iflw == oflw ) break;
}
}
if ( !oflw ) ds[u] = IINF;
return oflw;
} inline int calc( const int s, const int t ) {
int ret = 0; S = s, T = t;
while ( bfs() ) {
rep ( i, 0, bound ) curh[i] = head[i];
ret += dfs( S, IINF );
}
return ret;
}
} G; signed main() {
freopen( "sleep.in", "r", stdin );
freopen( "sleep.out", "w", stdout ); int Q; scanf( "%lld", &Q );
while ( Q-- ) {
scanf( "%lld %lld", &n, &m ), G.clear();
int S = 0, T = 1, node = 1;
rep ( i, 1, n ) {
fc[i].read();
G( S, lid[i] = ++node, IINF );
rep ( j, fc[i].l, fc[i].r ) {
G( node, node + 1, BASE - fc[i]( j ) ), ++node;
}
G( node, T, IINF );
}
rep ( i, 1, m ) {
int u, v, d; scanf( "%lld %lld %lld", &u, &v, &d );
rep ( x, fc[u].l, fc[u].r ) {
if ( fc[v].l <= x - d && x - d <= fc[v].r ) {
G( lid[u] + x - fc[u].l, lid[v] + x - d - fc[v].l, IINF );
} else if ( x - d > fc[v].r ) {
G( lid[u] + x - fc[u].l, T, IINF );
}
}
}
G.bound = node;
int ans = -G.calc( S, T );
if ( ans <= -IINF ) puts( "mei ji ge" );
else printf( "%lld\n", ans + n * BASE );
}
return 0;
}

Solution -「多校联训」数学考试的更多相关文章

  1. Solution -「多校联训」排水系统

    \(\mathcal{Description}\)   Link.   在 NOIP 2020 A 的基础上,每条边赋权值 \(a_i\),随机恰好一条边断掉,第 \(i\) 条段的概率正比于 \(a ...

  2. Solution -「多校联训」I Love Random

    \(\mathcal{Description}\)   给定排列 \(\{p_n\}\),可以在其上进行若干次操作,每次选取 \([l,r]\),把其中所有元素变为原区间最小值,求能够得到的所有不同序 ...

  3. Solution -「多校联训」签到题

    \(\mathcal{Description}\)   Link.   给定二分图 \(G=(X\cup Y,E)\),求对于边的一个染色 \(f:E\rightarrow\{1,2,\dots,c\ ...

  4. Solution -「多校联训」朝鲜时蔬

    \(\mathcal{Description}\)   Link.   破案了,朝鲜时蔬 = 超现实树!(指写得像那什么一样的题面.   对于整数集 \(X\),定义其 好子集 为满足 \(Y\sub ...

  5. Solution -「多校联训」消失的运算符

    \(\mathcal{Description}\)   Link.   给定长度为 \(n\) 的合法表达式序列 \(s\),其中数字仅有一位正数,运算符仅有 - 作为占位.求将其中恰好 \(k\) ...

  6. Solution -「多校联训」假人

    \(\mathcal{Description}\)   Link.   一种物品有 长度 和 权值 两种属性,现给定 \(n\) 组物品,第 \(i\) 组有 \(k_i\) 个,分别为 \((1,a ...

  7. Solution -「多校联训」古老的序列问题

    \(\mathcal{Description}\)   Link.   给定序列 \(\{a_n\}\),和 \(q\) 次形如 \([L,R]\) 的询问,每次回答 \[\sum_{[l,r]\su ...

  8. Solution -「多校联训」Sample

    \(\mathcal{Description}\)   Link   (稍作简化:)对于变量 \(p_{1..n}\),满足 \(p_i\in[0,1],~\sum p_i=1\) 时,求 \(\ma ...

  9. Solution -「多校联训」光影交错

    \(\mathcal{Description}\)   Link.   一个游戏包含若干次卡牌抽取,每次以 \(p_l\) 的概率得到 \(+1\),\(p_d\) 的概率得到 \(-1\),否则得到 ...

随机推荐

  1. 苹果系统 的 qq浏览器 和 qq内置浏览器 无法使用 websocket 的 妥协方案

    没错,就是用不了,js脚本不执行,更别说服务器运行 onopen函数了!!! 怎么办...搞了一天,仍然找不到连接的方法!!! 幸运的是仅仅苹果系统 的无法使用 ,安卓的却可以,奇了怪了 哈皮 ,那我 ...

  2. selenium实现并发

    for循环和多线程 + selenium 实例一 for循环 # -*- coding: utf-8 -*- """ Datetime: 2019/6/22 Author ...

  3. LINUX学习--nginx服务器的安装

    一.安装环境 操作系统CentOS6.8 关闭SeLinux和iptables防火墙 二.网络yum源 将下面的软件下载到  /etc/yum.repos.d/   的目录下 官方基础:http:// ...

  4. FastDFSJava客户端使用

    1.1.java客户端 余庆先生提供了一个Java客户端,但是作为一个C程序员,写的java代码可想而知.而且已经很久不维护了. 这里推荐一个开源的FastDFS客户端,支持最新的SpringBoot ...

  5. go包管理速通,一篇文章就够了,再也不用担心因为不会导包被辞退

    前言 最近在看一些go语言相关的书,发现了一个有意思的事情:其中一本书最新印刷的版本是2017年3月,而golang包管理的后起之秀go module伴随go1.11于2018年8月诞生--因此,书里 ...

  6. Android函数抽取壳的实现

    0x0 前言 函数抽取壳这个词不知道从哪起源的,但我理解的函数抽取壳是那种将dex文件中的函数代码给nop,然后在运行时再把字节码给填回dex的这么一种壳. 函数抽取前: 函数抽取后: 很早之前就想写 ...

  7. 基于Appium的APP自动化测试基础--美团APP的实例

    转:https://blog.csdn.net/Tigerdong1/article/details/80159156 前段时间用一种流行语言,一个主流工具,一个实用框架,写了一个美团app自动化测试 ...

  8. leetcode 264. 丑数 II 及 313. 超级丑数

    264. 丑数 II 题目描述 编写一个程序,找出第 n 个丑数. 丑数就是只包含质因数 2, 3, 5 的正整数. 示例: 输入: n = 10 输出: 12 解释: 1, 2, 3, 4, 5, ...

  9. spring拦截机制中Filter(过滤器)、interceptor(拦截器)和Aspect(切面)的使用及区别

    Spring中的拦截机制,如果出现异常的话,异常的顺序是从里面到外面一步一步的进行处理,如果到了最外层都没有进行处理的话,就会由tomcat容器抛出异常. 1.过滤器:Filter :可以获得Http ...

  10. 一段关于java NIO server端接受客户端socket连接;演示了关于channel,selector等组件的整合使用

    public class ReactorDemo { public static void main(String[] args) throws IOException { ServerSocketC ...