Atcoder A Mountaineer, atcodermountaineer

Source: Internet
Author: User

Atcoder A Mountaineer, atcodermountaineer

Time limit: 2sec/Stack limit: 256 MB/Memory limit: 256 MB

Problem

Dave is a mountaineer. He is now climbing a range of mountains.

On this mountains, there areNHuts located on a straight lining from east to west ..

The huts are numbered sequentially from1ToN. The west most hut is1, The east most hut isN. The I-th hut is located at an elevationHIMeters.

Dave wants to know how many huts he can look down and see from each hut.

He can see the j-th hut from the I-th hut if all huts between the I-th hut and the j-th hut including the j-th one are located at equal or lower elevationHI.

Note that the I-th hut itself is not supported ded in the hut he can see from the I-th hut.

Input

The input will be given in the following format from the Standard Input.

Nh1h2:hN
  • On the first line, you will be givenN(1 hourNListen 105), The number of huts.
  • ThenNLines follow, each of which containsHI(1 hourHIListen 105)The elevation of the I-th hut.
Achievements and Points

Your answer will be checked for two levels.

  • When you pass every test case which satisfies1 TibNLimit 3,000, You will be awarded30Points.
  • In addition, if you pass all the rest test cases which satisfy1 TibNLimit 105, You will be awarded70More points, summed up100Points.
Output

On the I-th line, output the number of huts Dave can see from the I-th hut. Make sure to insert a line break at the end of the output.

Input Example 1
 
 
  1. 3
  2. 1
  3. 2
  4. 3
Output Example 1
 
 
  1. 0
  2. 1
  3. 2

From each hut he can see every huts on the west.

Input Example 2
 
 
  1. 5
  2. 1
  3. 2
  4. 3
  5. 2
  6. 1
Output Example 2
 
 
  1. 0
  2. 1
  3. 4
  4. 1
  5. 0

From the 1st and 5th hut he can't see any other huts.

From the 2nd hut he can only see the 1st hut.

From the 4th hut he can only see the 5th hut.

From the 3rd hut he can see every other huts.

Input Example 3
 
 
  1. 5
  2. 3
  3. 2
  4. 1
  5. 2
  6. 3
Output Example 3
 
 
  1. 4
  2. 2
  3. 0
  4. 2
  5. 4

Note that he can see the huts on the equal elevation.

Input Example 4
 
 
  1. 8
  2. 4
  3. 3
  4. 2
  5. 3
  6. 4
  7. 3
  8. 2
  9. 1
Output Example 4
 
 
  1. 7
  2. 2
  3. 0
  4. 2
  5. 7
  6. 2
  7. 1
  8. 0
Train of Thought: This is a simple question, but I have been facing big data when TLE directly goes to the TLE source code.
import java.util.Scanner; public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int count = sc.nextInt();int num[] = new int[count];int flag[] = new int[count];for (int i = 0; i < count; i++) {num[i] = sc.nextInt();}for (int i = 0; i < count; i++) {for (int j = i - 1; j >= 0 && num[i] >= num[j]; j--,flag[i]++);for (int j = i + 1; j < count && num[i] >= num[j]; j++,flag[i]++);System.out.println(flag[i]); }}}
The following is the AC source code, which has been optimized to some extent based on the above source code. To some extent, some ideas have been changed, which is similar to https://oj.leetcode.com/problems/candy.
import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int count = sc.nextInt();int num[] = new int[count];int[] back = new int[count];int[] forward = new int[count];for (int i = 0; i < count; i++) {num[i] = sc.nextInt();}for (int i = 0; i < count; i++) {for (int j = i - 1; j >= 0 && num[i] >= num[j]; back[i] = back[i]+ back[j] + 1, j = j - back[j] - 1);}for (int i = count - 1; i >= 0; i--) {for (int j = i + 1; j < count && num[i] >= num[j];forward[i] = forward[i]+ forward[j] + 1, j = j + forward[j] + 1);}for (int i = 0; i < count; i++) {System.out.println(back[i] + forward[i]);}}}



Owl city-Chinese lyrics of hello seattle

Hello Seattle, I am a mountaineer
In the hills and highlands
I fall asleep
In hospital parking lots
And awake in your house
Hello Seattle, I am
Manteray
Deep beneathe the blue waves
I'll crawl the sandy bottom of Puget
Sound
And construct a summer home
Hello Seattle, I am the cresant
Moon
Shining down on your face
I will disguise myself as a sleeping
Pill
And descend inside of you
Hello Seattle, I am a cold
Seahorse
Feeling warm in your sand
I sing about the tide and the ocean
Surf
Rolling in the evening breeze
Hello Seattle, I am
Albatross
On the docks and your boats
I sail abve your inlets and
Interstates
Through the rain and open wind
Hello Seattle, I am an old
Lighthouse
Throwing beams of bright lights
Red in the morning, blue in
Evening sun
Taken heed from everyone
Hello Seattle, I am
Mountaineer
In the hills and highlands
I fall asleep in hosp1_parking
Lots
Take me abve your light
Carry me through the night
Hold me
Secure in flight
Sing me to sleep tonight
Take me abve your
Light
Carry me through the night
Hold me secure in flight
Sing me
Sleep tonight
Hi Seattle, I'm a mountain.
Trekking in hills and Highlands
Sleeping in hospital parking lots
Wake up in your mouth
Hello, Seattle, I'm a zookeeper (animal name: The artifactid in the cartilage fish, which is the same as that of the giant fin flying fish)
Deep Dive under the Blue Waves
Crawling on the bottom beach in pujiewan
Build a summer home
Hello, Seattle. I'm a new moon.
Clear the light on your face
I will become a sleeping pill
Fall into your heart
Hi Seattle, I'm a cold seahorse
Warm by your sand
Shake in the evening breeze
Singing the tide and waves
Hello, Seattle. I'm a trustship.
Soar above docks and ships
I glide over your harbor and road
No matter whether the weather blows or the rain
Hello, Seattle. I am an ancient beacon.
Emits bright light
Red in the morning and blue in the evening
Watching everyone
Fly me to your light
Take me through the night
Fly me steadily
Sleeping with me tonight... full text>

(3/6) and mountaineer, had been on a two-day climb away from the others and it Warn' t until la

(1/6) (2/6) (3/6) two teenagers had to be saved from a steep mountain-side in Scotl and earlier today. they were member of a party of youngsters who were in the second week of a fortnight's camping in the mountains. the two boys, both from birmheim, had been with a party of ten others who, with an experienced guide and mountaineer, had been on a two-day climb away from the others and it Warn' t until late yesterday afternoon that the alarm was raised and a search
Two teenagers were rescued from a steep hill in Scotl earlier today. They are both part of a two-week hiking camp for teenagers and are currently in the second week. Both boys are from Birmingham and have been with ten troops. There is also an experienced mountain leader who has been hiking independently from others for two days, however, it was not until yesterday afternoon that an alarm was issued and the search started.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.