当前位置:网站首页>BZOJ3189 : [Coci2011] Slika
BZOJ3189 : [Coci2011] Slika
2022-06-11 21:18:00 【dplovetree】
Slika
题意:

首先,题目有一个外衣,就是操作有版本的概念,他会进行存档和读档操作,但是我们知道,我们把操作建成一个树,他读档就是回到一个祖先,而对最终形态有影响的只有当前点到根的叠加操作。
那么我们就建一棵树,维护一个fa数组,最后不断跳祖先就知道了有效操作及顺序。
做法一:
用并查集维护当前行没染色的最右边的点。
我们把操作,逆序搞,因为后面染色的会覆盖前面染色的操作。
然后呢对于一段染过色的区间是不会被重复遍历的。
那么总的复杂度就是( m ∗ n + n ∗ n m*n+n*n m∗n+n∗n)。
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n,m) for(int i=n;i<=m;i++)
#define repp(i,n,m) for(int i=n;i>=m;i--)
int n,k,m;
char op[10];
int sa[100040];
int cnts=0,tot=0;
struct node{
int cl;
int x1,y1,x2,y2;
}z[100040];
queue<int>q;
int f[100050];
int fa[1010][1010];
int col[1004][1004];
int find(int x,int i){
if(x==fa[i][x])return x;
return fa[i][x]=find(fa[i][x],i);
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>n>>k>>m;
int now=0;
for(int i=1;i<=m;i++){
cin>>op;
if(op[0]=='P'){
tot++;
cin>>z[tot].cl>>z[tot].x1>>z[tot].y1>>z[tot].x2>>z[tot].y2;
f[tot]=now;
now=tot;
}else if(op[0]=='S'){
cnts++;
sa[cnts]=now;
}else{
int a;
cin>>a;
now=sa[a];
}
}
for(int i=0;i<n+2;i++){
for(int j=0;j<n+2;j++)col[i][j]=1,fa[i][j]=j;
}
while(now){
int u=now;
for(int i=z[u].x1;i<=z[u].x2;i++){
int p;
if((i-z[u].x1)%2==0)p=find(z[u].y1,i);
else p=find(z[u].y1+1,i);
for(int j=p;j<=z[u].y2;j=find(j+2,i)){
fa[i][j]=j+2;
col[i][j]=z[u].cl;
}
}
now=f[now];
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++)cout<<col[i][j]<<" ";
cout<<"\n";
}
return 0;
}
做法二:
边栏推荐
- table_ Display status
- 第一部分 物理层
- [advanced C language] integer storage in memory
- BUG -- coredump使用
- Flutter implements the JD address selection component
- 电竞网咖用2.5G网卡,体验飞一般的感觉!
- Application analysis of Poe image acquisition card in machine vision industrial computer
- Deriving Kalman filter from probability theory
- 关于gorm的preload方法笔记说明
- 使用 float 创建一个网页页眉、页脚、左边的内容和主要内容。
猜你喜欢

Explanation of each column output by explain statement

【博弈论-完全信息静态博弈】 战略式博弈

Release of version 5.6 of rainbow, add multiple installation methods, and optimize the topology operation experience

The gateway starts other microservices first. When the gateway is started, the gateway cannot be started and there is no exception log; Start the gateway first, and all services can be started normall

Network security Kali penetration learning introduction to web penetration using MSF penetration to attack win7 host and execute commands remotely

【C語言進階】整型在內存中的存儲

频域滤波器

Why should I use iwarp, roce V2, nvme of and other protocols for 100g network transmission

Tensorflow 2. X Getting Started tutorial

Frequency domain filter
随机推荐
JS performs non empty judgment on various data types of the returned data.
全球机器视觉市场规模持续上涨,PoE图像采集卡为工业相机提供高速传输通道
【博弈论-绪论】
【数据可视化】使用 Apache Superset 可视化 ClickHouse 数据
为什么需要微服务
Network security Kali penetration learning introduction to web penetration using MSF penetration to attack win7 host and execute commands remotely
A collection of commonly used open source data sets for face recognition
Codeforces Round #742 (Div. 2) F. One-Four Overload
数据库每日一题---第9天:销售员
A man always becomes a man and a man always arrives (progress, harvest, growth, self-confidence)
How to manually drag nodes in the Obsidian relationship graph
Flutter implements the JD address selection component
重投农业,加码技术服务,拼多多底盘进一步夯实
Mysql add 新增多个新字段并指定字段位置
[data visualization] use Apache superset to visualize Clickhouse data
Live broadcast with practice | 30 minutes to build WordPress website with Alibaba cloud container service and container network file system
Stream Chinese sorting
Realize the same length of tablayout subscript and text, and change the selected font size
Goland中在文件模板中为go文件添加个人声明
【博弈论-完全信息静态博弈】 战略式博弈