Codeforces Round #799 (Div. 4)A~H

Codeforces Round #799 (Div. 4)A~H,第1张

Codeforces Round #799 (Div. 4) Problem - A - Codeforces

You are given four distinct integers a, b, c, d.

Timur and three other people are running a marathon. The value a is the distance that Timur has run and b, c, d correspond to the distances the other three participants ran.

Output the number of participants in front of Timur.

Input

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

The description of each test case consists of four distinct integers a, b, c, d (0≤a,b,c,d≤104).

Output

For each test case, output a single integer — the number of participants in front of Timur.

Example input
4
2 3 4 1
10000 0 1 2
500 600 400 300
0 9999 10000 9998
output
2
0
1
3
问题解析

给你4个人位移长度,问你有几个人在第一个人的前面。

直接输出位移长度大于第一个人的个数即可。

AC代码
#include
using namespace std;
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

#define endl '\n'
#define int ll
typedef long long ll;
typedef unsigned long long ull;
typedef pairPII;
const int N = 2e5 + 50;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
    {
        int a;
        cin >> a;
        int res = 0;
        vectorv(3);
        for (int i = 0; i < 3; i++)
        {
            cin >> v[i];
            if (v[i] > a)res++;
        }
        cout << res << endl;
    }
    return 0;
}
Problem - B - Codeforces

Sho has an array a consisting of n integers. An operation consists of choosing two distinct indices i and j and removing ai and aj from the array.

For example, for the array [2,3,4,2,5], Sho can choose to remove indices 1 and 3. After this operation, the array becomes [3,2,5]. Note that after any operation, the length of the array is reduced by two.

After he made some operations, Sho has an array that has only distinct elements. In addition, he made operations such that the resulting array is the longest possible.

More formally, the array after Sho has made his operations respects these criteria:

No pairs such that (i The length of a is maximized.
Output the length of the final array.

Input

The first line contains a single integer t (1≤t≤103) — the number of test cases.

The first line of each test case contains a single integer n (1≤n≤50) — the length of the array.

The second line of each test case contains n integers ai (1≤ai≤104) — the elements of the array.

Output

For each test case, output a single integer — the length of the final array. Remember that in the final array, all elements are different, and its length is maximum.

Example input
4
6
2 2 2 3 3 3
5
9 1 9 9 1
4
15 16 16 15
4
10 100 1000 10000
output
2
1
2
4
问题解析

给你一个数组,你每次可以选两个数删除,问你把数组变的没有重复元素后,数组最大长度是多少。

记录每个数的出现次数,再看出现次数为奇数的数有多少,为偶数的数有多少。如果出现次数为奇数,那么删完相同的后还能留下一个数,如果出现次数为偶数,则还要再判断一下,出现次数为偶数的有多少个:

如果是偶数个(例如:1,1,2,2),那么可以内部消化(删一个1和一个2),最后剩下的数是:奇数个数+偶数个数;

如果是奇数个(例如:1,1,2,2,3,3),那么最后剩下的数是:奇数个数+偶数个数-1;

AC代码
#include
using namespace std;
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

#define endl '\n'
#define int ll
typedef long long ll;
typedef unsigned long long ull;
typedef pairPII;
const int N = 2e5 + 50;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        vectorv(n);
        unordered_mapmymap;
        for (int i = 0; i < n; i++)
        {
            cin >> v[i];
            mymap[v[i]]++;
        }
        int ji = 0, ou = 0;
        for (auto i : mymap)
        {
            if (i.second % 2 == 0)ou++;
            else ji++;
        }
        if (ou % 2 == 0)
        {
            cout << ji + ou << endl;
        }
        else cout << ji + ou - 1 << endl;
    }
    return 0;
}
Problem - C - Codeforces

Mihai has an 8×8 chessboard whose rows are numbered from 1 to 8 from top to bottom and whose columns are numbered from 1 to 8 from left to right.

Mihai has placed exactly one bishop on the chessboard. The bishop is not placed on the edges of the board. (In other words, the row and column of the bishop are between 2 and 7, inclusive.)

