Loading [MathJax]/jax/output/CommonHTML/config.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
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
87500
代码可运行
举报
文章被收录于专栏: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 #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
4300
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
4190
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
3300
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
6090
Codeforces Round #624 (Div. 3) A - Add Odd or Subtract Even
You are given two positive integers aa and bb.
glm233
2020/09/28
5080
Educational Codeforces Round 81 (Rated for Div. 2) B - Infinite Prefixes
You are given string s of length nn consisting of 0-s and 1-s. You build an infinite string t as a concatenation of an infinite number of strings s, or t=ssss…t=ssss… For example, if s= 10010, then t= 100101001010010...
glm233
2020/09/28
4030
Educational Codeforces Round 81 (Rated for Div. 2)  B - Infinite Prefixes
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
8580
Codeforces Round #416 (Div. 2)(A,思维题,暴力,B,思维题,暴力)
Educational Codeforces Round 81 (Rated for Div. 2)
B. Infinite Prefixes 无限前缀 You are given string ? of length ? consisting of 0-s and 1-s. You build an
ACM算法日常
2020/02/17
3750
Educational Codeforces Round 81 (Rated for Div. 2)
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
5860
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
3950
Codeforces Round #FF (Div. 2):C. DZY Loves Sequences[通俗易懂]
DZY has a sequence a, consisting of n integers.
全栈程序员站长
2022/07/08
2250
一道有顶点的数组题 - 贪心算法
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
4270
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
3590
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
5240
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
3610
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
5770
Codeforces Round #618 (Div. 2)-Non-zero
这个题是说通过最小的修改次数,是数列和不能为0,乘积不能为0; 那么也即数列中不存在0,如果存在0的一定要改,存在0的只能变成1,那我们考虑变成1之后,的和是否等于0,如果等于,就在修改1个,即cnt+1。
风骨散人Chiam
2020/10/29
3520
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
4770
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
4370
Codeforce 1255 Round #601 (Div. 2)B. Fridge Lockers(思维)
Codeforces Round #633 (Div. 2) B Sorted Adjacent Differences(直观感知+排序插放)
You have array of nn numbers a1,a2,…,ana1,a2,…,an.
glm233
2020/09/28
5460
推荐阅读
相关推荐
Codeforces Round #613 (Div. 2)B. Just Eat It!
更多 >
领券
💥开发者 MCP广场重磅上线!
精选全网热门MCP server,让你的AI更好用 🚀
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验