赛时随便写了个做法,看standing,发现很多人的做法也是很奇特
赛后看了官方题解。。翻译下

题意:

每次可以给一个任意的后缀里的所有数 + i +i +i
执行n次。
使得逆序对最少。

思路:

tip1:

什么时候逆序对最少?
序列非递减。

解法:

处理出差分数组
d = [ a 2 − a 1 , a 3 − a 2 , . . . , a n − a n − 1 ] d = [a_2-a_1,a_3-a_2,...,a_n-a_{n-1}] d=[a2​−a1​,a3​−a2​,...,an​−an−1​]

那么什么时候序列非递减?转换为差分数组都是非负。

由 d i = a i + 1 − a i , i ∈ [ 1 , n − 1 ] d_i = a_{i+1}-a_{i} ,i\in[1,n-1] di​=ai+1​−ai​,i∈[1,n−1]
显然 d i ≥ − a i d_i \ge -a_i di​≥−ai​
那么我们可以对位置 i + 1 i+1 i+1开始的后缀 + a i +a_i +ai​.
由于每个 a i a_i ai​都是唯一的,所以可以构造出非递减序列。

最后输出的时候,注意 i = n i=n i=n时,就另 a n s [ a [ i ] ] = n ans[a[i]] = n ans[a[i]]=n即可。

AC(Java)

package com.hgs.codeforces.contest.globalround.contest23.c2;/*** @author youtsuha* @version 1.0* Create by 2022/10/16 14:13*/
import java.util.*;
import java.io.*;
public class Main {static FastScanner cin;static PrintWriter cout;private static void init()throws IOException {cin = new FastScanner(System.in);cout = new PrintWriter(System.out);}private static void close(){cout.close();}private static void sol()throws IOException {int n = cin.nextInt();int a[] = new int[n];for(int i = 0; i < n; i ++ ) {int p = cin.nextInt();p--;a[p] = (i + 1) + 1;}for(int i = 0; i < n; i ++ ) cout.print(Math.min(a[i],n) + " ");cout.println();}public static void main(String[] args) throws IOException {init();int tt = cin.nextInt();while(tt -- > 0)sol();close();}
}
class FastScanner {BufferedReader br;StringTokenizer st = new StringTokenizer("");public FastScanner(InputStream s) {br = new BufferedReader(new InputStreamReader(s));}public FastScanner(String s) throws FileNotFoundException {br = new BufferedReader(new FileReader(new File(s)));}public String next() throws IOException {while (!st.hasMoreTokens()){try {st = new StringTokenizer(br.readLine());} catch (IOException e) { e.printStackTrace(); }}return st.nextToken();}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());}
}

Codeforces Global Round 23 C. Permutation Operations相关推荐

  1. 【Codeforces Global Round 23】B. Rebellion

    Codeforces Global Round 23中B. Rebellion Codeforces比赛记录 文章目录 题目链接: 一.B. Rebellion 题目意思: 上思路: 总结 B. Re ...

  2. codeforces global round 23

    constest :codeforces global round 23 contest time:2022.10.16 contest grade: 2800 contest rating chan ...

  3. Codeforces Global Round 23 E CF1746E Joking (Hard Version)

    题意 互动题 你需要猜一个数 范围e5 询问在不在数集中 限最多52次 猜测是不是某个数 最多两次 其中询问反馈你的答案未必是对的,只保证2次连续询问至少有一次是对的 猜测都是对的 思路 对同一个数集 ...

  4. Codeforces Global Round 1 晕阙记

    Codeforces Global Round 1 晕阙记 我做这场比赛的时候晕得要死.做这三道题做太久了,rating涨不起来啊! A 如果愿意的话你可以看做是膜2意义下的运算,写快速幂等各种膜运算 ...

  5. Codeforces Global Round 3

    Codeforces Global Round 3 A. Another One Bites The Dust 有若干个a,有若干个b,有若干个ab.你现在要把这些串拼成一个串,使得任意两个相邻的位置 ...

  6. Codeforces Global Round 14 F. Phoenix and Earthquake 思维 + 并查集

    传送门 文章目录 题意: 思路: 题意: 给你nnn个点,mmm条边,限制xxx,每个点都有沥青aia_iai​,定义合并两个点即两点之间有边且au+av≥xa_u+a_v\ge xau​+av​≥x ...

  7. Codeforces Global Round 1

    Codeforces Global Round 1 题解:The Editorial of the First Codeforces Global Round A:其实mod 2计算一下就行了 B:删 ...

  8. Codeforces Global Round 4-D. Prime Graph(伯特兰-切比雪夫定理)

    题目:Codeforces Global Round 4-D. Prime Graph 题意:给出n(顶点的个数),要求所得图满足: 1.无平行边和自环 2.边的总数是个质数 3.每个点的度(也就是点 ...

  9. Codeforces Global Round 15 ABCD

    A. Subsequence Permutation 题意: 给定一个字符串,选择任意数量的字符调整位置,使得调整位置之后整个序列是从小到大的,要求调整的位置数量最小 输入 4 3 lol 10 co ...

最新文章

  1. Java嵌套构造函数造成的stack overflow异常
  2. JVM—类加载器和双亲委派模型
  3. layui表格固定列覆盖滚动条导致错位
  4. 神话系列之一 C# 开发的操作系统和数据库
  5. pcDuino的linux移植五GPIO驱动开发
  6. NUC1178 Kickdown【水题】
  7. 一千个哈姆雷特,一千个手游开发者
  8. 【破损识别】基于matlab GUI机器视觉+SVM玉米种子破损识别(带面板)【含Matlab源码 1651期】
  9. 【系统分析师之路】2010年系统分析师上午综合知识真题
  10. java iplimage 头文件_在javacv中将IplImage转换为Mat
  11. 约翰诺依曼在1940年发明了计算机英语,冯诺依曼元胞自动机
  12. 苦橙花---不喧哗,自有声
  13. chrome-功能指令
  14. 对于Python的get-pip.py安装教程
  15. fatal: unable to access ‘https://gitee.com/****/****.git/‘: The requested URL returned error
  16. 微信小程序服务商下子商户支付下单接口
  17. 冷链食品追溯迫在眉睫,爱码物联3步助力冷链溯源
  18. Meth | 新建git项目
  19. linux查看进程并kill
  20. 第一章、华软代码生成器简单模板调制教程

热门文章

  1. Axure原型——《瑶族非遗服饰App》
  2. 网络视频播放ZFPlayer
  3. 配置Docker源为阿里源
  4. 扫描线算法讲解+例题
  5. UniApp基础:简单入门
  6. iPhone难卖,被欧洲反垄断的服务业务也难赚钱了,苹果的日子艰难
  7. vue3组件通信方式
  8. Jlink驱动的官方下载链接及步骤 - JLink_Windows_Vxxxx_x86_xx
  9. 公园安防建设:如何基于EasyCVR技术打造城市公园智能化视频监控?
  10. periphery SPM