#FT0000168. Thay hàng, thay cột và tổng ký tự (Bored of Suffixes and Prefixes)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Thay hàng, thay cột và tổng ký tự (Bored of Suffixes and Prefixes)
Bored of Suffixes and Prefixes
Source: SPOJ
Version: Phước Hưng OJ Extended.
Problem Statement
You are given an matrix of uppercase English letters, with A worth , B worth , ..., Z worth . Process operations:
0 x y s: if , replace row with the string ; if , replace column with the characters of from top to bottom. The string always has length .1 x1 y1 x2 y2: output the sum of letter values in the inclusive rectangle from to .
Rows and columns are 0-indexed. Replacement operations immediately affect all following queries.
Input
The first line contains , followed by uppercase strings of length . The next lines contain either 0 x y s or 1 x1 y1 x2 y2.
Output
Print the sum of letter values for each type-1 operation, one answer per line.
Subtask
- Subtask 1 (20 points): ; ; every matrix row and replacement string has exactly letters
A–Z; , in replacement operations; , in queries. - Subtask 2 (30 points): ; ; every matrix row and replacement string has exactly letters
A–Z; , in replacement operations; , in queries. - Subtask 3 (50 points): ; ; every matrix row and replacement string has exactly letters
A–Z; , in replacement operations; , in queries.
Examples
Example 1
Input
4 3
ABCD
ABCD
ABCD
ABCD
1 0 0 3 3
0 0 2 PQRS
1 0 2 3 3
Output
40
58
Explanation
Initially each row totals , so the full matrix totals . Replacing row 2 by PQRS changes its last two letters to R and S, values 18 and 19. The other three rows contribute over columns 2–3; the new row contributes , yielding .
Example 2
Input
3 6
AAA
BBB
CCC
1 0 0 2 2
0 1 0 XYZ
1 0 0 2 0
0 0 1 AZA
1 1 0 1 2
1 0 1 2 2
Output
18
75
28
35
Explanation
The original matrix totals . Replacing column 0 from top to bottom with XYZ makes that column sum . Replacing row 1 with AZA gives . The last rectangle spans columns 1–2 in all three rows and totals .