当前位置:网站首页>CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!)
CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!)
2022-08-02 04:25:00 【一条小小yu】
前缀和之和之我是煞笔
D. Magical Array
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Example
input
Copy
7 3 9 0 1 2 0 0 2 1 1 0 0 1 1 1 2 0 0 2 0 0 1 2 0 0 1 2 1 0 3 7 25 15 20 15 25 20 20 26 14 20 14 26 20 20 25 15 20 15 20 20 25 3 9 25 15 20 15 25 20 20 20 20 26 14 20 14 26 20 20 20 20 25 15 20 15 25 15 20 20 25 3 11 25 15 20 15 25 20 20 20 20 20 20 26 14 20 14 26 20 20 20 20 20 20 25 15 20 15 25 20 15 20 20 20 25 3 13 25 15 20 15 25 20 20 20 20 20 20 20 20 26 14 20 14 26 20 20 20 20 20 20 20 20 25 15 20 15 25 20 20 15 20 20 20 20 25 3 15 25 15 20 15 25 20 20 20 20 20 20 20 20 20 20 26 14 20 14 26 20 20 20 20 20 20 20 20 20 20 25 15 20 15 25 20 20 20 15 20 20 20 20 20 25 3 9 909459 479492 676924 224197 162866 164495 193268 742456 728277 948845 455424 731850 327890 304150 237351 251763 225845 798316 975446 401170 792914 272263 300770 242037 236619 334316 725899output
Copy
3 1 3 10 3 15 3 20 3 25 3 30 1 1378716Note
In the first test case, the secret array bb is [0,1,1,1,1,1,1,1,0][0,1,1,1,1,1,1,1,0]. Array c1c1 and array c2c2 are generated by using operation 1. Array c3c3 is generated by using operation 2.
For Array c1c1,you can choose i=4i=4 and j=5j=5 perform Operation 1 one time to generate it. For Array c2c2, you can choose i=6i=6 and j=7j=7 perform Operation 1 one time to generate it. For Array c3c3,you can choose i=4i=4 and j=5j=5 perform Operation 2 one time to generate it.
In the second test case, the secret array bb is [20,20,20,20,20,20,20][20,20,20,20,20,20,20]. You can also find that array c1c1 and array c2c2 are generated by using Operation 1. Array c3c3 is generated by using Operation 2.
In the third test case, the secret array bb is [20,20,20,20,20,20,20,20,20][20,20,20,20,20,20,20,20,20]. You can also find that array c1c1 and array c2c2 are generated by using Operation 1. Array c3c3 is generated by using Operation 2.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int N=3e5+10;
ll sums[N],sum[N],n,m,t;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>t;
while(t--)
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
sums[i]=0;
sum[i]=0;
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
ll x;
cin>>x;
sum[j]=x+sum[j-1];
sums[i]+=sum[j];
}
}
int k=1;
if(sums[n]!=sums[1]&&sums[n]!=sums[2])k=n;
for(int i=2;i<=n-1;i++)
{
if(sums[i]!=sums[1]&&sums[i]!=sums[n])k=i;
}
cout<<k<<" "<<max(sums[1],sums[2])-sums[k]<<"\n";
}
return 0;
}
边栏推荐
猜你喜欢
随机推荐
Platts Analysis-MATLAB Toolbox Function
论人生自动化
爬虫_爬取wasde月度供需平衡表(实例)
批量--10---根据set数拆分文件
Deep Learning Basics Overfitting, Underfitting Problems, and Regularization
温暖的世界
Minecraft 1.18.1, 1.18.2 module development 23.3D animation armor production
HyperLynx中层叠设计实例
力扣练习——单词搜索
通关剑指 Offer——剑指 Offer II 008. 和大于等于 target 的最短子数组
力扣练习——44 路径总和 III
Go 语言是如何实现切片扩容的?【slice】
300M级mysql数据库跨版本迁移流程
ClickHouse的客户端命令行参数
深度剖析-class的几个对象(utlis,component)-瀑布流-懒加载(概念,作用,原理,实现步骤)
Luogu P2437 Bee Route
如果有些字段不想进行序列化怎么办?
投资组合分析:portfolio_analysis.Tangenvy_portfolio(切点组合)
单调队列模板 滑动窗口
洛谷P2437蜜蜂路线