HDU 5204 Rikka with sequence
来源:互联网 发布:java退格符处理 编辑:程序博客网 时间:2024/06/05 18:31
Problem Description
As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:
Yuta have a sequence. Because the sequence is very self-willed(RenXing), at first the sequence is empty. And then Yuta do n operations on this sequence, each operation is either of these two types:
1.Add a number w into each gap of the sequence. For example if w=3 and the sequence before is “2 4”, it will be changed to “3 2 3 4 3”.
**after the first operation of the first type, there is only one number in the sequence**
2.Query the kth small number in the subsequence [L,R]. For example if k=2, L=2, R=4 and the sequence is “3 2 3 4 2”, the answer will be 3.
Yuta wants Rikka to tell him the answer of each query.
It is too difficult for Rikka. Can you help her?
Yuta have a sequence. Because the sequence is very self-willed(RenXing), at first the sequence is empty. And then Yuta do n operations on this sequence, each operation is either of these two types:
1.Add a number w into each gap of the sequence. For example if w=3 and the sequence before is “2 4”, it will be changed to “3 2 3 4 3”.
**after the first operation of the first type, there is only one number in the sequence**
2.Query the kth small number in the subsequence [L,R]. For example if k=2, L=2, R=4 and the sequence is “3 2 3 4 2”, the answer will be 3.
Yuta wants Rikka to tell him the answer of each query.
It is too difficult for Rikka. Can you help her?
Input
The first line contains one number n(n≤100000) . Each of the following n lines describes an operation: if it is “1 w” it will be the first type. Otherwise if it is “2 L R k”, it will be the second type. (1≤w≤109,L≤R≤1018)
R will not be larger than the length of the sequence
R will not be larger than the length of the sequence
Output
For each query operation, output one number – the answer.
Sample Input
61 31 12 2 3 21 22 3 5 22 1 4 4
Sample Output
323因为每次加进来的数一定占据了当前的奇数位置,所以暴力的统计区间范围内的数字个数即可。#include <cstdio>#include <algorithm>const int maxn = 200009;using namespace std;int n, a[maxn], m, tot;long long L, R, l, r, K;struct node{ int w; long long cnt; node(int w = 0, long long cnt = 0) :w(w), cnt(cnt){} bool operator<(const node &rhs)const{ return w < rhs.w; }}p[maxn];inline void solve(){ scanf("%I64d%I64d%I64d", &L, &R, &K); int time = 0; for (int t = tot - 1; L <= R; L = (L + 1) >>1, R = R >> 1, t--) { l = L; if (!(l & 1))l++; r = R; if (!(r & 1))r--; if (l <= r) p[time++] = node(a[t], (r - l) / 2 + 1); } sort(p, p + time); for (int i = 0; K&&i < tot; i++) { K -= min(K, p[i].cnt); if (!K) printf("%d\n", p[i].w); } }int main(){ while (scanf("%d", &n) != EOF) { tot = 0; while (n--) { scanf("%d", &m); if (m == 1) scanf("%d", &a[tot++]); else solve(); } } return 0;}
0 0
- HDU 5204 Rikka with sequence
- hdu 5204 Rikka with sequence
- HDU 5204 Rikka with sequence
- hdu 5204 Rikka with sequence yy题
- HDU 5204 Rikka with sequence 思维.
- HDU 5828 Rikka with Sequence
- Hdu 5828 Rikka with Sequence
- HDU 5828 Rikka with Sequence
- hdu 5204 Rikka with sequence && BestCoder Round #37
- hdu 5204 Rikka with sequence(BestCoder Round #37)
- HDOJ 5204 Rikka with sequence
- HDU 5828 Rikka with Sequence 解题报告
- hdu5204-Rikka with sequence
- hdu5828 Rikka with Sequence
- Rikka with Sequence II
- hdu5828 Rikka with Sequence
- HDU5828-Rikka with Sequence
- HDU 5828 Rikka with Sequence(线段树+小优化)
- Bloom Filter 布隆过滤器
- Softmax回归模型
- TCMalloc分析笔记(gperftools-2.4)
- 蛇形表(递归打印)
- 第二章 面向对象的编程风格(调用函数)
- HDU 5204 Rikka with sequence
- ffmpeg添加mpeg ps流的pcm的解码支持
- SQLserver自定义样式主键-函数实现篇
- java 正则表达式
- stm32 读写内部Flash
- leetcode: Binary Tree Right Side View
- TCP三次握手/四次挥手解析
- HDU 5201 The Monkey King
- Android四大组件之Activity篇