D. Magical Array

42 篇文章 0 订阅

Eric has an array bb of length mm, then he generates nn additional arrays c1,c2,…,cnc1,c2,…,cn, each of length mm, from the array bb, by the following way:

Initially, ci=bci=b for every 1≤i≤n1≤i≤n. Eric secretly chooses an integer kk (1≤k≤n)(1≤k≤n) and chooses ckck to be the special array.

There are two operations that Eric can perform on an array ctct:

  • Operation 1: Choose two integers ii and jj (2≤i<j≤m−12≤i<j≤m−1), subtract 11 from both ct[i]ct[i] and ct[j]ct[j], and add 11 to both ct[i−1]ct[i−1] and ct[j+1]ct[j+1]. That operation can only be used on a non-special array, that is when t≠kt≠k.;
  • Operation 2: Choose two integers ii and jj (2≤i<j≤m−22≤i<j≤m−2), subtract 11 from both ct[i]ct[i] and ct[j]ct[j], and add 11 to both ct[i−1]ct[i−1] and ct[j+2]ct[j+2]. That operation can only be used on a special array, that is when t=kt=k.

    Note that Eric can't perform an operation if any element of the array will become less than 00 after that operation.

Now, Eric does the following:

  • For every non-special array cici (i≠ki≠k), Eric uses only operation 1 on it at least once.
  • For the special array ckck, Eric uses only operation 2 on it at least once.

Lastly, Eric discards the array bb.

For given arrays c1,c2,…,cnc1,c2,…,cn, your task is to find out the special array, i.e. the value kk. Also, you need to find the number of times of operation 22 was used on it.

Input

The first line contains a single integer tt (1≤t≤1041≤t≤104) — the number of test cases. Description of test cases follows.

The first line of each test case contains two integers nn and mm (3≤n≤1053≤n≤105, 7≤m≤3⋅1057≤m≤3⋅105) — the number of arrays given to you, and the length of each array.

The next nn lines contains mm integers each, ci,1,ci,2,…,ci,mci,1,ci,2,…,ci,m.

It is guaranteed that each element of the discarded array bb is in the range [0,106][0,106], and therefore 0≤ci,j≤3⋅10110≤ci,j≤3⋅1011 for all possible pairs of (i,j)(i,j).

It is guaranteed that the sum of n⋅mn⋅m over all test cases does not exceed 106106.

It is guaranteed that the input is generated according to the procedure above.

Output

For each test case, output one line containing two integers — the index of the special array, and the number of times that Operation 2 was performed on it. It can be shown that under the constraints given in the problem, this value is unique and won't exceed 10181018, so you can represent it as a 6464-bit integer. It can also be shown that the index of the special array is uniquely determined.

In this problem, hacks are disabled.

题意:给一个长度为m的数组b,然后把b复制成n个和b一样的c数组

选一个特殊数组ct

有两种操作:

1.对不是特殊数组的数组c来操作,我们选两个数i,j,c[i]-1,c[j]-1,c[i-1]+1,c[j+1]+1

2.对是特殊数组的数组c来操作,我们选两个数i,j,c[i]-1,c[j]-1,c[i-1]+1,c[j+2]+1

然后给你n个变化后的c数组,让我们找特殊数组并计算操作了几次。

思路:我们可以看出特殊数组和正常数组的区别就是

正常数组在j+1的位置+1而特殊数组是在j+2的位置+1的,

我们通过观察可以发现这样的性质:

算c[i]*i的和

在进行操作一前后:

 可以看出c[i]*i的和没有变化

在进行操作二前后:

 可以看出c[i]*i每进行一个操作2就多加了个1

那么我们就找这n个数组里c[i]*i的和,当一个数组的和大于其他所有数组的和的时候

这个数组就是特殊数组,并且他们的差就是操作2的次数

/*

 .----------------.  .----------------.  .----------------.  .----------------. 
| .--------------. || .--------------. || .--------------. || .--------------. |
| |  ________    | || |  _________   | || | ____    ____ | || |     ____     | |
| | |_   ___ `.  | || | |_   ___  |  | || ||_   \  /   _|| || |   .'    `.   | |
| |   | |   `. \ | || |   | |_  \_|  | || |  |   \/   |  | || |  /  .--.  \  | |
| |   | |    | | | || |   |  _|  _   | || |  | |\  /| |  | || |  | |    | |  | |
| |  _| |___.' / | || |  _| |___/ |  | || | _| |_\/_| |_ | || |  \  `--'  /  | |
| | |________.'  | || | |_________|  | || ||_____||_____|| || |   `.____.'   | |
| |              | || |              | || |              | || |              | |
| '--------------' || '--------------' || '--------------' || '--------------' |
 '----------------'  '----------------'  '----------------'  '----------------'

*/
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<cmath>
#include<unordered_map>
#include<unordered_set>
#include<stack>
#define int long long
#define lowbit(x) x&(-x)
#define PI 3.1415926535
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int gcd(int a,int b){
	return b>0 ? gcd(b,a%b):a;
}
/*
int dx[8]={-2,-2,-1,1,2,2,-1,1};
int dy[8]={-1,1,2,2,1,-1,-2,-2};
int dx[4]={0,-1,0,1};
int dy[4]={-1,0,1,0};
int dx[8]={-1,1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
*/
/*void init(){
	int con=0;
	for(int i=1;i<=15;i++)con+=i;
}
*/
/*
void sjdhfb(){
	int djbhff=0;
	for(int dd=1;dd<=4;dd++){
		djbhff+=dd;
	}
}
*/
//int e[N],ne[N],h[N],idx,w[N];
/*void add(int a,int b,int c){
	e[idx]=b;
	w[idx]=c;
	ne[idx]=h[a];
	h[a]=idx++;
}
*/
const int N=3e5+10;
int n,m;
int a[N];
void sove(){
	cin>>n>>m;
	int con1=-1,con2,id=1;
	for(int i=1;i<=n;i++){
		int num=0;
		for(int j=1;j<=m;j++){
			cin>>a[j];
			num+=a[j]*j;
		}
		if(con1==-1){
			con1=num;
		}else if(con1==num){
			con1=num;
		}else{
			if(con1>num){
				id=i-1;
				con2=con1;
				con1=num;
			}else{
				id=i;
				con2=num;
			}
		}
	}
	cout<<id<<" "<<con2-con1<<endl;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie() ,cout.tie() ;
	int t=1;
	cin>>t;
//	init();
//	sjdhfb();
//	init();
	while(t--){
		sove();
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值