当前位置: 首页 > news >正文

CF2157C Meximum Array 2

限制分开讨论。

首先对于一个位置,如果两个地方的限制都有,那么填 \(k + 1\),因为此时不能填 \(< k\) 的数,也不能填 \(k\),因此填 \(k + 1\)

如果什么限制都没有,那当然是填什么无所谓。

重要的就是只有两个限制的其中一个该怎么办。

如果只有 \(\min\) 的限制,那很好办,直接赋值成 \(k\) 就好了。

如果只有 \(mex\) 的限制,并不好办,因为你不确定你是填上一个数 \(+ 1\) 还是填 \(0\),我们发现此时找到上一个只有 \(mex\) 的位置,如果中间没有连着的限制,那么证明要从头再来,就填 \(0\),否则就填上个数 \(+1\) 的循环位移。

code:

#include <bits/stdc++.h>using namespace std;#define int long long
#define fir first
#define sec second
#define mkp make_pair 
#define pb push_back
#define lep( i, l, r ) for ( int i = ( l ); i <= ( r ); ++ i )
#define rep( i, r, l ) for ( int i = ( r ); i >= ( l ); -- i )typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair < int, int > pii;namespace IO{const int SIZE=1<<21;static char ibuf[SIZE],obuf[SIZE],*iS,*iT,*oS=obuf,*oT=oS+SIZE-1;int qr;char qu[55],c;bool f;#define getchar() (IO::iS==IO::iT?(IO::iT=(IO::iS=IO::ibuf)+fread(IO::ibuf,1,IO::SIZE,stdin),(IO::iS==IO::iT?EOF:*IO::iS++)):*IO::iS++)#define putchar(x) *IO::oS++=x,IO::oS==IO::oT?flush():0#define flush() fwrite(IO::obuf,1,IO::oS-IO::obuf,stdout),IO::oS=IO::obuf#define puts(x) IO::Puts(x)template<typename T>inline void read(T&x){for(f=1,c=getchar();c<48||c>57;c=getchar())f^=c=='-';for(x=0;c<=57&&c>=48;c=getchar()) x=(x<<1)+(x<<3)+(c&15); x=f?x:-x;}template<typename T>inline void write(T x){if(!x) putchar(48); if(x<0) putchar('-'),x=-x;while(x) qu[++qr]=x%10^48,x/=10;while(qr) putchar(qu[qr--]);}inline void Puts(const char*s){for(int i=0;s[i];i++)putchar(s[i]);putchar('\n');}struct Flusher_{~Flusher_(){flush();}}io_flusher_;
}
using IO::read;
using IO::write;template < class type > inline void chkmin ( type &x, type y ) { x = ( x <= y ? x : y ); }
template < class type > inline void chkmax ( type &x, type y ) { x = ( x >= y ? x : y ); }const int N = 105;int t, n, k, q;
int a[N], b[N], ans[N];void Solve () {cin >> t;while ( t -- ) {cin >> n >> k >> q;for ( int i = 1; i <= q; i ++ ) {int op, l, r;cin >> op >> l >> r;if ( op == 1 ) {for ( int j = l; j <= r; j ++ ) {a[j] = 1;}}else {for ( int j = l; j <= r; j ++ ) {b[j] = 1;}}}for ( int i = 1; i <= n; i ++ ) {if ( a[i] && b[i] ) {ans[i] = k + 1;}else if ( a[i] ) {ans[i] = k;}else if ( b[i] ) {int lst = -1, flag = 1;for ( int j = i - 1; j >= 1; j -- ) {flag &= b[j];if ( !a[j] && b[j] ) {lst = j;break;}}if ( lst == -1 || flag ) {ans[i] = ( ans[lst] + 1 ) % k;}else {ans[i] = 0;}}else {ans[i] = 0;}}for ( int i = 1; i <= n; i ++ ) {cout << ans[i] << " ";}cout << '\n';}
}signed main () {
#ifdef judgefreopen ( "Code.in", "r", stdin );freopen ( "Code.out", "w", stdout );freopen ( "Code.err", "w", stderr );
#endifSolve ();return 0;
}
http://www.jsqmd.com/news/53236/

相关文章:

  • 如何在实际项目中选择使用Java NIO框架还是传统IO框架?
  • AT_fps_24_b 整数の組
  • 详细介绍:【数据结构初阶】单链表
  • 第五十篇
  • 每日随笔
  • 2025年日语自学软件推荐:最适合零基础与进阶者的优质口碑选择
  • ABC386 VP总结
  • tarjan 强连通分量、缩点、点双、割点、割边(桥)
  • 我踩坑后总结:企业微信客服API接入客服系统,90%的人都搞错了!
  • 香橙派上进行MQTT数据存储客户端开发(一)基本环境配置
  • GEO 优化价格大比拼,哪家最便宜?三大高性价比机构推荐
  • 2025年AI学习机哪个品牌好?热门品牌功能与效果全解析
  • 2025年知名的长租公寓有哪些:权威榜单与精选解析
  • 编程中的枚举法与数学上的穷举法有何区别?
  • 如百钱百鸡问题,枚举法和穷举法有何不同
  • 根本魔法语言数组 (一) (C语言)
  • 《程序员修炼之道:从小工到专家》阅读笔记5
  • Spring Cloud工程中使用Nacos配置中心的2种方式
  • 人工智能之数据分析 Matplotlib:第三章 基本属性
  • 那为什么go 就能用同步的写法,而且不用协程的情况下,实现异步编程,而且还不阻塞os线程
  • URL地址转base64
  • 2025年租房去哪里找房源:独家榜单与深度解析
  • C# 图片加载引发的内存溢出异常
  • 实用指南:LV.5 文件IO
  • CSS视图过渡入门指南:让多页面应用拥有丝滑动画
  • 《ROS1学习笔记8——自定义服务素材》
  • 实用指南:逻辑回归(Logistic Regression)
  • CTIP 与 3D-IC 堆栈热行为仿真实践
  • Mac 安装 4K Video Downloader v5.0.0.5303-1.dmg 方法(附安装包)
  • 浮点数定点表示(Q格式)