当前位置: 首页 > news >正文

P1903 [国家集训队] 数颜色 / 维护队列

带修改的莫队

带修改的莫队就是在基础莫队的基础上增加了一维属性,之前只需要维护l,r现在还需要维护一下时间t,排序还是先按照左端点块儿号排序,然后右端点块儿号排序,最后按时间排序。其它的都是差不多的。

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
//#define x first
//#define y second
//#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
const int mod = 1e9 + 7;
const int N = 1e6+ 10;
int dx[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
int n, m, mc, mq, len;
int o[N], f[N], st[N], res;
//        结果  标记 
struct query{ // 记录询问的列表int l, r, id, t;
}q[N];
struct modify{ // 记录修改操作的列表int x, y;
}c[N];inline int get(int a) // 得到块儿号
{return a / len;
}inline void add(int a) // 增加
{if(!st[a]) res ++;st[a] ++;
}inline void del(int a) // 删除
{st[a] --;if(!st[a]) res --;
}
bool cmp(query a, query b) // 排序
{int ai = get(a.l), aj = get(a.r);int bi = get(b.l), bj = get(b.r);if(ai != bi) return ai < bi; // 按左端点块儿号if(aj != bj) return aj < bj; // 按右端点块儿号return a.t < b.t; // 按时间
}inline void sovle()
{cin >> n >> m;for(int i = 1; i <= n; i ++) cin >> o[i];for(int i = 0; i < m; i ++){char op;int a, b;cin >> op >> a >> b;if(op == 'Q') mq ++, q[mq] = {a, b, mq, mc};else c[++ mc] = {a,  b};}len = pow(n, 0.666); // 怎么分块儿,,,可以找一些大手子的博客看一下stable_sort(q + 1, q + mq + 1, cmp);int now = 0, l = 1, r = 0;for(int i = 1; i <= mq; i ++){int id = q[i].id, t = q[i].t;while(r < q[i].r) add(o[++ r]);while(r > q[i].r) del(o[r --]); // 更新右端点while(l < q[i].l) del(o[l ++]);while(l > q[i].l) add(o[-- l]); // 更新左端点while(now < t) // 更新时间{now ++;if(c[now].x <= r && c[now].x >= l) // 不在修改范围内,直接跳过{del(o[c[now].x]);add(c[now].y);}swap(o[c[now].x], c[now].y); // 交换两个颜色} while(now > t){if(c[now].x <= r && c[now].x >= l){del(o[c[now].x]);add(c[now].y);}swap(o[c[now].x], c[now].y);now --;}f[id] = res; //  记录结果}for(int i = 1; i <= mq; i ++){cout << f[i] << endl;}
}signed main(void)
{IOS;int t = 1;
//	cin >> t;while(t --) sovle();return 0;
}

http://www.lryc.cn/news/221191.html

相关文章:

  • uniapp 请求接口的方式
  • 怎么查看当前vue项目,要求的node.js版本
  • QT5自适应
  • 蓝桥杯官网练习题(日期问题)
  • PDF文件解析
  • 初识微服务技术栈
  • windows 下运行正常,但是linux下报错 : Could not find or load main class
  • MySQL 数据目录和 InnoDB 表空间补充知识:详细结构
  • 移远EC600U-CN开发板 day02
  • visual studio Python 配置QGIS(qgis)教程
  • 第二证券:消费电子概念活跃,博硕科技“20cm”涨停,天龙股份斩获10连板
  • petalinux 2022.2 在 ubantu18.04 下的安装
  • 【进程与线程】进程与线程 QA
  • 电脑风扇控制软件 Macs Fan Control Pro mac中文版功能介绍
  • 【13】c++11新特性 —>call_once
  • 解决logstash插件logstash-outputs-mongodb一条数据失败后一直重复尝试
  • 【网络协议】聊聊HTTPDNS如何工作的
  • TikTok与老年用户:社交媒体的跨代交流
  • 如何在Linux机器上使用ssh远程连接Windows Server服务器
  • NLP常见任务的分类指标
  • node插件express(路由)的插件使用(二)——body-parser和ejs插件的基本使用
  • 学习c++的第十天
  • 895. 最长上升子序列
  • 岩土工程铁路桥梁监测中智能振弦传感器的应用方案
  • 【数智化人物展】觉非科技CEO李东旻:数据闭环,智能驾驶数智时代发展的新引擎...
  • 字符型液晶显示器LCD 1602的显示控制(Keil+Proteus)
  • 为什么我学了几天 STM32 感觉一脸茫然?
  • DC-DC降压芯片120V转12V5A大功率SL3038电源芯片
  • CE认证木质玩具TUME外贸出口测试报告解析
  • oracle_19c 安装