bzoj 1878
来源:互联网 发布:域名绑定服务器 编辑:程序博客网 时间:2024/06/16 20:33
这题妙啊
离线处理, 先将询问右端点排序
因为是问不同的
so 这样, 不可用语言描述啊
#include <bits/stdc++.h>using namespace std;typedef long long LL;const int INF = 0x3f3f3f3f;inline int read(void){ int x = 0, c = 0, f = 1; for(;c<'0'||c>'9';c=getchar())f=c!='-'; for(;c>='0'&&c<='9';c=getchar())x=x*10+c-'0'; return f ? x : -x;}const int N = 51000, M = 201000;struct node{ int l, r, id; bool operator < (const node &t) const { return r != t.r ? r < t.r : l < t.l; }} que[M];int cnt[N], ans[M], n, m, col[N], last[1010000], pre[N];#define lowbit(x) (x&-x)inline void Updata(int pos,int val) { for(;pos<=n;pos+=lowbit(pos)) cnt[pos] += val;}inline int Query(int pos){ int ret = 0; for(;pos;pos^=lowbit(pos)) ret += cnt[pos]; return ret;}int main() { n = read(); for (int i = 1; i <= n; i++) { col[i] = read(); pre[i] = last[col[i]]; last[col[i]] = i; } m = read(); for (int i = 1; i <= m; i++) { que[i].l = read(), que[i].r = read(); que[i].id = i; } sort(que+1,que+m+1); int now = 0; for (int i = 1; i <= m; i++) { while (now < que[i].r) { now++; Updata(pre[now]+1, 1); Updata(now+1, -1); } ans[que[i].id] = Query(que[i].l); } for (int i = 1; i <= m; i++) printf("%d\n",ans[i]);}
阅读全文
1 0
- bzoj 1878
- [BZOJ ]
- BZOJ****-****
- BZOJ
- BZOJ
- BZOJ
- BZOJ
- BZOJ
- BZOJ
- BZOJ
- BZOJ
- BZOJ
- BZOJ
- bzoj
- bzoj
- BZOJ
- BZOJ
- bzoj
- 2017年第0届浙江工业大学之江学院程序设计竞赛决赛—C 勤劳的ACgirls
- word2007如何更新目录
- corde coverage
- <%@include...> 与<jsp:include....>指令的区别
- JSON.parse()
- bzoj 1878
- 按键消抖的原理和基于verilog的消抖设计(转)
- generate if的用法
- FPGA\\CPLD设计学习笔记(转)
- iOS TableViewCell 自定义选中样式
- LRU缓存实现(Java)
- 视频通信之一:为什么要对视频进行压缩(转)
- verilog左移位宽增加?
- php扩展