CF1866E.Elevators of Tamem

省选/NOI-

通过率:0%

时间限制:5.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There is a building named Taman Membeku (shortened as Tamem). The building has NN floors numbered from 11 to NN from bottom to top. The only way to move between floors in the building is to use elevators. There are 33 elevators available in Tamem, namely elevators 11, 22, and 33.

Pak Chanek works as an elevator operator in Tamem. Pak Chanek will work for QQ days. Initially, each elevator is in floor 11 and all elevators are on. On each day, exactly one of the following will happen:

  • 1 x y – There is a person currently in floor xx who wants to go to floor yy. (1≤x,y≤N1\leq x,y\leq N; x≠yx\neq y)
  • 2 p – Elevator pp changes state at the start of the day. If previously it is on, then it will turn off. If previously it is off, then it will turn on. (1≤p≤31\leq p\leq3)

For each day, Pak Chanek can control the movement of all elevators as he pleases. However, for each day where there is a person currently in floor xx who wants to go to floor yy, among all elevator movements done by Pak Chanek, the following must happen:

  1. One elevator moves to floor xx.
  2. The person gets into the elevator.
  3. The elevator moves to floor yy.
  4. The person gets out of the elevator.

For each day, Pak Chanek can only move the elevators that are currently on. Note that, since a change in state happens at the start of the day, this means that an elevator that turns off on some day starts becoming unusable from that day itself. Conversely, an elevator that turns on on some day starts becoming usable from that day itself.

It is known that the electricity fee for each day is different. More specifically, on the jj-th day, the fee needed to move one elevator up or down by one floor is AjA_j.

From the start, Pak Chanek already knows the electricity fees and the sequence of events that will happen on the QQ days, so Pak Chanek can operate the elevators strategically. What is the minimum possible electricity fee to fulfill all needs of the people who want to move between floors in Tamem? Note: in the end, each elevator does not have to go back to floor 11.

有一栋名为“Taman Membeku”(简称 Tamem)的大楼。该大楼共有 NN 层,自下而上编号为 11 至 NN。大楼内楼层之间唯一的通行方式是乘坐电梯。Tamem 大楼内共有 33 部电梯,分别称为电梯 11、电梯 22 和电梯 33。

Pak Chanek 是 Tamem 大楼的一名电梯操作员。他将连续工作 QQ 天。初始时,每部电梯均位于第 11 层,且全部处于开启状态。每天恰好发生以下两种事件之一:

  • 1 x y —— 当前有一个人在第 xx 层,希望前往第 yy 层。(1≤x,y≤N1\leq x,y\leq N;x≠yx\neq y)
  • 2 p —— 在当天开始时,电梯 pp 的开关状态发生切换:若之前处于开启状态,则变为关闭;若之前处于关闭状态,则变为开启。(1≤p≤31\leq p\leq3)

每天 Pak Chanek 均可自由控制所有电梯的运行。但若当天发生了“有一个人在第 xx 层希望前往第 yy 层”的事件,则 Pak Chanek 所进行的所有电梯移动中,必须满足以下过程:

  1. 某一部电梯移动至第 xx 层;
  2. 该人进入该电梯;
  3. 该电梯从第 xx 层移动至第 yy 层;
  4. 该人离开该电梯。

此外,每天 Pak Chanek 只能移动当前处于开启状态的电梯。注意:由于状态切换发生在当天开始时,因此某天被关闭的电梯从当天起即不可用;反之,某天被开启的电梯也从当天起即可使用。

已知每天的电费各不相同。具体而言,在第 jj 天,使一部电梯向上或向下移动一层所需的电费为 AjA_j。

从一开始,Pak Chanek 就已知晓全部 QQ 天的电费序列及每日发生的事件序列,因此他可以战略性地调度电梯。问:为满足 Tamem 大楼中所有人员的楼层间通行需求,所需支付的最小总电费是多少?
注:最终,各电梯无需返回第 11 层。

输入格式

The first line contains two integers NN and QQ (2≤N≤1052\leq N\leq10^5; 1≤Q≤3001\leq Q\leq300) — the number of floors and the number of days.

