P3939 数颜色

$vecotr$里二分就是好用,全是$STL$

颜色数目比较少,可以对每一种颜色弄一个$vector$记录一下,查找$l,r$内颜色数为$x$的兔子数,直接在$G[x]$这个$vector$里二分即可

交换两个数。。。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector> #define N 320202
using namespace std; vector<int>G[N]; int n,m,c[N]; int main()
{
scanf("%d%d",&n,&m);
for(int x,i=;i<=n;i++ ){
scanf("%d",&x);
G[x].push_back(i),c[i]=x;
}
for(int opt,l,r,x,i=;i<=m;i++){
scanf("%d",&opt);
if(opt==){
scanf("%d%d%d",&l,&r,&x);
int L=lower_bound(G[x].begin(),G[x].end(),l)-G[x].begin();
int R=upper_bound(G[x].begin(),G[x].end(),r)-G[x].begin()-;
//>=l <=r
if(L>R) printf("0\n");
else printf("%d\n",R-L+);
}else{
scanf("%d",&x);
if(c[x]==c[x+]) continue;
l=x,r=x+;
int pos_1=lower_bound(G[c[l]].begin(),G[c[l]].end(),l)-G[c[l]].begin();
int pos_2=lower_bound(G[c[r]].begin(),G[c[r]].end(),r)-G[c[r]].begin();
G[c[l]][pos_1]++;
G[c[r]][pos_2]--;
swap(c[x],c[x+]);
}
} return ;
}

最新文章

  1. linux-dns服务器搭建
  2. Java四种引用包括强引用,软引用,弱引用,虚引用。
  3. Html 5+
  4. Using command-line Subversion to access project source files
  5. tableview 编辑状态设置
  6. iOS学习之数据请求
  7. ElasticSearch5在Ubuntu系统下的安装和Java调用
  8. node使用buffer生成图片
  9. 关于String中的不变模式
  10. NYOJ 题目12喷水装置(二)
  11. asp.net(C#)实现功能强大的时间日期处理类完整实例
  12. XVIII Open Cup named after E.V. Pankratiev. GP of Romania
  13. Linux下数据库的启动和关闭
  14. IDEA快速入门(Mac版)
  15. BZOJ3786星系探索——非旋转treap(平衡树动态维护dfs序)
  16. Linux shell 自启动脚本写法
  17. 升级tomcat需要更改哪些配置?
  18. SRM 596 DIV2
  19. CentOS7安装OpenStack(Rocky版)-08.启动一个虚拟机实例
  20. MyBatis基本配置和实践(二)

热门文章

  1. django QQ认证登录
  2. Java 在线反编译
  3. bzoj 3625: [Codeforces Round #250]小朋友和二叉树【NTT+多项式开根求逆】
  4. IO流案例:1.复制多级文件夹 2.删除多级文件夹
  5. android 浏览器对图片加载高度渲染问题
  6. Educational Codeforces Round 46 (Rated for Div. 2) C. Covered Points Count
  7. LVS集群-DR模式
  8. Suricata的配置
  9. SonarQube+Svn+Jenkins环境搭建----问题总结
  10. hihocoder1079 离散化