noi.ac day6t3 color
分析
将询问离线,枚举右端点。新加入一个右端点i时,假设离i第t近的同色位置为p,t+1近的是q,则当i是右端点时,(q,p]的点可以作为左端点。
注意对于一个点离它第t近的同色点可以用队列维护求得
之后用树状数组差分一下就可以了
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
struct node {
int le,ri,id;
};
node a[];
vector<int>q[];
int C[],d[],n,m,k,t,ans[];
int nxt[],fa[],pre[],ppre[],is[];
inline bool cmp(const node x,const node y){return x.ri<y.ri;}
inline int lb(int x){return x&(-x);}
inline void add(int x,int k){while(x<=n)d[x]+=k,x+=lb(x);}
inline int Q(int x){int res=;while(x)res+=d[x],x-=lb(x);return res;}
int main(){
int i,j=;
scanf("%d%d%d%d",&n,&m,&k,&t);
for(i=;i<=n;i++)scanf("%d",&C[i]);
for(i=;i<=m;i++)scanf("%d%d",&a[i].le,&a[i].ri),a[i].id=i;
sort(a+,a+m+,cmp);
for(i=;i<=k;i++)q[i].push_back();
for(i=;i<=n;i++){
int x=C[i],s=q[x].size();
q[x].push_back(i);
if(s>=t)add(q[x][s-t]+,),add(q[x][s-t+]+,-);
if(s>t)add(q[x][s-t-]+,-),add(q[x][s-t]+,);
for(j;j<=m;j++)
if(a[j].ri==i)ans[a[j].id]=Q(a[j].le);
else break;
}
for(i=;i<=m;i++)printf("%d\n",ans[i]);
return ;
}
noi.ac day6t3 color的更多相关文章
- NOI.AC NOIP模拟赛 第六场 游记
		NOI.AC NOIP模拟赛 第六场 游记 queen 题目大意: 在一个\(n\times n(n\le10^5)\)的棋盘上,放有\(m(m\le10^5)\)个皇后,其中每一个皇后都可以向上.下 ... 
- # NOI.AC省选赛 第五场T1 子集,与&最大值
		NOI.AC省选赛 第五场T1 A. Mas的童年 题目链接 http://noi.ac/problem/309 思路 0x00 \(n^2\)的暴力挺简单的. ans=max(ans,xor[j-1 ... 
- NOI.ac #31 MST DP、哈希
		题目传送门:http://noi.ac/problem/31 一道思路好题考虑模拟$Kruskal$的加边方式,然后能够发现非最小生成树边只能在一个已经由边权更小的边连成的连通块中,而树边一定会让两个 ... 
- NOI.AC NOIP模拟赛 第五场 游记
		NOI.AC NOIP模拟赛 第五场 游记 count 题目大意: 长度为\(n+1(n\le10^5)\)的序列\(A\),其中的每个数都是不大于\(n\)的正整数,且\(n\)以内每个正整数至少出 ... 
- NOI.AC NOIP模拟赛 第二场 补记
		NOI.AC NOIP模拟赛 第二场 补记 palindrome 题目大意: 同[CEOI2017]Palindromic Partitions string 同[TC11326]Impossible ... 
- NOI.AC NOIP模拟赛 第一场 补记
		NOI.AC NOIP模拟赛 第一场 补记 candy 题目大意: 有两个超市,每个超市有\(n(n\le10^5)\)个糖,每个糖\(W\)元.每颗糖有一个愉悦度,其中,第一家商店中的第\(i\)颗 ... 
- NOI.AC NOIP模拟赛 第四场 补记
		NOI.AC NOIP模拟赛 第四场 补记 子图 题目大意: 一张\(n(n\le5\times10^5)\)个点,\(m(m\le5\times10^5)\)条边的无向图.删去第\(i\)条边需要\ ... 
- NOI.AC NOIP模拟赛 第三场 补记
		NOI.AC NOIP模拟赛 第三场 补记 列队 题目大意: 给定一个\(n\times m(n,m\le1000)\)的矩阵,每个格子上有一个数\(w_{i,j}\).保证\(w_{i,j}\)互不 ... 
- NOI.AC WC模拟赛
		4C(容斥) http://noi.ac/contest/56/problem/25 同时交换一行或一列对答案显然没有影响,于是将行列均从大到小排序,每次处理限制相同的一段行列(呈一个L形). 问题变 ... 
随机推荐
- hive 遇到的问题及解决方法
			org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.ipc.StandbyException): Operation category RE ... 
- codeigniter教程:Codeigniter出现Unable to connect to your databas
			Codeigniter出现A Database Error Occurred错误 下午把项目构建到服务器上的时候,codeigniter竟然出现了 a database error occurred ... 
- 延时并自动关闭MessageBox
			信息提示框(MessageBox)是微软NET自带的一个用于弹出警告.错误或者讯息一类的“模式”对话框.此类对话框一旦开启,则后台窗体无法再被激活(除非当前的MessageBox被点击或者关闭取消). ... 
- uva11078 - Open Credit System(动态维护关键值)
			这道题使用暴力解法O(n*n)会超时,那么用动态维护最大值可以优化到O(n).这种思想非常实用. #include<iostream> #include<cstdio> #in ... 
- 5.MySQL优化---索引优化专题
			来自互联网,整理转载. 摘要:多关于索引,分为以下几点来讲解: 一.索引的概述(什么是索引,索引的优缺点) 二.索引的基本使用(创建索引) 三.索引的基本原理(面试重点) 四.索引的数据结构(B树,h ... 
- php是如何工作的
			a:前提条件: apache服务器启动正常工作 b:客户端浏览器在地址栏输入一个程序地栏 按回车发送请求 {请求}http://127.0.0.1/day03/1.php c:apache接收请求,并 ... 
- numpy、scipy、pandas
			以下分别是numpy.Scipy.pandas的简介.虽然这些包提供的一些结构比python自身的“更高级.更高效”,更高级是因为它们能完成更高级的任务,但是,学习的时候尽量不要和python割裂开认 ... 
- Vue 将样式绑定到一个对象让模板更清晰
			Vue 将样式绑定到一个对象让模板更清晰 <div id="app"> <div v-bind:style="styleObject"> ... 
- HIVE-默认分隔符的(linux系统的特殊字符)查看,输入和修改
			这段时间做hive的时候,用到了系统默认分隔符.通常下面2中情况我们需要需要用到分隔符 1,制作table的输入文件,有时候我们需要输入一些特殊的分隔符 2,把hive表格导出到本地时,系统默认的分隔 ... 
- LeetCode第二题:Add Two Numbers
			You are given two non-empty linked lists representing two non-negative integers. The digits are stor ... 
