Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >Codeforces 1291 Round #616 (Div. 2) B

Codeforces 1291 Round #616 (Div. 2) B

作者头像
风骨散人Chiam
发布于 2020-10-29 04:40:25
发布于 2020-10-29 04:40:25
89700
代码可运行
举报
文章被收录于专栏:CSDN旧文CSDN旧文
运行总次数:0
代码可运行

B. Array Sharpening time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output You’re given an array a1,…,an of n non-negative integers.

Let’s call it sharpened if and only if there exists an integer 1≤k≤n such that a1<a2<…ak+1>…>an. In particular, any strictly increasing or strictly decreasing array is sharpened. For example:

The arrays [4], [0,1], [12,10,8] and [3,11,15,9,7,4] are sharpened; The arrays [2,8,2,8,6,5], [0,1,1,0] and [2,5,6,9,8,8] are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any i (1≤i≤n) such that ai>0 and assign ai:=ai−1.

Tell if it’s possible to make the given array sharpened using some number (possibly zero) of these operations.

Input The input consists of multiple test cases. The first line contains a single integer t (1≤t≤15 000) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer n (1≤n≤3⋅105).

The second line of each test case contains a sequence of n non-negative integers a1,…,an (0≤ai≤109).

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

Output For each test case, output a single line containing “Yes” (without quotes) if it’s possible to make the given array sharpened using the described operations, or “No” (without quotes) otherwise.

Example inputCopy 10 1 248618 3 12 10 8 6 100 11 15 9 7 8 4 0 1 1 0 2 0 0 2 0 1 2 1 0 2 1 1 3 0 1 0 3 1 0 1 outputCopy Yes Yes Yes No No Yes Yes Yes Yes No Note In the first and the second test case of the first test, the given array is already sharpened.

In the third test case of the first test, we can transform the array into [3,11,15,9,7,4] (decrease the first element 97 times and decrease the last element 4 times). It is sharpened because 3<11<15 and 15>9>7>4.

In the fourth test case of the first test, it’s impossible to make the given array sharpened.

这个题考虑不能构成的情况,就是从这数左边不能构成,右边也不能构成。然后左右都可以的时候,中间两个可能相等不能构成左右。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#include <bits/stdc++.h>
using namespace std;
int a[300010];
int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        int n;
        cin>>n;
        bool bk = true;
        for (int i = 1; i <= n; i++)
            cin>>a[i] ;
        for (int i = 1; i <= n; i++)
            if (a[i] < min(i - 1, n - i))
            {
                bk = false;
                break;
            }
        if (n % 2 == 0 && max(a[n / 2], a[n / 2 + 1]) < n / 2)
        {
            bk = false;
        }
        if (bk == false)
            puts("No");
        else
            puts("Yes");
    }
    return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020/02/04 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
