• CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!)


    前缀和之和之我是煞笔

    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
    • Operation 2: Choose two integers ii and jj (2≤iNote 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 725899
    

    output

    Copy

    3 1
    3 10
    3 15
    3 20
    3 25
    3 30
    1 1378716
    

    Note

    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.

    1. #include
    2. using namespace std;
    3. typedef long long ll;
    4. typedef double db;
    5. const int N=3e5+10;
    6. ll sums[N],sum[N],n,m,t;
    7. int main()
    8. {
    9. ios::sync_with_stdio(false);
    10. cin.tie(0);
    11. cout.tie(0);
    12. cin>>t;
    13. while(t--)
    14. {
    15. cin>>n>>m;
    16. for(int i=1;i<=n;i++)
    17. {
    18. sums[i]=0;
    19. sum[i]=0;
    20. }
    21. for(int i=1;i<=n;i++)
    22. {
    23. for(int j=1;j<=m;j++)
    24. {
    25. ll x;
    26. cin>>x;
    27. sum[j]=x+sum[j-1];
    28. sums[i]+=sum[j];
    29. }
    30. }
    31. int k=1;
    32. if(sums[n]!=sums[1]&&sums[n]!=sums[2])k=n;
    33. for(int i=2;i<=n-1;i++)
    34. {
    35. if(sums[i]!=sums[1]&&sums[i]!=sums[n])k=i;
    36. }
    37. cout<" "<<max(sums[1],sums[2])-sums[k]<<"\n";
    38. }
    39. return 0;
    40. }

     

  • 相关阅读:
    每天一道算法题(十)——获取和为k的子数组
    python实验课7~8---面向对象
    golang中零停机重启服务之套接字复用,endless
    Vue通知提醒框(Notification)
    云计算与大数据第5章 云计算安全题库及答案
    伪原创智能改写api百度-收录良好
    NPDP|作为产品经理,如何快速提升自身业务素养?
    web前端期末大作业——HTML+CSS简单的旅游网页设计与实现
    NOIP2000提高组第二轮T2:乌龟棋
    HTML常用标签的简单用法
  • 原文地址:https://blog.csdn.net/m0_61949623/article/details/126106664