QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 1024 MB Total points: 100

#15821. Where the Lantern Lights are Dimming

统计

元宵灯会上展出了许多花灯。在夜幕中,它们投下美丽的影子和倒影,吸引了无数游客往来观赏。由于同时展出的花灯数量众多,无法一一展现每盏灯的独特之处。因此,主办方会轮流开启部分花灯,同时关闭其他花灯。在任何时刻,总有一些花灯处于点亮状态,而另一些则处于熄灭状态。此外,有些花灯因故障而永久熄灭,失去了闪耀的机会。

为了让游客参与到元宵灯会中,主办方还举办了评分活动。如果游客对灯会非常满意,他们将获得一包每张 3 分的贴纸,并会在每盏正在展出的花灯上贴上一张 3 分贴纸。如果他们感到满意,将获得一包 1 分的贴纸,并会在每盏正在展出的花灯上贴上一张。如果他们对灯会感到失望,将获得一包 -2 分的贴纸,并会在每盏正在展出的花灯上贴上一张。换句话说,那些处于熄灭状态且未点亮的花灯将没有机会从该游客处获得任何贴纸。灯会结束后,请编写一个程序来计算所有花灯上贴纸的总分。

输入格式

输入的第一行包含两个整数 $n$ 和 $m$。接下来的 $n$ 行描述了编号从 $0$ 到 $n - 1$ 的 $n$ 盏花灯的初始状态。每行包含两个整数:$s_i$ 和 $p_i$。$s_i$ 表示花灯的状态:

  • $1$ 表示第 $i$ 盏花灯初始为开启状态,
  • $0$ 表示其为关闭状态,
  • $-1$ 表示其已损坏(意味着它永久关闭且无法被开启)。

$p_i$ 表示第 $i$ 盏花灯上已有的贴纸总分。

接下来的 $m$ 行按时间顺序给出了 $m$ 个事件,每个事件对应以下两种类型之一:切换或评分。

  • 以字母 W 开头的行表示切换事件。后面跟着两个整数 $l_j$ 和 $r_j$,表示编号在 $[l_j, r_j]$(包含边界)范围内的花灯状态将被切换。
  • 以字母 C 开头的行表示游客的评分事件。这些行后面跟着一个整数 $q_j \in \{-2, 1, 3\}$,表示游客给出的贴纸分数。每盏当前处于点亮状态的花灯都会从该游客处获得一张分数为 $q_j$ 的贴纸。

输出格式

输出一个整数,表示灯会结束后所有花灯上的贴纸总分。

数据范围

  • $1 \le n \le 1,000,000$
  • $1 \le m \le 1,000,000$
  • $s_i \in \{-1, 0, 1\}$
  • $-10,000 \le p_i \le 10,000$
  • $0 \le l_j \le r_j < n$
  • $q_j \in \{-2, 1, 3\}$

样例

输入 1

3 3
0 0
0 0
0 0
W 0 2
W 1 1
C 3

输出 1

6

输入 2

5 5
1 5
0 0
-1 2
1 0
0 -2
C 1
W 0 4
C -2
W 1 3
C 3

输出 2

9

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.