传送门

分析

将询问离线,枚举右端点。新加入一个右端点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的更多相关文章

  1. NOI.AC NOIP模拟赛 第六场 游记

    NOI.AC NOIP模拟赛 第六场 游记 queen 题目大意: 在一个\(n\times n(n\le10^5)\)的棋盘上,放有\(m(m\le10^5)\)个皇后,其中每一个皇后都可以向上.下 ...

  2. # NOI.AC省选赛 第五场T1 子集,与&最大值

    NOI.AC省选赛 第五场T1 A. Mas的童年 题目链接 http://noi.ac/problem/309 思路 0x00 \(n^2\)的暴力挺简单的. ans=max(ans,xor[j-1 ...

  3. NOI.ac #31 MST DP、哈希

    题目传送门:http://noi.ac/problem/31 一道思路好题考虑模拟$Kruskal$的加边方式,然后能够发现非最小生成树边只能在一个已经由边权更小的边连成的连通块中,而树边一定会让两个 ...

  4. NOI.AC NOIP模拟赛 第五场 游记

    NOI.AC NOIP模拟赛 第五场 游记 count 题目大意: 长度为\(n+1(n\le10^5)\)的序列\(A\),其中的每个数都是不大于\(n\)的正整数,且\(n\)以内每个正整数至少出 ...

  5. NOI.AC NOIP模拟赛 第二场 补记

    NOI.AC NOIP模拟赛 第二场 补记 palindrome 题目大意: 同[CEOI2017]Palindromic Partitions string 同[TC11326]Impossible ...

  6. NOI.AC NOIP模拟赛 第一场 补记

    NOI.AC NOIP模拟赛 第一场 补记 candy 题目大意: 有两个超市,每个超市有\(n(n\le10^5)\)个糖,每个糖\(W\)元.每颗糖有一个愉悦度,其中,第一家商店中的第\(i\)颗 ...

  7. NOI.AC NOIP模拟赛 第四场 补记

    NOI.AC NOIP模拟赛 第四场 补记 子图 题目大意: 一张\(n(n\le5\times10^5)\)个点,\(m(m\le5\times10^5)\)条边的无向图.删去第\(i\)条边需要\ ...

  8. NOI.AC NOIP模拟赛 第三场 补记

    NOI.AC NOIP模拟赛 第三场 补记 列队 题目大意: 给定一个\(n\times m(n,m\le1000)\)的矩阵,每个格子上有一个数\(w_{i,j}\).保证\(w_{i,j}\)互不 ...

  9. NOI.AC WC模拟赛

    4C(容斥) http://noi.ac/contest/56/problem/25 同时交换一行或一列对答案显然没有影响,于是将行列均从大到小排序,每次处理限制相同的一段行列(呈一个L形). 问题变 ...

随机推荐

  1. codeforces D. Area of Two Circles' Intersection 计算几何

    D. Area of Two Circles' Intersection time limit per test 2 seconds memory limit per test 256 megabyt ...

  2. linux查看网络链接状况命令netstat

    linux查看网络链接状况命令 netstat 参数如下: -a 显示所有socket,包括正在监听的. -c 每隔1秒就重新显示一遍,直到用户中断它. -i 显示所有网络接口的信息,格式同“ifco ...

  3. 简洁的Jquery弹出窗插件

    做项目时,很多时候都需要弹窗提示.如果要求不是很严格的项目,直接使用alert就可以搞定.对于需要高度定制化的项目,而且要求比较高的时候,就需要设计符合整体风格的弹出层,这种有美工帮忙,也比较好搞定. ...

  4. LeetCode Distribute Candies

    原题链接在这里:https://leetcode.com/problems/distribute-candies/#/description 题目: Given an integer array wi ...

  5. 如何上Chrome谷歌商店

    将以下代码复制到本地Hosts中即可. #Google Services START64.233.162.83 0.docs.google.com64.233.162.83 0.drive.googl ...

  6. 8、Selenium+python安装HTMLTestRunner插件

    1.打开网址:http://tungwaiyip.info/software/HTMLTestRunner.html,下载HTMLTestRunner.py 2.copy其HTMLTestRunner ...

  7. 一根Express Route同时支持ARM和ASM的VNET

    ARM模式的Azure管理模式在China Azure上已经正式落地了.今后在China Azure上应该主要以ARM的模式创建VM了. 并且目前Express Route也已经可以在ARM模式下创建 ...

  8. Cache缓存优化

    降低数据库压力 <appSettings><add key="/></appSettings> //设置实体缓存时间 public RupengWang. ...

  9. 机器学习:集成学习(Bagging、Pasting)

    一.集成学习算法的问题 可参考:模型集成(Enxemble) 博主:独孤呆博 思路:集成多个算法,让不同的算法对同一组数据进行分析,得到结果,最终投票决定各个算法公认的最好的结果: 弊端:虽然有很多机 ...

  10. Mybatis多参数查询映射

    一.单个参数: public List<XXBean> getXXBeanList(String xxCode); <select id="getXXXBeanList&q ...