Seating Arrangements (easy version)

H1. Seating Arrangements (easy version)


It is the easy version of the problem. The only difference is that in this version n = 1 n = 1 n=1.

In the cinema seats can be represented as the table with n n n rows and m m m columns. The rows are numbered with integers from 1 1 1 to n n n. The seats in each row are numbered with consecutive integers from left to right: in the k k k-th row from m ( k − 1 ) + 1 m (k - 1) + 1 m(k1)+1 to m k m k mk for all rows 1 ≤ k ≤ n 1 \le k \le n 1kn.

1 1 1 2 2 2 ⋯ \cdots m − 1 m - 1 m1 m m m
m + 1 m + 1 m+1 m + 2 m + 2 m+2 ⋯ \cdots 2 m − 1 2 m - 1 2m1 2 m 2 m 2m
2 m + 1 2m + 1 2m+1 2 m + 2 2m + 2 2m+2 ⋯ \cdots 3 m − 1 3 m - 1 3m1 3 m 3 m 3m
⋮ \vdots ⋮ \vdots ⋱ \ddots ⋮ \vdots ⋮ \vdots
m ( n − 1 ) + 1 m (n - 1) + 1 m(n1)+1 m ( n − 1 ) + 2 m (n - 1) + 2 m(n1)+2 ⋯ \cdots n m − 1 n m - 1 nm1 n m n m nm

There are n m nm nm people who want to go to the cinema to watch a new film. They are numbered with integers from 1 1 1 to n m nm nm. You should give exactly one seat to each person.

It is known, that in this cinema as lower seat index you have as better you can see everything happening on the screen. i i i-th person has the level of sight a i a_i ai. Let’s define s i s_i si as the seat index, that will be given to i i i-th person. You want to give better places for people with lower sight levels, so for any two people i i i, j j j such that a i < a j a_i < a_j ai<aj it should be satisfied that s i < s j s_i < s_j si<sj.

After you will give seats to all people they will start coming to their seats. In the order from 1 1 1 to n m nm nm, each person will enter the hall and sit in their seat. To get to their place, the person will go to their seat’s row and start moving from the first seat in this row to theirs from left to right. While moving some places will be free, some will be occupied with people already seated. The inconvenience of the person is equal to the number of occupied seats he or she will go through.

Let’s consider an example: m = 5 m = 5 m=5, the person has the seat 4 4 4 in the first row, the seats 1 1 1, 3 3 3, 5 5 5 in the first row are already occupied, the seats 2 2 2 and 4 4 4 are free. The inconvenience of this person will be 2 2 2, because he will go through occupied seats 1 1 1 and 3 3 3.

Find the minimal total inconvenience (the sum of inconveniences of all people), that is possible to have by giving places for all people (all conditions should be satisfied).

Input

The input consists of multiple test cases. The first line contains a single integer t t t ( 1 ≤ t ≤ 100 1 \le t \le 100 1t100) — the number of test cases. Description of the test cases follows.

The first line of each test case contains two integers n n n and m m m ( n = 1 n = 1 n=1, 1 ≤ m ≤ 300 1 \le m \le 300 1m300) — the number of rows and places in each row respectively.

The second line of each test case contains n ⋅ m n \cdot m nm integers a 1 , a 2 , … , a n ⋅ m a_1, a_2, \ldots, a_{n \cdot m} a1,a2,,anm ( 1 ≤ a i ≤ 1 0 9 1 \le a_i \le 10^9 1ai109), where a i a_i ai is the sight level of i i i-th person.

It’s guaranteed that the sum of n ⋅ m n \cdot m nm over all test cases does not exceed 1 0 5 10^5 105.

Output

For each test case print a single integer — the minimal total inconvenience that can be achieved.

Example

Input

4
1 3
1 2 3
1 5
2 1 5 3 3
1 2
2 1
1 6
2 3 2 1 1 1

Output

3
6
0
1

Note

In the first test case, there is a single way to arrange people, because all sight levels are distinct. The first person will sit on the first seat, the second person will sit on the second place, the third person will sit on the third place. So inconvenience of the first person will be 0 0 0, inconvenience of the second person will be 1 1 1 and inconvenience of the third person will be 2 2 2. The total inconvenience is 0 + 1 + 2 = 3 0 + 1 + 2 = 3 0+1+2=3.

In the second test case, people should sit as follows: s 1 = 2 s_1 = 2 s1=2, s 2 = 1 s_2 = 1 s2=1, s 3 = 5 s_3 = 5 s3=5, s 4 = 4 s_4 = 4 s4=4, s 5 = 3 s_5 = 3 s5=3. The total inconvenience will be 6 6 6.

