#P10096. [ROIR 2023] 扫地机器人 (Day 1)

    ID: 10754 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>线段树2023离散化Special Judge扫描线ROIR(俄罗斯)

[ROIR 2023] 扫地机器人 (Day 1)

Background

Translated from ROIR 2023 D1T3

A cleaning robot is cleaning a 2D coordinate plane. The cleaning robot is a square of side length k×kk\times k, with its sides parallel to the coordinate axes. Initially, the bottom-left corner of the robot is at (0,0)(0,0), and the top-right corner is at (k,k)(k,k).

Problem Description

You are given a sequence of nn move operations. The ii-th move operation consists of a direction did_i (N means up, increasing the yy coordinate; E means right, increasing the xx coordinate; W means left, decreasing the xx coordinate; S means down, decreasing the yy coordinate) and a distance aia_i (the distance the robot moves). Based on the given robot moves, compute the total cleaned area (a point is considered cleaned if it has been covered by the robot at least once).

Input Format

The first line contains two integers: the robot size kk and the number of operations nn.

In the next nn lines, each line contains one move operation and the corresponding distance aia_i. The move operation is given by a letter did_i (N for up, E for right, W for left, S for down), and the distance aia_i is an integer.

Output Format

Output the total area cleaned by the robot.

1 5
E 2
N 2
W 4
S 4
E 4
17
3 4
W 2
N 1
W 1
N 2
27

Hint

Sample explanation: The figure below shows the robot movements in the two samples.

Constraints

This problem uses bundled testdata.

Subtask ID Points kk nn aia_i
11 99 =1= 1 10\le 10
22 1010 10\le 10 ^ 100\le 100
33 1111 1000\le 1000 =1= 1
44 88 104\le 10^4 105\le 10^5 =k= k
55 1414 =1= 1 1000\le 1000 109\le 10^9
66 1515 104\le 10^4 ^ ^
77 1616 =1= 1 105\le 10^5
88 1717 104\le 10^4 ^

For 100%100\% of the testdata, 1k1041 \le k \le 10^4, 1n1051 \le n \le 10^5, 1ai1091 \le a_i \le 10^9.

Translated by ChatGPT 5