Codeforces Round #624 (Div. 3) B - WeirdSort
You are also given a set of distinct positions p1,p2,…,pmp1,p2,…,pm, where 1≤pi<n1≤pi<n. The position pipi means that you can swap elements a[pi]a[pi] and a[pi+1]a[pi+1]. You can apply this operation any number of times for each of the given positions.
glm233
2020/09/28
5430
Codeforces 1291 Round #616 (Div. 2) C. Mind Control(超级详细)
You and your n−1 friends have found an array of integers a1,a2,…,an. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
风骨散人Chiam
2020/10/29
3810
Codeforces 1291  Round #616 (Div. 2) C. Mind Control(超级详细)
Codeforces Round #618 (Div. 2)-B. Assigning to Classes
Reminder: the median of the array [a1,a2,…,a2k+1] of odd number of elements is defined as follows: let [b1,b2,…,b2k+1] be the elements of the array in the sorted order. Then median of this array is equal to bk+1. There are 2n students, the i-th student ha
风骨散人Chiam
2020/10/29
5990
Codeforces Round #619 (Div. 2)
A 题目 You are given three strings a, b and c of the same length n. The strings consist of lowercase English letters only. The i-th letter of a is ai, the i-th letter of b is bi, the i-th letter of c is ci.
杨鹏伟
2020/09/11
3910
Codeforce1311B. WeirdSort (冒泡排序)
You are also given a set of distinct positions p1,p2,…,pm, where 1≤pi<n. The position pi means that you can swap elements a[pi] and a[pi+1]. You can apply this operation any number of times for each of the given positions.
风骨散人Chiam
2020/10/29
4450
Codeforces Round #613 (Div. 2)B. Just Eat It!
Today, Yasser and Adel are at the shop buying cupcakes. There are nn cupcake types, arranged from 11 to nn on the shelf, and there are infinitely many of each type. The tastiness of a cupcake of type ii is an integer aiai. There are both tasty and nasty cupcakes, so the tastiness can be positive, zero or negative.
glm233
2020/09/28
4480
Codeforces Round #623 (Div. 2, based on VK Cup 2019-2020 - Elimination Round, Engine) C. Restoring
C. Restoring Permutation time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output You are given a sequence b1,b2,…,bn. Find the lexicographically minimal permutation a1,a2,…,a2n such that bi=min(a2i−1,a2i), or determine that it is impossible.
风骨散人Chiam
2020/10/29
5580
Codeforce 1255 Round #601 (Div. 2)B. Fridge Lockers(思维)
Hanh lives in a shared apartment. There are nn people (including Hanh) living there, each has a private fridge.
风骨散人Chiam
2020/10/28
4610
Codeforce 1255 Round #601 (Div. 2)B. Fridge Lockers(思维)
Codeforces Round #633 (Div. 2)C Powered Addition (贪心,二进制)
You have an array aa of length nn. For every positive integer xx you are going to perform the following operation during the xx-th second:
glm233
2020/09/28
3530
Codeforces Round #605 (Div. 3) D. Remove One Element
You are given an array aa consisting of nn integers.
glm233
2020/09/28
5110
Codeforces Round #395 (Div. 2)(A.思维,B,水)
A. Taymyr is calling you time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist. Ili
Angel_Kitty
2018/04/08
7820
Codeforces Round #618 (Div. 2)-Non-zero
这个题是说通过最小的修改次数,是数列和不能为0,乘积不能为0; 那么也即数列中不存在0,如果存在0的一定要改,存在0的只能变成1,那我们考虑变成1之后,的和是否等于0,如果等于,就在修改1个,即cnt+1。
风骨散人Chiam
2020/10/29
3650
Codeforces Round #633 (Div. 2) B Sorted Adjacent Differences(直观感知+排序插放)
You have array of nn numbers a1,a2,…,ana1,a2,…,an.
glm233
2020/09/28
5700
Codeforce-CodeCraft-20 (Div. 2)-A. Grade Allocation
n students are taking an exam. The highest possible score at this exam is m. Let ai be the score of the i-th student. You have access to the school database which stores the results of all students.
风骨散人Chiam
2020/10/28
3820
一道有顶点的数组题 - 贪心算法
Let's call it sharpened if and only if there exists an integer 1≤k≤n such that a1<a2<…ak+1>…>an. In particular, any strictly increasing or strictly decreasing array is sharpened. For example:
ACM算法日常
2020/02/17
4490
Codeforces Round #559 (Div. 2)B. Expansion coefficient of the array
Let's call an array of non-negative integers a1,a2,…,ana1,a2,…,an a kk-extension for some non-negative integer kk if for all possible pairs of indices 1≤i,j≤n1≤i,j≤n the inequality k⋅|i−j|≤min(ai,aj)k⋅|i−j|≤min(ai,aj) is satisfied. The expansion coefficient of the array aa is the maximal integer kk such that the array aa is a kk-extension. Any array is a 0-expansion, so the expansion coefficient always exists.
glm233
2020/09/28
6230
Codeforce 1255 Round #601 (Div. 2) A. Changing Volume (贪心)
Bob watches TV every day. He always sets the volume of his TV to bb. However, today he is angry to find out someone has changed the volume to aa. Of course, Bob has a remote control that can change the volume.
风骨散人Chiam
2020/10/28
4150
Codeforces Round #416 (Div. 2)(A,思维题,暴力,B,思维题,暴力)
A. Vladik and Courtesy time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output At regular competition Vladik and Valera won a and b candies respectively. Vladik offered 1 his candy to Valera. After that
Angel_Kitty
2018/04/09
8870
Codeforces Round #416 (Div. 2)(A,思维题,暴力,B,思维题,暴力)
Codeforces Round #483 (Div. 2) D. XOR-pyramid
For an array bb of length mm we define the function ff as
用户2965768
2018/08/30
5640
Codeforces Round #615 (Div. 3)A. Collecting Coins
Polycarp has three sisters: Alice, Barbara, and Cerene. They're collecting coins. Currently, Alice has aa coins, Barbara has bb coins and Cerene has cc coins. Recently Polycarp has returned from the trip around the world and brought nn coins.
glm233
2020/09/28
6150
推荐阅读
相关推荐
Codeforces Round #624 (Div. 3) B - WeirdSort
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验