D. Nene and the Mex Operator

2024-04-14 22:52
文章标签 mex operator nene

本文主要是介绍D. Nene and the Mex Operator,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

 

 解题思路

  • 若选定一个区间\left [ l,r \right ],则可以构造成值全为r-l+1
  • 构造方如下:
  • 先将区间全变为0
  • (若区间有0且不全为0mex [l,r]两次(全变为一个值后再全变为0),若没有0则一次,若已经全为0则0次)
  • 保留r为0,依次递归构造[l,r-1],[l+1,r-1],[l+2,r-1]\cdots,每次保留左端值
  • 则构造出区间值为r-l,r-l-1,\cdots 2,1,0,再mex一次变为全r-l+1
  • 例:0 0 0 0->1 0 0 0->2 2 0 0->2 0 0 0-> 2 1 0 0->3 3 3 0->3 0 0 0->……->3 2 1 0->4 4 4 4 
  • 预处理出需要构造的区间
  • Sum[i]<Sum[j]+(i-j+1)*(i-j+1)
import java.io.*;
import java.math.BigInteger;
import java.util.*;//implements Runnable
public class Main {static long md=(long)1e9+7;static long Linf=Long.MAX_VALUE/2;static int inf=Integer.MAX_VALUE/2;static int N=200010;static int n=0;static int m=0;staticclass M{int x,y;public M(int u,int v){x=u;y=v;}}static Vector<M> stp;static long[] a;static void get(int l,int r){if(l==r){if(a[l]!=0)stp.add(new M(l,r));stp.add(new M(l,r));a[l]=1;return;}boolean zero=false;boolean ok=true;for(int i=l;i<=r;++i){if(a[i]==0)zero=true;else ok=false;}if(!ok){if(zero)stp.add(new M(l,r));stp.add(new M(l,r));for(int i=l;i<=r;++i)a[i]=0;}for(int i=l;i<r;++i)get(i,r-1);stp.add(new M(l,r));for(int i=l;i<=r;++i)a[i]=r-l+1;}static void solve() throws Exception{AReader input=new AReader();
//        String fileName="";
//		Scanner input=new Scanner(new FileReader(fileName));//        BufferedReader input = new BufferedReader(new FileReader(fileName));PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));String al="abcdefghijklmnopqrstuvwxyz";char[] ac=al.toCharArray();n=input.nextInt();a=new long[n+1];for(int i=1;i<=n;++i)a[i]=input.nextLong();long[] sum=new long[n+1];int[] len=new int[n+1];for(int i=1;i<=n;++i){sum[i]=sum[i-1]+a[i];for(int j=1;j<=i;++j){if(sum[i]<sum[i-j]+(long)j*j){len[i]=j;sum[i]=sum[i-j]+(long)j*j;}}}stp=new Vector<>();out.print(sum[n]+" ");int r=n;while(r>0){if(len[r]==0){r--;continue;}int l=r-len[r]+1;get(l,r);r=l-1;}out.println(stp.size());for(M now:stp){out.println(now.x+" "+now.y);}out.flush();out.close();}public static void main(String[] args) throws Exception{solve();}//	public static final void main(String[] args) throws Exception {
//		  new Thread(null, new Tx2(), "线程名字", 1 << 27).start();
//	}
//		@Override
//		public void run() {
//			try {
//				//原本main函数的内容
//				solve();
//
//			} catch (Exception e) {
//			}
//		}staticclass AReader{BufferedReader bf;StringTokenizer st;public AReader(){bf=new BufferedReader(new InputStreamReader(System.in));st=new StringTokenizer("");}public String nextLine() throws IOException{return bf.readLine();}public String next() throws IOException{while(!st.hasMoreTokens()){st=new StringTokenizer(bf.readLine());}return st.nextToken();}public char nextChar() throws IOException{//确定下一个token只有一个字符的时候再用return next().charAt(0);}public int nextInt() throws IOException{return Integer.parseInt(next());}public long nextLong() throws IOException{return Long.parseLong(next());}public double nextDouble() throws IOException{return Double.parseDouble(next());}public float nextFloat() throws IOException{return Float.parseFloat(next());}public byte nextByte() throws IOException{return Byte.parseByte(next());}public short nextShort() throws IOException{return Short.parseShort(next());}public BigInteger nextBigInteger() throws IOException{return new BigInteger(next());}}
}

这篇关于D. Nene and the Mex Operator的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/904240

相关文章

Flink 原理与实现:Operator Chain原理

硬刚大数据系列文章链接: 2021年从零到大数据专家的学习指南(全面升级版) 2021年从零到大数据专家面试篇之Hadoop/HDFS/Yarn篇 2021年从零到大数据专家面试篇之SparkSQL篇 2021年从零到大数据专家面试篇之消息队列篇 2021年从零到大数据专家面试篇之Spark篇 2021年从零到大数据专家面试篇之Hbase篇

Flink: 两个递归彻底搞懂operator chain

《2021年最新版大数据面试题全面开启更新》 operator chain是指将满足一定条件的operator 链在一起,放在同一个task里面执行,是Flink任务优化的一种方式,在同一个task里面的operator的数据传输变成函数调用关系,这种方式减少数据传输过程。常见的chain例如:source->map->filter,这样的任务链可以chain在一起,那么其内部是如何决定

C++ std::set<,> operator怎么用

std::set 不重复key默认less排序 STL中的关联容器: std::set template<class Key,class Compare = std::less<Key>,class Allocator = std::allocator<Key>> class set; std::set 是关联容器,含有 Key 类型对象的已排序集。 它的key就是value

Java Operator SDK

Java Operator SDK 生成项目骨架快速入门模式和最佳实践使用示例Operators实现示例OperatorQuarkusSpring Boot Operators 代表Kubernetes管理集群和非集群资源。这个Java Operator SDK (JOSDK) 旨在通过使用一个对Java开发人员来说应该感觉自然的API,使编写Kubernetes操作员变得尽可能

0基础学习Python路径(40)operator模块

operator 模块 operator 模块提供了一套与 Python 的内置运算符对应的高效率函数。 函数的种类 函数包含的种类有:对象的比较运算、逻辑运算、数学运算和序列运算 比较运算 运算函数语法小于lt(a, b)a < b小于等于le(a, b)a <= b大于gt(a, b)a > b大于等于ge(a, b)a >= b等于eq(a, b)a == b不等于ne(a, b)

matlab mex 编译C sparsenet库

这段时间,同实验室师姐用稀疏编码sparsenet做实验,在官网有标准的linux版本 window版本为一位大牛做的,但是下载下来,为dll文件,早期版本的matlab可以打开,但是谁还用那么老的… 查看了makefile文件,发现用mex编译 上网查了资料,https://blog.csdn.net/ayw_hehe/article/details/6821225 碰到使用matlab编译

疫情下开盘首日千股跌停,百万用户转战MEX

2020年刚刚开头,太多人都想重启这一年,因为这一年实属不太平。疫情肆虐,新冠肺炎成了一场骇人的瘟疫,以武汉为中心,在全国范围内肆意蔓延开来。 疫情可怕,和疫情同样可怕的,是随之而来的经济形势的低靡。形势所迫,股市大跌,餐饮关门,工厂停工,各大娱乐场所也纷纷歇业。百业萧条,这无疑使得广大百姓收入骤减,甚至一时之间没了经济来源。 正因为如此,大家纷纷把目光聚集到了可以在线上进行操作和运营的币圈世

孙鑫视频学习:“operator +=” 不明确的问题解决方法

在基于单文档应用程序的MFC程序中,在OnChar函数中使用m_strLine+=nChar时,出现了error C2593:“operator +=”不明确的错误,如下解决方法,亲测可用:   将m_strLine+=nChar改为m_strLine+=char(nChar)或m_strLine+=(char)nChar   因为:在OnChar函数的参数中,nChar是UINT类型的。

C++map容器中operator[ ]的实现原理

目录 一、operator[ ]函数介绍 二、insert函数介绍 三、operator[ ]函数实现原理 四、operator[ ]函数功能 一、operator[ ]函数介绍 mapped_type& operator[] (const key_type& k); 在map容器中存储的是一个键值对value_type,其本质是pair<const key_type,

new 和operator new

参考 1、http://blog.csdn.net/wudaijun/article/details/9273339 2、http://www.cnblogs.com/luxiaoxun/archive/2012/08/10/2631812.html new 、operator new 和 placement new <—-> new( (void*)pBuf) ClassObj(obj)