[bzoj2453]维护队列
2016-05-30 19:07
351 查看
题目大意
需要兹瓷修改,区间询问不同种类数。带修改莫队
裸上呀!#include<cstdio> #include<algorithm> #define fo(i,a,b) for(i=a;i<=b;i++) using namespace std; const int maxn=10000+10,maxd=1000000+10,c=25; int belong[maxn],a[maxn],b[maxn][3],ans[maxn],cnt[maxd]; struct dong{ int l,r,x,id; } ask[maxn]; int i,j,k,t,n,m,l,r,x,top,tot,now; bool cmp(dong a,dong b){ return belong[a.l]<belong[b.l]||belong[a.l]==belong[b.l]&&belong[a.r]<belong[b.r]||belong[a.l]==belong[b.l]&&belong[a.r]==belong[b.r]&&a.x<b.x; } void in(int x){ cnt[x]++; if (cnt[x]==1) now++; } void out(int x){ cnt[x]--; if (cnt[x]==0) now--; } void change(int j,int x,int y){ a[j]=y; if (l<=j&&j<=r){ out(x); in(y); } } char get(){ char ch=getchar(); while (ch!='Q'&&ch!='R') ch=getchar(); return ch; } int main(){ scanf("%d%d",&n,&m); fo(i,1,n) scanf("%d",&a[i]),belong[i]=(i-1)/c+1; fo(i,1,m) if (get()=='Q'){ ++top; scanf("%d%d",&ask[top].l,&ask[top].r); ask[top].x=tot; ask[top].id=top; } else{ scanf("%d%d",&j,&k); b[++tot][0]=j; b[tot][1]=a[j]; a[j]=b[tot][2]=k; } sort(ask+1,ask+top+1,cmp); l=1;r=0;x=tot; fo(i,1,top){ while (x<ask[i].x){ x++; change(b[x][0],b[x][1],b[x][2]); } while (x>ask[i].x){ change(b[x][0],b[x][2],b[x][1]); x--; } while (l<ask[i].l){ out(a[l]); l++; } while (l>ask[i].l){ l--; in(a[l]); } while (r<ask[i].r){ r++; in(a[r]); } while (r>ask[i].r){ out(a[r]); r--; } ans[ask[i].id]=now; } fo(i,1,top) printf("%d\n",ans[i]); }
相关文章推荐
- 常用linux命令
- 远程登录Linux图形化界面
- apache commons-io
- linux 连接windows 共享文件夹
- File_operations结构体
- linux下邮件查看命令
- POJ2976 Dropping tests(01分数规划)
- Linux下PCB的结构体
- 【NOI2005】维护数列
- C#三十六 三层架构的实现
- C#三十六 三层架构的实现
- C#三十六 三层架构的实现
- linux下启动和关闭网卡命令
- nginx服务器安装及配置文件详解
- jdk8中tomcat修改配置PermSize为MetaspaceSize
- jdk8中tomcat修改配置PermSize为MetaspaceSize
- jdk8中tomcat修改配置PermSize为MetaspaceSize
- linux_2day
- Tomcat标准目录
- ElKstack-解决nginx日志url链接包含中文logstash报错问题