P3130 [USACO15DEC]计数haybalesCounting Haybales

    • 240通过
    • 785提交
  • 题目提供者 FarmerJohn2
  • 评测方式 云端评测
  • 标签 并查集 排序 离散化 USACO 2015 高性能
  • 难度 提高+/省选-
  • 时空限制 1000ms / 128MB

题解

  • 提示:收藏到任务计划后,可在首页查看。
  • 体验新版界面

    最新讨论 显示

    推荐的相关题目 显示

    题目描述

    Farmer John is trying to hire contractors to help rearrange his farm, but so far all of them have quit when they saw the complicated sequence of instructions FJ wanted them to follow. Left to complete the project by himself, he realizes that indeed, he has made the project perhaps more complicated than necessary. Please help him follow his instructions to complete the farm upgrade.

    FJ's farm consists of $N$ fields in a row, conveniently numbered $1 \ldots N$. In each field there can be any number of haybales. Farmer John's instructions contain three types of entries:

    1) Given a contiguous interval of fields, add a new haybale to each field.

    2) Given a contiguous interval of fields, determine the minimum number of haybales in a field within that interval.

    3) Given a contiguous interval of fields, count the total number of haybales inside that interval.

    FJ像雇佣几个人在他的农场里帮忙,他需要进行很多种操作,请你帮他搞定。

    FJ的农场有N块田地排长一行,编号是从1到N的。每一块田地都有很多草包。FJ要进行下面几种操作:

    1)给定一段连续的田地,给每一个田地都增加一些新的草包。

    2)给定一段连续的田地,找出草包最少的田地有多少草包。

    3)给定一段连续的田地,统计一共有多少草包。

    输入输出格式

    输入格式:

    The first line contains two positive integers, $N$ ($1 \leq N \leq 200,000$) and

    $Q$ ($1 \leq Q \leq 100,000$).

    The next line contains $N$ nonnegative integers, each at most 100,000,

    indicating how many haybales are initially in each field.

    Each of the next $Q$ lines contains a single uppercase letter, either M, P or S,

    followed by either two positive integers $A$ and $B$ ($1 \leq A \leq B \leq N$),

    or three positive integers $A$, $B$, and $C$ ($1 \leq A \leq B \leq N$;

    $1 \leq C \leq 100,000$). There will be three positive integers if and only if

    the uppercase letter is P.

    If the letter is M, print the minimum number of haybales in the interval of fields

    from $A \ldots B$.

    If the letter is P, put $C$ new haybales in each field in the interval of fields

    from $A \ldots B$.

    If the letter is S, print the total number of haybales found within interval of

    fields from $A \ldots B$.

    输出格式:

    A line in the output should appear in response to every 'M' or 'S' entry in FJ's

    instructions.

    输入输出样例

    输入样例#1: 复制
    4 5
    3 1 2 4
    M 3 4
    S 1 3
    P 2 3 1
    M 3 4
    S 1 3
    输出样例#1: 复制
    2
    6
    3
    8
    提示
    标程仅供做题后或实在无思路时参考。
    请自觉、自律地使用该功能并请对自己的学习负责。
    如果发现恶意抄袭标程,将按照I类违反进行处理。