Compare commits

...

2 Commits

Author SHA1 Message Date
e48cc83bfb docs: 更新README.md添加找规律章节
添加找规律章节内容,包括列出规则、模拟样例和自己构造样例的方法
2025-10-27 22:07:06 +08:00
90fee25d70 feat: 添加P9117.cpp实现网格颜色更新功能
实现一个处理网格颜色更新的解决方案,根据输入操作更新行和列的颜色,并输出最终网格状态。支持多测试用例处理。
2025-10-27 20:05:44 +08:00
2 changed files with 55 additions and 0 deletions

View File

@ -1,3 +1,5 @@
# 算法笔记
## P6476 题解易错点
@ -6,6 +8,11 @@
2. **清空操作优化**每次使用后需要清空tot数组但直接memset会超时改用标记数组记录修改位置
3. **下标偏移**结构体T使用of常量处理负数下标数组大小需要*2
4. **状态转移公式**注意容斥原理的应用dp[i][j] = 当前三元组数 + 子区间累计值 - 重复部分
## 找规律
* 列出所有规则
* 模拟所有样例
* 样例不够自己凑
## 线性动态规划优化为$O(n\log{n})$方法
>如果是递增序列就lower_bound

48
src/10/27/P9117.cpp Normal file
View File

@ -0,0 +1,48 @@
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <istream>
using ll = int64_t;
const ll maxn = 1e5+7;
struct S{
ll c,t;
inline bool operator<(const S&other)const{
return t<other.t;
}
}h[maxn],l[maxn];
ll n,m,q;
static inline void solve(){
std::cin>>n>>m>>q;
for(ll i=1;i<=n;i++)h[i]={0,0};
for(ll i=1;i<=m;i++)l[i]={0,0};
for(ll i=1;i<=q;i++){
ll opt,x,c;
std::cin>>opt>>x>>c;
if(opt==0){
h[x]={c,i};
}else{
l[x]={c,i};
}
}
for(ll i=1;i<=n;i++){
for(ll j=1;j<=m;j++){
if(h[i].c==0&&l[j].c==0){
std::cout<<"0 ";
continue;
}
std::cout<<std::max(h[i],l[j]).c<<" ";
}
std::cout<<"\n";
}
}
int main(){
std::iostream::sync_with_stdio(false);
std::cin.tie(nullptr);
ll T;
std::cin>>T;
while(T--)solve();
}