The bishop attacks in all directions diagonally, and there is no limit to the distance which the bishop can attack. Note that the cell on which the bishop is placed is also considered attacked.

An example of a bishop on a chessboard. The squares it attacks are marked in red.

Mihai has marked all squares the bishop attacks, but forgot where the bishop was! Help Mihai find the position of the bishop.

Input

The first line of the input contains a single integer t (1≤t≤36) — the number of test cases. The description of test cases follows. There is an empty line before each test case.

Each test case consists of 8 lines, each containing 8 characters. Each of these characters is either ‘#’ or ‘.’, denoting a square under attack and a square not under attack, respectively.

Output

For each test case, output two integers r and c (2≤r,c≤7) — the row and column of the bishop.

The input is generated in such a way that there is always exactly one possible location of the bishop that is not on the edge of the board.

Example input
3

.....#..
#...#...
.#.#....
..#.....
.#.#....
#...#...
.....#..
......#.

#.#.....
.#......
#.#.....
...#....
....#...
.....#..
......#.
.......#

.#.....#
..#...#.
...#.#..
....#...
...#.#..
..#...#.
.#.....#
#.......
output
4 3
2 2
4 5
问题解析

题目说给你一个8*8的棋盘,有个棋子可以攻击它的对角线方向(攻击范围是‘#’),让你找到这个棋子的位置。而且这个棋子不会出现在边缘位置。

遍历矩阵,找到一个位置(x,y),这个位置的字符是’#',而且它斜对角的四个方向(x-1,y-1),(x-1,y+1),(x+1,y+1),(x+1,y-1)也都是‘#’,找到并输出即可。

AC代码
#include
using namespace std;
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

#define endl '\n'
#define int ll
typedef long long ll;
typedef unsigned long long ull;
typedef pairPII;
const int N = 2e5 + 50;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
    {
        vectorv(8);
        for (int i = 0; i < 8; i++)
        {
            cin >> v[i];
        }
        bool flag = false;
        int x, y;
        for (int i = 1; i < 8; i++)
        {
            for (int j = 1; j < 8; j++)
            {
                if (v[i][j] == '#' && v[i + 1][j + 1] == '#' && v[i - 1][j - 1] == '#' && v[i + 1][j - 1] == '#' && v[i - 1][j + 1] == '#')
                {
                    x = i, y = j, flag = true;
                    break;
                }
            }
            if (flag)break;
        }
        cout << x+1 << " " << y+1 << endl;
    }
    return 0;
}
Problem - D - Codeforces

Victor has a 24-hour clock that shows the time in the format “HH:MM” (00 ≤ HH ≤ 23, 00 ≤ MM ≤ 59). He looks at the clock every x minutes, and the clock is currently showing time s.

How many different palindromes will Victor see in total after looking at the clock every x minutes, the first time being at time s?

For example, if the clock starts out as 03:12 and Victor looks at the clock every 360 minutes (i.e. every 6 hours), then he will see the times 03:12, 09:12, 15:12, 21:12, 03:12, and the times will continue to repeat. Here the time 21:12 is the only palindrome he will ever see, so the answer is 1.

A palindrome is a string that reads the same backward as forward. For example, the times 12:21, 05:50, 11:11 are palindromes but 13:13, 22:10, 02:22 are not.

Input

The first line of the input contains an integer t (1≤t≤100) — the number of test cases. The description of each test case follows.

The only line of each test case contains a string s of length 5 with the format “HH:MM” where “HH” is from “00” to “23” and “MM” is from “00” to “59” (both “HH” and “MM” have exactly two digits) and an integer x (1≤x≤1440) — the number of minutes Victor takes to look again at the clock.

Output

For each test case, output a single integer — the number of different palindromes Victor will see if he looks at the clock every x minutes starting from time s.

Example input
6
03:12 360
00:00 1
13:22 2
15:15 10
11:11 1440
22:30 27
output
1
16
10
0
1
1
问题解析

题目是说给你一个当前的时间s,然后再给你一个分钟数m,让你每隔m分钟就看一下时钟,如果当前时钟数可以形成一个回文串(21:12)就记录一下,问你一次轮回一共能看见几个回文串。

直接把给的时间s转换成小时x和分钟y两个变量,再用a和b表示看时钟时看到的小时数和分钟数,为了方便也可以把分钟数m也转化成小时和分钟两部分。当ax且by时说明完成一次轮回。然后判断是否是回文就判断一下a和b是否是相反的数(比如21和12)即可。

AC代码
#include
using namespace std;
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

#define endl '\n'
#define int ll
typedef long long ll;
typedef unsigned long long ull;
typedef pairPII;
const int N = 2e5 + 50;

bool check(int a,int b)
{
    string s1 = to_string(a), s2 = to_string(b);
    if (s1.size() < 2)s1 = "0" + s1;
    if (s2.size() < 2)s2 = "0" + s2;
    reverse(s1.begin(), s1.end());
    return s1 == s2;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
    {
        string s;
        int ans;
        cin >> s >> ans;
        int res = 0;
        int h = ans / 60, m = ans % 60;
        int x = stoi(s.substr(0, 2)), y = stoi(s.substr(3, 2));
        if (check(x, y))res++;
        int b = y + m, a = h + x + (b) / 60;
        b %= 60;
        a %= 24;
        while (a != x || b != y)
        {
            if (check(a, b))res++;
            b += m;
            a += h + b / 60;
            a %= 24;
            b %= 60;
        }
        cout << res << endl;
    }
    return 0;
}
Problem - E - Codeforces

Slavic has an array of length n consisting only of zeroes and ones. In one operation, he removes either the first or the last element of the array.

What is the minimum number of operations Slavic has to perform such that the total sum of the array is equal to s after performing all the operations? In case the sum s can’t be obtained after any amount of operations, you should output -1.

Input

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

The first line of each test case contains two integers n and s (1≤n,s≤2⋅105) — the length of the array and the needed sum of elements.

The second line of each test case contains n integers ai (0≤ai≤1) — the elements of the array.

It is guaranteed that the sum of n over all test cases doesn’t exceed 2⋅105.

Output

For each test case, output a single integer — the minimum amount of operations required to have the total sum of the array equal to s, or -1 if obtaining an array with sum s isn’t possible.

Example input
7
3 1
1 0 0
3 1
1 1 0
9 3
0 1 0 1 1 1 0 0 1
6 4
1 1 1 1 1 1
5 1
0 0 1 1 0
16 2
1 1 0 0 1 0 0 1 1 0 0 0 0 0 1 1
6 3
1 0 1 0 0 0
output
0
1
3
2
2
7
-1
问题解析

题目是说给你一个全由0和1组成的数组和一个数k,你每次可以删除数组头部元素或尾部元素,问你最少删多少个元素后,使得数组的和为k。

二分做法,做两个辅助数组lx和rx,存储的是数对,lx[i].first代表这是从左往右数第几个1,lx[i].second代表到这个1需要删多少元素;rx同理,但是是从右往左。我们固定遍历左端点,每遍历一个段点,就用二分去右边找我们需要的点,在计算走到左端点的步数+走到右端点的步数即可,在此过程中维护最小值。

AC代码
#include
using namespace std;
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

#define endl '\n'
#define int ll
typedef long long ll;
typedef unsigned long long ull;
typedef pairPII;
const int N = 2e5 + 50;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
    {
        int n, k, sum = 0;
        cin >> n >> k;
        vectorv(n + 1);
        vectorlx,rx;
        lx.push_back({ 0,0 });
        rx.push_back({ 0,0 });
        for (int i = 1; i <= n; i++)
        {
            cin >> v[i];
            if (v[i] == 1)
            {
                lx.push_back({ lx.back().first + 1,i });
            }
            sum += v[i];
        }
        for (int i = n; i >= 1; i--)
        {
            if (v[i] == 1)
            {
                rx.push_back({ rx.back().first + 1,n - i + 1 });
            }
        }
        if (sum == k)
        {
            cout << 0 << endl;
            continue;
        }
        else if (sum < k)
        {
            cout << -1 << endl;
            continue;
        }
        int res = 1e9;
        for (auto i : lx)
        {
            if (sum - i.first == k)
            {
                res = min(res, i.second);
                continue;
            }
            if (sum - i.first < k)
            {
                break;
            }
            int l = 0, r = rx.size() - 1;
            while (l < r)
            {
                int mid = (l + r) / 2;
                if (rx[mid].first == sum - k - i.first)
                {
                    l = mid;
                    break;
                }
                else if (rx[mid].first <= sum - k - i.first)l = mid;
                else r = mid;
            }
            res = min(res, i.second + rx[l].second);
        }
        cout << res << endl;
    }
    return 0;
}
Problem - F - Codeforces

Given an array a of positive integers with length n, determine if there exist three distinct indices i, j, k such that ai+aj+ak ends in the digit 3.

Input

The first line contains an integer t (1≤t≤1000) — the number of test cases.

The first line of each test case contains an integer n (3≤n≤2⋅105) — the length of the array.

The second line of each test case contains n integers a1,a2,…,an (1≤ai≤109) — the elements of the array.

The sum of n across all test cases does not exceed 2⋅105.

Output

Output t lines, each of which contains the answer to the corresponding test case. Output “YES” if there exist three distinct indices i, j, k satisfying the constraints in the statement, and “NO” otherwise.

You can output the answer in any case (for example, the strings “yEs”, “yes”, “Yes” and “YES” will be recognized as a positive answer).

Example input
6
4
20 22 19 84
4
1 11 1 2022
4
1100 1100 1100 1111
5
12 34 56 78 90
4
1 9 8 4
6
16 38 94 25 18 99
output
YES
YES
NO
NO
YES
YES
问题解析

题目是说给你一个数组,问你能不能在这个数组里找到3个元素,让他们的和%10后等于3。

我是打表方法写的:

包含0的且结尾是3的三数和有:0+1+2,0+0+3,0+4+9,0+5+8,0+6+7;

包含1的:0+1+2,1+1+1,1+3+9,1+4+8,1+5+7,1+6+6;

包含2的:0+1+2,1+1+1,1+3+9,1+4+8,1+5+7,1+6+6;

包含3的:0+0+3,1+3+9,2+3+8,3+3+7,3+4+6,3+5+5;

………………

先把所有的元素%10,然后记录出现次数,再判断能不能满足以上的情况,能满足一个就是yes。

AC代码
#include
using namespace std;
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

#define endl '\n'
#define int ll
typedef long long ll;
typedef unsigned long long ull;
typedef pairPII;
const int N = 2e5 + 50;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        vectorv(n);
        unordered_mapmymap;
        for (int i = 0; i < n; i++)
        {
            cin >> v[i];
            v[i] %= 10;
            mymap[v[i]]++;
        }
        bool flag = false;
        if (!flag&&mymap[0] > 0)
        {
            if (mymap[1] > 0 && mymap[2] > 0)flag = true;
            if (mymap[3] > 0 && mymap[0] >= 2)flag = true;
            if (mymap[4] > 0 && mymap[9] > 0)flag = true;
            if (mymap[5] > 0 && mymap[8] > 0)flag = true;
            if (mymap[6] > 0 && mymap[7] > 0)flag = true;           
        }
        if (!flag && mymap[1] > 0)
        {
            if (mymap[2] > 0 && mymap[0] > 0)flag = true;
            if (mymap[1] >= 3)flag = true;
            if (mymap[3] > 0 && mymap[9] > 0)flag = true;
            if (mymap[4] > 0 && mymap[8] > 0)flag = true;
            if (mymap[5] > 0 && mymap[7] > 0)flag = true;
            if (mymap[6] >=2)flag = true;
        }
        if (!flag && mymap[2] > 0)
        {
            if (mymap[2] >= 2 && mymap[9] > 0)flag = true;
            if (mymap[3] > 0 && mymap[8] > 0)flag = true;
            if (mymap[4] > 0 && mymap[7] > 0)flag = true;
            if (mymap[5] > 0 && mymap[6] > 0)flag = true;
        }
        if (!flag && mymap[3] > 0)
        {
            if (mymap[3] >= 2 && mymap[7] > 0)flag = true;
            if (mymap[4] > 0 && mymap[6] > 0)flag = true;
            if (mymap[5] >= 2)flag = true;
        }
        if (!flag && mymap[4] > 0)
        {
            if (mymap[4] >= 2 && mymap[5] > 0)flag = true;
        }
        if (!flag && mymap[5] > 0)
        {
            if (mymap[9] >= 2 && mymap[5] > 0)flag = true;
        }
        if (!flag && mymap[6] > 0)
        {
            if (mymap[8] > 0 && mymap[9] > 0)flag = true;
        }
        if (!flag && mymap[7] > 0)
        {
            if (mymap[7] >= 2 && mymap[9] > 0)flag = true;
            if (mymap[8] >= 2)flag = true;
        }

        if (flag)cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}
