\(\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. idea环境下SpringBoot Web应用引入JSP

    1. 环境 开发环境:idea2019.3 jkd版本:1.8 springboot版本:2.6.2 2. 引入JSP的步骤 2.1 新建工程,引入依赖 这里只是解析jsp,因此只需要引入spring ...

  2. leetcode 718. 最长重复子数组

    问题描述 给两个整数数组 A 和 B ,返回两个数组中公共的.长度最长的子数组的长度. 示例: 输入: A: [1,2,3,2,1] B: [3,2,1,4,7] 输出:3 解释: 长度最长的公共子数 ...

  3. Android Sensor.TYPE_STEP_COUNTER 计步器传感器 步数统计

    注意:使用 计步器传感器 Sensor.TYPE_STEP_COUNTER 获取步数前需要手机支持该传感器 1.学习资料 1.1 SENSOR.TYPE_STEP_COUNTER 地址:开发者文档 翻 ...

  4. 【记录一个问题】笔记本ThinkPad X1-Extreme安装ubuntu 18后,更新nvidia显卡驱动后出现显示问题,无法再登录

    如题 更新的过程如下: sudo ubuntu-drivers autoinstall sudo reboot 后续准备在recovery模式中尝试删除驱动.

  5. Ajax的IE缓存问题

    Ajax之IE缓存问题 <!-- IE浏览器会对ajax的结果进行一个缓存,这样就会导致一个缓存问题 浏览器会读取缓存 而不会去使用一个新的数据 这样对一个时效性比较强的场景 ajax的缓存会影 ...

  6. Android开发 定时任务清理数据

    原文地址:Android开发 定时任务清理数据 | Stars-One的杂货小窝 公司项目,需要整定时任务,对数据进行清理,需要在每天凌晨0:00进行数据的清理,使用了Alarm和广播的方式来实现 P ...

  7. Go 面向对象之结构体

    #### Go 面向对象之结构体最近有四天没更新公众号,有一些事情耽误了,生活就是这样,总会一些事情让人措不及防; ***山浓水浅,坐看流年***1. Go 也支持面向对象编程(OOP) 但是它和传统 ...

  8. Spring中的单例模式

    Spring中的单例模式 单例模式的介绍 1.1 简介 ​ 保证整个应用中某个实例有且只有一个 1.2作用 保证一个类仅有一个实例,并且提供一个访问它的全局访问点. 单例模式的优点和缺点 单例模式的优 ...

  9. python11day

    昨日回顾 函数的参数: 实参角度:位置参数.关键字参数.混合参数 形参角度:位置参数.默认参数.仅限关键字参数.万能参数 形参角度参数顺序:位置参数,*args,默认参数,仅限关键字参数,**kwar ...

  10. Android开发-记账本-实现记账功能选择

    制作GridView适配器,实现页面数据的变化 制作类型存储数据库,存储的主要是图片类型,类型被选中时的图片,类型未被选中时的图片. 数据库代码如下 package com.example.Utils ...