The second line contains QQ integers A1,A2,A3…,AQA_1, A_2, A_3 \ldots, A_Q (1≤Aj≤1051 \leq A_j \leq 10^5) — the electricity fee for each day.

The jj-th of the next QQ lines contains the jj-th event as described. At any moment, there will always be at least one elevator that is on.

第一行包含两个整数 NN 和 QQ(2≤N≤1052\leq N\leq10^5;1≤Q≤3001\leq Q\leq300)——分别为楼层数与天数。

第二行包含 QQ 个整数 A1,A2,A3…,AQA_1, A_2, A_3 \ldots, A_Q(1≤Aj≤1051 \leq A_j \leq 10^5)——表示每一天的电费。

接下来的 QQ 行中,第 jj 行描述第 jj 个事件。在任意时刻,总至少有一部电梯处于运行状态。

输出格式

An integer representing the minimum possible electricity fee to fulfill all needs of the people who want to move between floors in Tamem.

一个整数,表示满足塔梅姆所有人员楼层间移动需求所需的最低电费。

输入输出样例

  • 输入#1

    9 8
    3 4 4 3 4 2 7 6
    1 2 7
    1 3 9
    2 2
    1 4 5
    1 3 5
    2 2
    1 7 3
    1 2 1

    输出#1

    114

说明/提示

The following is an example of an optimal strategy:

  1. On the 11-st day:
    • Elevator 22 moves to floor 33.
    • Elevator 33 moves to floor 22, picks the person up, moves to floor 77, then drops the person off.
  2. On the 22-nd day:
    • Elevator 22 picks the person up, moves to floor 99, then drops the person off.
  3. On the 33-rd day:
    • Elevator 22 turns off.
  4. On the 44-th day:
    • Elevator 33 moves to floor 44, picks the person up, moves to floor 55, drops the person off, then moves to floor 33.
  5. On the 55-th day:
    • Elevator 33 picks the person up, moves to floor 55, then drops the person off.
  6. On the 66-th day:
    • Elevator 22 turns on.
    • Elevator 11 moves to floor 22.
    • Elevator 22 moves to floor 77.
  7. On the 77-th day:
    • Elevator 22 picks the person up, moves to floor 33, then drops the person off.
  8. On the 88-th day:
    • Elevator 11 picks the person up, moves to floor 11, then drops the person off.

The total electricity fee for each day from the 11-st day to the 88-th day are 2424, 2424, 00, 1818, 88, 66, 2828, and 66 respectively. Therefore, the total electricity fee for the entire QQ days is 24+24+0+18+8+6+28+6=11424+24+0+18+8+6+28+6=114.

It can be obtained that there is no strategy that requires a smaller electricity fee.

以下是最佳策略的一个示例:

  1. 第 11 天:
    • 电梯 22 移动至 33 楼。
    • 电梯 33 移动至 22 楼,接载乘客,再移动至 77 楼,然后让乘客下车。
  2. 第 22 天:
    • 电梯 22 接载乘客,移动至 99 楼,然后让乘客下车。
  3. 第 33 天:
    • 电梯 22 关闭。
  4. 第 44 天:
    • 电梯 33 移动至 44 楼,接载乘客,再移动至 55 楼,让乘客下车,然后移动至 33 楼。
  5. 第 55 天:
    • 电梯 33 接载乘客,移动至 55 楼,然后让乘客下车。
  6. 第 66 天:
    • 电梯 22 启动。
    • 电梯 11 移动至 22 楼。
    • 电梯 22 移动至 77 楼。
  7. 第 77 天:
    • 电梯 22 接载乘客,移动至 33 楼,然后让乘客下车。
  8. 第 88 天:
    • 电梯 11 接载乘客,移动至 11 楼,然后让乘客下车。

第 11 天至第 88 天每天的电费分别为 2424、2424、00、1818、88、66、2828 和 66。因此,整个 QQ 天的总电费为 24+24+0+18+8+6+28+6=11424+24+0+18+8+6+28+6=114。

可以证明,不存在所需电费更少的策略。

输入解题思路,AI测评打分。不知道怎么写?

首页