Problem - G - Codeforces

Given an array a of length n and an integer k, find the number of indices 1≤i≤n−k such that the subarray [ai,…,ai+k] with length k+1 (not with length k) has the following property:

If you multiply the first element by 20, the second element by 21, …, and the (k+1)-st element by 2k, then this subarray is sorted in strictly increasing order.
More formally, count the number of indices 1≤i≤n−k such that
20⋅ai<21⋅ai+1<22⋅ai+2<⋯<2k⋅ai+k.

Input

The first line contains an integer t (1≤t≤1000) — the number of test cases.

The first line of each test case contains two integers n, k (3≤n≤2⋅105, 1≤k

The second line of each test case contains n integers a1,a2,…,an (1≤ai≤109) — the elements of the array.

The sum of n across all test cases does not exceed 2⋅105.

Output

For each test case, output a single integer — the number of indices satisfying the condition in the statement.

Example input
6
4 2
20 22 19 84
5 1
9 5 3 2 1
5 2
9 5 3 2 1
7 2
22 12 16 4 3 22 12
7 3
22 12 16 4 3 22 12
9 3
3 9 12 3 9 12 3 9 12
output
2
3
2
3
1
0
问题解析

题目是说给你一个数组和一个值k,让你找出所有长度为k+1且能满足(a[i]* 2^0 )<(a[i+1]*2^1 )<……(a[i+k] *2^k )的子数组。

先分析一下,这个子数组是按照顺序每个元素乘上2的i次方,并且数组要乘递增形式,因为乘上2的i次幂后,i+1的数比i的数多乘一个2,也就是说i+1的数之前至少要大于i的一半,不然便不能满足严格递增的要求。

那么我们遍历一遍数组,只要当前元素是前一个数的一半还大,我们就把这个数记作1,反之记作0,然后我们只要找区间长度为k+1,且区间和为k+1的区间即可。注意,每个区间的第一个数必然是0,在判断区间和的时候,如果区间第一个数原来记作0,也要暂时改成1。至于快速算区间和,用线段树或前缀和都可以,这里为了方便写的是前缀和。

AC代码
#include
using namespace std;
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

#define endl '\n'
#define int ll
typedef long long ll;
typedef unsigned long long ull;
typedef pairPII;
const int N = 2e5 + 50;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
    {
        int n,k;
        cin >> n >> k;
        vectorv(n+1),ans(n+1),sum(n+1);
        for (int i = 1; i <= n; i++)
        {
            cin >> v[i];
            if (v[i] > v[i - 1] / 2)
            {
                ans[i] = 1;
            }
            sum[i] = sum[i - 1] + ans[i];
        }
        int res = 0;
        for (int i = k+1; i <= n; i++)
        {
            int r = sum[i], l = sum[i - k - 1];
            if (i-k!=1&&ans[i - k] == 0)r++;
            if (r - l >= k + 1)res++;
        }
        cout << res << endl;
    }
    return 0;
}
Problem - H - Codeforces

