A14981 | Desktop Rearrangement
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Your friend Ivan asked you to help him rearrange his desktop. The desktop can be represented as a rectangle matrix of size $n \times m$ consisting of characters '.' (empty cell of the desktop) and '\*' (an icon).
The desktop is called good if all its icons are occupying some prefix of full columns and, possibly, the prefix of the next column (and there are no icons outside this figure). In other words, some amount of first columns will be filled with icons and, possibly, some amount of first cells of the next (after the last full column) column will be also filled with icons (and all the icons on the desktop belong to this figure). This is pretty much the same as the real life icons arrangement.
In one move, you can take one icon and move it to any empty cell in the desktop.
Ivan loves to add some icons to his desktop and remove them from it, so he is asking you to answer $q$ queries: what is the minimum number of moves required to make the desktop good after adding/removing one icon?
Note that queries are permanent and change the state of the desktop.
The desktop is called good if all its icons are occupying some prefix of full columns and, possibly, the prefix of the next column (and there are no icons outside this figure). In other words, some amount of first columns will be filled with icons and, possibly, some amount of first cells of the next (after the last full column) column will be also filled with icons (and all the icons on the desktop belong to this figure). This is pretty much the same as the real life icons arrangement.
In one move, you can take one icon and move it to any empty cell in the desktop.
Ivan loves to add some icons to his desktop and remove them from it, so he is asking you to answer $q$ queries: what is the minimum number of moves required to make the desktop good after adding/removing one icon?
Note that queries are permanent and change the state of the desktop.
输入格式
The first line of the input contains three integers $n$ , $m$ and $q$ ( $1 \le n, m \le 1000; 1 \le q \le 2 \cdot 10^5$ ) — the number of rows in the desktop, the number of columns in the desktop and the number of queries, respectively.
The next $n$ lines contain the description of the desktop. The $i$ -th of them contains $m$ characters '.' and '\*' — the description of the $i$ -th row of the desktop.
The next $q$ lines describe queries. The $i$ -th of them contains two integers $x_i$ and $y_i$ ( $1 \le x_i \le n; 1 \le y_i \le m$ ) — the position of the cell which changes its state (if this cell contained the icon before, then this icon is removed, otherwise an icon appears in this cell).
The next $n$ lines contain the description of the desktop. The $i$ -th of them contains $m$ characters '.' and '\*' — the description of the $i$ -th row of the desktop.
The next $q$ lines describe queries. The $i$ -th of them contains two integers $x_i$ and $y_i$ ( $1 \le x_i \le n; 1 \le y_i \le m$ ) — the position of the cell which changes its state (if this cell contained the icon before, then this icon is removed, otherwise an icon appears in this cell).
输出格式
Print $q$ integers. The $i$ -th of them should be the minimum number of moves required to make the desktop good after applying the first $i$ queries.
输入输出样例
输入 #1
4 4 8 ..** .*.. *... ...* 1 3 2 3 3 1 2 3 3 4 4 3 2 3 2 2
输出 #1
3 4 4 3 4 5 5 5
输入 #2
2 5 5 *...* ***** 1 3 2 2 1 3 1 5 2 3
输出 #2
2 3 3 3 2
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted