分析:高级数据结构学傻了.....一眼看上去觉得是莫队,发现带修改,于是分块,由于写的常数很大,只有70分.

正解很简单,记录下颜色为c的每只兔子的位置,每次二分找这个区间有多少只这种颜色的兔子就可以了,交换操作就交换位置,颜色.可能会存不下,所以用vector.

70分分块:

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; int n, m, a[][], b[], block, l[], r[], pos[], cnt, vis[];
bool flag = true; void update(int cur)
{
int t = b[cur], t2 = b[cur + ];
swap(b[cur], b[cur + ]);
int p1 = pos[cur], p2 = pos[cur + ];
a[p1][t]--;
a[p2][t]++;
a[p1][t2]++;
a[p2][t2]--;
} int query(int ll, int rr, int c)
{
int L = pos[ll], R = pos[rr], res = ;
if (L >= R - )
{
for (int i = ll; i <= rr; i++)
if (b[i] == c)
res++;
return res;
}
for (int i = L + ; i <= R - ; i++)
res += a[i][c];
for (int i = ll; i <= r[L]; i++)
if (b[i] == c)
res++;
for (int i = l[R]; i <= rr; i++)
if (b[i] == c)
res++;
return res;
} int main()
{
scanf("%d%d", &n, &m);
block = sqrt(n);
for (int i = ; i <= n; i++)
pos[i] = (i - ) / block + ;
cnt = (n - ) / block + ;
for (int i = ; i <= cnt; i++)
l[i] = r[i - ] + , r[i] = min(block * i, n);
for (int i = ; i <= n; i++)
{
int t;
scanf("%d", &t);
a[pos[i]][t]++;
b[i] = t;
}
while (m--)
{
int op, l, r, c;
scanf("%d", &op);
if (op == )
{
scanf("%d%d%d", &l, &r, &c);
printf("%d\n", query(l, r, c));
}
else
{
scanf("%d", &c);
update(c);
}
} return ;
}

正解:

#include <cmath>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int maxn = ; int n, m, a[maxn];
vector <int>b[maxn]; int main()
{
scanf("%d%d", &n, &m);
for (int i = ; i <= n; i++)
{
scanf("%d", &a[i]);
b[a[i]].push_back(i);
}
for (int i = ; i <= n; i++)
sort(b[i].begin(), b[i].end());
while (m--)
{
int op, l, r, c;
scanf("%d", &op);
if (op == )
{
scanf("%d%d%d", &l, &r, &c);
printf("%d\n", (int)(upper_bound(b[c].begin(), b[c].end(), r) - lower_bound(b[c].begin(), b[c].end(), l)));
}
else
{
scanf("%d", &c);
if (a[c] != a[c + ])
{
(*lower_bound(b[a[c]].begin(), b[a[c]].end(), c))++;
(*lower_bound(b[a[c + ]].begin(), b[a[c + ]].end(), c + ))--;
swap(a[c], a[c + ]);
}
}
} return ;
}

最新文章

  1. MediaElement.js之浏览器跨域请求视频播放
  2. django1.8 提示(1_8.W001) The standalone TEMPLATE_* settings were deprecated in Django 1.8 and the TEMPLATES dictionary takes precedence. You must put the values of the following settings into your defau
  3. RDO部署openstack(2)
  4. 动态链接库知识点归纳之一(DLL概念,如何建立,如何使用,如何优化,如何查看)
  5. MyEclipse — Maven+Spring+Struts+Hibernate 整合 [学习笔记-2]
  6. 解决某些手机RadioGroup中的RadioButton不居中的问题
  7. UVA 10282 (13.08.18)
  8. php学习笔记(2)
  9. JSP实现界面的自动跳转的几种方式
  10. MySQL 查询重复数据,删除重复数据保留id最小的一条作为唯一数据
  11. appscan使用教程(全)
  12. 第二十二节,TensorFlow中的图片分类模型库slim的使用、数据集处理
  13. Postgresql 简单安装过程. Study From https://www.cnblogs.com/stulzq/p/7766409.html
  14. 不越狱安装破解软件,iResign重签名方法
  15. 3、CommonChunkPlugin提取公共js-以提取一个jquery为例
  16. MySQL: ON DUPLICATE KEY UPDATE 用法
  17. C语言中线程和进程的区别
  18. 搭建高可用mongodb集群(二)&mdash;&mdash; 副本集
  19. Oracle相关操作示例(导出导入dmp需要采用)
  20. 用 HTML5+ payment方法支付宝支付遇到的坑

热门文章

  1. 积分图像 分类: 图像处理 Matlab 2015-06-06 10:30 149人阅读 评论(0) 收藏
  2. 实现字符串的查找和替换 分类: c/c++ 2014-10-09 22:33 469人阅读 评论(0) 收藏
  3. Service官方教程(8)Bound Service示例之2-跨进程使用Messenger
  4. sdut1933WHUgirls(dp)
  5. AJPFX:递归与非递归之间的转化
  6. iOS:swift :可选类型
  7. jQuery的属性与样式之样式操作.css()
  8. python学习第三次
  9. 类方法__setattr__,__delattr__,__getattr__
  10. 谈谈JVM内存区域的划分