Marian is at a casino. The game at the casino works like this.

Before each round, the player selects a number between 1 and 109. After that, a dice with 109 faces is rolled so that a random number between 1 and 109 appears. If the player guesses the number correctly their total money is doubled, else their total money is halved.

Marian predicted the future and knows all the numbers x1,x2,…,xn that the dice will show in the next n rounds.

He will pick three integers a, l and r (l≤r). He will play r−l+1 rounds (rounds between l and r inclusive). In each of these rounds, he will guess the same number a. At the start (before the round l) he has 1 dollar.

Marian asks you to determine the integers a, l and r (1≤a≤109, 1≤l≤r≤n) such that he makes the most money at the end.

Note that during halving and multiplying there is no rounding and there are no precision errors. So, for example during a game, Marian could have money equal to 1/1024, 1/128, 1/2, 1, 2, 4, etc. (any value of 2t, where t is an integer of any sign).

Input

The first line contains a single integer t (1≤t≤100) — the number of test cases.

The first line of each test case contains a single integer n (1≤n≤2⋅105) — the number of rounds.

The second line of each test case contains n integers x1,x2,…,xn (1≤xi≤109), where xi is the number that will fall on the dice in the i-th round.

It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.

Output

For each test case, output three integers a, l, and r such that Marian makes the most amount of money gambling with his strategy. If there are multiple answers, you may output any of them.

Example input
4
5
4 4 3 4 4
5
11 1 11 1 11
1
1000000000
10
8 8 8 9 9 6 6 9 6 6
output
4 1 5
1 2 2
1000000000 1 1
6 6 10
问题解析

这题是说有一个游戏,每次会随机出现一个1~10^9的数,你能猜出这个数,你的金币就能翻倍,反之减半,你现在知道了未来n轮出现的数,现在你在一个时间段内一直只买一个数,一开始只有一个金币,要你在这个时间段挣的钱最多,输出买的数和这个时间段的开始与结束坐标。

其实这题类似dp的经典问题:最大子段和。我们每次可以枚举一个数,相同的数当作1,其余的数都是-1,求一下最大子段和就行,记录下最大子段和出现在哪个区间,且是枚举的哪个元素就行。但正常写法是在这里是n^2,不行,所以我们要换一种写法。

我们把所有相同的数都存入一个vector里,然后对这些vector求最大子段和即可(省去了一点点遍历的过程),这些vector的总长度为n,求最大子段和的时间复杂度是On。

AC代码
#include
using namespace std;
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

#define endl '\n'
#define int ll
typedef long long ll;
typedef unsigned long long ull;
typedef pairPII;
const int N = 2e5 + 50;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        vectorv(n+1);
        map>mymap;
        for (int i = 1; i <= n; i++)
        {
            cin >> v[i];
            mymap[v[i]].push_back(i);
        }
        int res = 0, lx = -1, rx = -1, ans = -1;
        for (auto i : mymap)
        {
            int len = i.second.size();
            int x = 1, l = i.second[0], r = i.second[0];
            for (int j = 1; j < len; j++)
            {
                if (i.second[j] - l + 1 - (x + 1) < x + 1)
                {
                    x++;
                    r = i.second[j];
                    if (res < x-(r-l+1-x))
                    {
                        res = x-(r-l+1-x);
                        lx = l;
                        rx = r;
                        ans = i.first;
                    }
                }
                else
                {
                    if (res < x - (r - l + 1 - x))
                    {
                        res = x;
                        lx = l;
                        rx = r;
                        ans = i.first;
                        
                    }
                    l = i.second[j], r = i.second[j], x = 1;
                }
            }
            if (res < x - (r - l + 1 - x))
            {
                res = x-(r-l+1-x);
                lx = l;
                rx = r;
                ans = i.first;  
            }
        }
        cout << ans << " " << lx << " " << rx << endl;
    }
    return 0;
}

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1498177.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-25
下一篇 2022-06-25

发表评论

登录后才能评论

评论列表(0条)

保存