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

原题链接
带修莫队模板.
增加一维时间t.
需要注意:
1.排序第一关键字为l所在块编号,第二关键字为r所在块编号,第三关键字为t.
2.块的大小为cbrt(n*t), 即block = cbrt((double)n * max(1, nc));
3.对t处理时可交换原序列中颜色编号与该操作交换后的颜色编号.
时间复杂度O(n^5/3).证明略.
代码如下:

#include <cstdio>
#include <cctype>
#include <cmath>
#include <algorithm>

using namespace std;

inline int read(){
   
    int res = 0, pdf = 0; char ch = getchar();
    while(!isdigit(ch)) pdf = ch == '-', ch = getchar();
    while(isdigit(ch)) res = (res<<3) + (res<<1) + (ch^48), ch = getchar();
    return pdf ? -res : res;
} 

inline void Print(int x) {
   
	if (x < 0) x = -x, putchar('-'); 
	if (x < 10) putchar(x + '0'); 
	else {
   
		Print(x / 10); 
		putchar(x % 10 + '0'); 
	}
} 

const int N = 2e6 + 10; 
int n, m, ans, nq, nc, block, pos[N], col[N], ton[N]; 
struct Query {
   
	int id, l, r, t, ans; 
}q[N];
struct Change {
   
	int p, k
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值