code

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
 
using namespace std;


const int N = 2e5+10,INF=0x3f3f3f3f,mod=1e9+7;
 
typedef pair<int,int> PII;

int T=1;

void solve(){
	int n,m;
	cin>>n>>m;
	int cnt=0;
	vector<int> a(m+5,0);
	for(int i=0;i<m;i++) cin>>a[i];
	for(int i=0;i<m;i++){
		for(int j=0;j<i;j++){
			if(a[i]>a[j]) cnt++;
		}
	}
	cout<<cnt<<endl;
}

signed main(){
	cin>>T; 
    while(T--){
        solve();
    }
    return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/906758.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

TikTok如何用邮箱注册?用哪种邮箱比较好?

要在TikTok上创建一个账号&#xff0c;首先需要进行注册&#xff0c;这是一个简单但至关重要的步骤。在本篇文章中&#xff0c;我们将详细介绍如何用邮箱注册TikTok的整个过程&#xff0c;包括每个步骤的细节和注意事项。此外&#xff0c;我们还将讨论选择哪种邮箱比较好&#…

输电线路绝缘子缺陷分割系统:轻松训练模式

输电线路绝缘子缺陷分割系统源码&#xff06;数据集分享 [yolov8-seg&#xff06;yolov8-seg-C2f-MSBlock等50全套改进创新点发刊_一键训练教程_Web前端展示] 1.研究背景与意义 项目参考ILSVRC ImageNet Large Scale Visual Recognition Challenge 项目来源AAAI Global Al …

flink 自定义kudu connector中使用Metrics计数平均吞吐量,并推送到自定义kafkaReporter

文章目录 前言1. Registering metrics2. Metrics 的类型2.1 counter2.2 Gauge2.3 Histogram2.4 meter 3. 指标划分3.1 指标所属的范围3.2 默认所属 4. 自定义kudu connector中使用Metrics4.1 sink算子继承RichFunction4.2 注册指标4.3 计数逻辑4.4 自定义Reporter&#xff0c;推…

Calling short variants with GATK4

计算生物学实验5: Calling short variants with GATK4 1. 实验目的 本实验目的是利用 GATK4 工具准确高效地检测出基因组中的短变异。通过该工具对样本基因组进行分析&#xff0c;旨在发现单核苷酸变异&#xff08;SNV&#xff09;和小的插入缺失&#xff08;Indel&#xff0…

【D3.js in Action 3 精译_038】4.2 D3 折线图的绘制方法及曲线插值处理

当前内容所在位置&#xff08;可进入专栏查看其他译好的章节内容&#xff09; 第一部分 D3.js 基础知识 第一章 D3.js 简介&#xff08;已完结&#xff09; 1.1 何为 D3.js&#xff1f;1.2 D3 生态系统——入门须知1.3 数据可视化最佳实践&#xff08;上&#xff09;1.3 数据可…

《机器学习by周志华》学习笔记-神经网络-04全局最小误差与局部极小误差

1、神经网络中误差的概念及公式 根据上文《逆误差传播算法》我们可以知道误差公式的演化: ① 第k个训练样例的误差函数: ②该训练集的累积误差函数: ③正则化误差目标函数: 其中: :表示第k个训练样例的误差;:表示连接权重和阈值任意参数;根据上文我们可知需要确定的参…

每日读则推(十四)——Meta Movie Gen: the most advanced media foundation models to-date

premiere n.首映,首次公演 v.首次公演(戏剧、音乐、电影) a.首要的,最早的 Today we’re premiering Meta Movie Gen: the most advanced media foundation models to-date. 迄今,到现在为止 …

大模型面试题全面总结:每一道都是硬核挑战

节前&#xff0c;我们组织了一场算法岗技术&面试讨论会&#xff0c;邀请了一些互联网大厂同学、参加社招和校招面试的同学&#xff0c;针对算法岗技术趋势、大模型落地项目经验分享、新手如何入门算法岗、该如何准备、面试常考点分享等热门话题进行了深入的讨论。 今天分享…

c++文件操作中的seekp函数使用方法

seekp函数能设置输出流的位置 比如我先向文件输入了123456&#xff0c;现在我想在第四个字符后面再加上ABC&#xff0c;这个时候我们就可以用seekp函数来设置输出的位置 #include <iostream> #include <fstream> #include <string>using namespace std;int …

Python小白学习教程从入门到入坑------第二十三课 封装(语法进阶)

面向对象的三大特征&#xff1a;封装、继承、多态 一、封装 1.1 何为封装 封装&#xff1a;在Python中指的是隐藏对象中一些不希望被外部所访问到的属性或者方法。将复杂的信息、流程给包起来&#xff0c;内部处理&#xff0c;让使用者只需要通过简单的操作步骤&#xff0c;…

less解决function中return写法在浏览器被识别成Object导致样式失败的问题

问题描述&#xff1a; 一开始写的是: baseFontSize: 37.5px;//基于屏幕尺寸/10得出的基准font-size// return失败,浏览器显示为[object Object],[object Object] .pxToRem(px){value: px / baseFontSize * 1rem;return value; } 使用height: .pxToRem(40px);之后浏览器却是这…

OpenCV视觉分析之目标跟踪(4)目标跟踪类TrackerDaSiamRPN的使用

操作系统&#xff1a;ubuntu22.04 OpenCV版本&#xff1a;OpenCV4.9 IDE:Visual Studio Code 编程语言&#xff1a;C11 算法描述 cv::TrackerDaSiamRPN 是 OpenCV 中用于目标跟踪的一个类&#xff0c;它实现了 DaSiam RPN&#xff08;Deformable Siamese Region Proposal Net…

高效视频制作大提速,视频剪辑软件的高级自定义命令功能批量调整视频的色调、饱和度和亮度,轻松驾驭视频编辑技巧

在浩瀚的数字海洋中&#xff0c;视频如同璀璨的星辰&#xff0c;而每一颗星辰都渴望被精心雕琢&#xff0c;闪耀出最独特的光芒。想象一下&#xff0c;你手握一把神奇的钥匙&#xff0c;能够轻松解锁批量视频剪辑的奥秘&#xff0c;让每一帧画面都跃动着你的创意与激情。这把钥…

Vue3入门--[vue/compiler-sfc] Unexpected token, expected “,“ (18:0)

新手小白学习Vue–入门就踩坑系列 问题描述 创建了一个Person.vue&#xff0c;保存后直接报错&#xff1a; [plugin:vite:vue] [vue/compiler-sfc] Unexpected token, expected "," (18:0) 在网上搜了半天也没找到原因&#xff0c;最后还得靠自己&#xff0c;现将解…

【制造业&盒子】箱子检测系统源码&数据集全套:改进yolo11-swintransformer

改进yolo11-MLCA等200全套创新点大全&#xff1a;箱子检测系统源码&#xff06;数据集全套 1.图片效果展示 项目来源 人工智能促进会 2024.11.01 注意&#xff1a;由于项目一直在更新迭代&#xff0c;上面“1.图片效果展示”和“2.视频效果展示”展示的系统图片或者视频可能为…

Spring Security 框架篇-深入了解 Spring Security 的认证功能流程和自定义实现登录接口(实现自定义认证过滤器、登出功能)

&#x1f525;博客主页&#xff1a; 【小扳_-CSDN博客】 ❤感谢大家点赞&#x1f44d;收藏⭐评论✍ 文章目录 1.0 Spring Security 框架概述 2.0 Spring Security 核心功能-认证功能 2.1 过滤器链 2.2 登录认证流程 2.3 思路分析 3.0 登录认证具体操作 3.1 环境搭建 3.2 实现 U…

HBuilderx修改主题色-改变编辑器背景颜色等

效果图&#xff1a; 第一步我们打开HBuilderX 选择工具 – 主题 – 选择&#xff08;雅蓝&#xff09; 然后再设置&#xff0c;源码视图里面打开Setting.json文件 3.将一下代码赋值到右侧用户设置即可 {"workbench.colorCustomizations": {// "[Defau…

食堂采购系统源码:实现供应链管理平台功能模块的技术实践

在当前数字化转型浪潮中&#xff0c;餐饮和食堂管理的需求越来越高&#xff0c;食堂采购系统逐渐成为企业和组织优化管理、降低成本的关键工具。 一、食堂采购系统的核心功能概述 一个完善的食堂采购系统不仅需要具备传统的订单管理、库存管理、供应商管理功能&#xff0c;还…

Python 工具库每日推荐 【Sphinx】

文章目录 引言文档工具的重要性今日推荐:Sphinx 文档生成工具主要功能:使用场景:安装与配置快速上手示例代码代码解释实际应用案例案例:为 Python 项目生成 API 文档案例分析高级特性自定义主题国际化支持扩展阅读与资源优缺点分析优点:缺点:总结【 已更新完 TypeScript …

stm32不小心把SWD和JTAG都给关了,程序下载不进去,怎么办?

因为想用STM32F103的PA15引脚&#xff0c;调试程序的时候不小心把SWD和JTAD接口都给关了&#xff0c;先看下罪魁祸首 GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable,ENABLE);//关掉JTAG&#xff0c;不关SWGPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE);//关掉SW&am…