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
89200
代码可运行
举报
文章被收录于专栏: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 删除。

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

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
一道有顶点的数组题 - 贪心算法
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
4400
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
3840
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
5390
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
3750
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
5930
Codeforces Round #618 (Div. 2)-Non-zero
这个题是说通过最小的修改次数,是数列和不能为0,乘积不能为0; 那么也即数列中不存在0,如果存在0的一定要改,存在0的只能变成1,那我们考虑变成1之后,的和是否等于0,如果等于,就在修改1个,即cnt+1。
风骨散人Chiam
2020/10/29
3600
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
4410
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
4360
Codeforces Round #624 (Div. 3) D.Three Integers
In one move, you can add +1+1 or −1−1 to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero) number of times, you can even perform this operation several times with one number. Note that you cannot make non-positive numbers using such operations.
glm233
2020/09/28
4870
Codeforces Round #633 (Div. 2) B Sorted Adjacent Differences(直观感知+排序插放)
You have array of nn numbers a1,a2,…,ana1,a2,…,an.
glm233
2020/09/28
5630
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
3460
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
4530
Codeforce 1255 Round #601 (Div. 2)B. Fridge Lockers(思维)
CodeForces - 1245 B - Restricted RPS(贪心)
Let nn be a positive integer. Let a,b,ca,b,c be nonnegative integers such that a+b+c=na+b+c=n.
风骨散人Chiam
2020/10/28
4480
Codeforces Beta Round #72 (Div. 1 Only)B. Doctor
There are n animals in the queue to Dr. Dolittle. When an animal comes into the office, the doctor examines him, gives prescriptions, appoints tests and may appoint extra examination. Doc knows all the forest animals perfectly well and therefore knows exactly that the animal number i in the queue will have to visit his office exactly ai times. We will assume that an examination takes much more time than making tests and other extra procedures, and therefore we will assume that once an animal leaves the room, it immediately gets to the end of the queue to the doctor. Of course, if the animal has visited the doctor as many times as necessary, then it doesn't have to stand at the end of the queue and it immediately goes home.
glm233
2020/09/28
3590
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
5530
Codeforces Round #624 (Div. 3) C - Perform the Combo
You want to perform the combo on your opponent in one popular fighting game. The combo is the string ss consisting of nn lowercase Latin letters. To perform the combo, you have to press all buttons in the order they appear in ss. I.e. if s=s="abca" then you have to press 'a', then 'b', 'c' and 'a' again.
glm233
2020/09/28
6760
AIM Tech Round 4 (Div. 2)(A,暴力,B,组合数,C,STL+排序)
A. Diversity time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters, or pr
Angel_Kitty
2018/04/09
6950
AIM Tech Round 4 (Div. 2)(A,暴力,B,组合数,C,STL+排序)
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
7730
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
6200
Codeforces Round #624 (Div. 3) A - Add Odd or Subtract Even
You are given two positive integers aa and bb.
glm233
2020/09/28
5290
推荐阅读
相关推荐
一道有顶点的数组题 - 贪心算法
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验