5333. 【NOIP2017提高A组模拟8.23】大新闻
2017-09-01 21:16
309 查看
Description
Input
Output
Sample Input
6 82 7 4 3 5 9
3 2 5 3
1
2 4
3 1 4 2
2 6
3 1 7 5
1
3 3 6 4
Sample Output
54
6
9
Data Constraint
Hint
题解
到过来做就是一道裸的可持久化线段树了代码
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int N = 200010; const int LG = 33; #define child int t0, int &t, int l = 1, int r = 1e9 #define mid ((l + r) >> 1) #define ls a[t0].l, a[t].l, l, mid #define rs a[t0].r, a[t].r, mid + 1, r struct NOTE { int l,r,s; }a[N * 2 * LG]; int root[N * 2]; int tim; int tot; int f ; int n, m, x, y, k, op; void rev(child) { a[t = ++tot] = a[t0], ++a[t].s; if (l == r) return; if (x <= mid) rev(ls); else rev(rs); } int ask(child) { if (l == r) return l; int tmp = a[a[t0].l].s - a[a[t].l].s; if (k <= tmp) return ask(ls); return k -= tmp, ask(rs); } int main() { freopen("news.in","r",stdin); freopen("news.out","w",stdout); scanf("%d%d",&n,&m); for (int i = 1; i <= n; i++) scanf("%d", f + i); for (int i = n; i >= 1; i--) { x = f[i]; ++tim; root[tim] = root[tim - 1]; rev(root[tim - 1], root[tim]); } while (m--) { scanf("%d", &op); if (op == 1) { --tim; continue; } if (op == 2) { scanf("%d", &x); ++tim; root[tim] = root[tim - 1]; rev(root[tim - 1], root[tim]); continue; } scanf("%d%d%d", &x, &y, &k); printf("%d\n", ask(root[tim - x + 1], root[tim - y])); } }
相关文章推荐
- 【jzoj5333】【NOIP2017提高A组模拟8.23】【大新闻】【可持久化线段树】
- 5331. 【NOIP2017提高A组模拟8.23】壕游戏 费用流 动态连边
- jzoj5331 【NOIP2017提高A组模拟8.23】壕游戏
- 5332. 【NOIP2017提高A组模拟8.23】密码 AC自动机+数位DP
- 【JZOJ5332】【NOIP2017提高A组模拟8.23】密码
- 【jzoj5332】【NOIP2017提高A组模拟8.23】【密码】【ac自动机】【动态规划】
- JZOJ 5397. 【NOIP2017提高A组模拟10.6】Biology
- JZOJ5400. 【NOIP2017提高A组模拟10.7】Repulsed 树型DP+贪心
- [JZOJ5405]【NOIP2017提高A组模拟10.10】Permutation
- 【JZOJ4920】【NOIP2017提高组模拟12.10】降雷皇
- 降雷皇 【NOIP2017提高组模拟12.10】
- JZOJ4923. 【NOIP2017提高组模拟12.17】巧克力狂欢
- 【JZOJ4929】 【NOIP2017提高组模拟12.18】B
- JZOJ 5347. 【NOIP2017提高A组模拟9.5】遥远的金字塔
- 【jzoj5347】【NOIP2017提高A组模拟9.5】【遥远的金字塔】【斜率优化动态规划】
- [JZSC2017] 【NOIP2017提高组模拟6.28】总结
- 5358. 【NOIP2017提高A组模拟9.12】BBQ
- JZOJ5373. 【NOIP2017提高A组模拟9.17】信仰是为了虚无之人 并查集+启发式合并
- JZOJ 5373. 【NOIP2017提高A组模拟9.17】信仰是为了虚无之人
- JZOJ100041. 【NOIP2017提高A组模拟7.12】列车调度