题目链接

传送门

题意

每次往集合里面添加一段连续区间的数,然后询问当前集合内的中位数。

思路

思路很好想,但是卡内存。

当时写的动态开点线段树没卡过去,赛后机房大佬用动态开点过了,\(tql\)。

卡不过去就只能离散化加左闭右开线段树写了。

代码

#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL; #define lson (rt<<1),L,mid
#define rson (rt<<1|1),mid + 1,R
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("/home/dillonh/CLionProjects/Dillonh/in.txt","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0) const double eps = 1e-8;
const int mod = 1000000007;
const int maxn = 800000 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL; int n, tot, x, y, xx, yy, m1, m2, a1, a2, b1, b2, c1, c2;
int L[maxn], R[maxn], num[maxn*2], lazy[maxn*4];
LL sum[maxn*4]; void push_up(int rt) {
sum[rt] = sum[rt<<1] + sum[rt<<1|1];
} void push_down(int rt, int l, int r) {
if(!lazy[rt]) return;
int x = lazy[rt];
lazy[rt] = 0;
int mid = (l + r) >> 1;
lazy[rt<<1] += x, lazy[rt<<1|1] += x;
sum[rt<<1] += 1LL * x * (num[mid+1]-num[l]);
sum[rt<<1|1] += 1LL * x * (num[r+1]-num[mid+1]);
} void update(int l, int r, int rt, int L, int R) {
if(l <= L && R <= r) {
sum[rt] += num[R+1] - num[L];
++lazy[rt];
return;
}
push_down(rt, L, R);
int mid = (L + R) >> 1;
if(r <= mid) update(l, r, lson);
else if(l > mid) update(l, r, rson);
else {
update(l, mid, lson);
update(mid + 1, r, rson);
}
push_up(rt);
} int query(LL all, int rt, int L, int R) {
if(L == R) {
LL pos = sum[rt] / (num[R+1] - num[L]);
pos = num[L] + (all - 1) / pos;
return pos;
}
push_down(rt, L, R);
int mid = (L + R) >> 1;
if(sum[rt<<1] >= all) return query(all, lson);
else return query(all - sum[rt<<1], rson);
} int main() {
#ifndef ONLINE_JUDGE
FIN;
#endif
scanf("%d", &n);
scanf("%d%d%d%d%d%d", &x, &xx, &a1, &b1, &c1, &m1);
scanf("%d%d%d%d%d%d", &y, &yy, &a2, &b2, &c2, &m2);
L[1] = min(x, y) + 1, R[1] = max(x, y) + 1;
L[2] = min(xx, yy) + 1, R[2] = max(xx, yy) + 1;
num[++tot] = L[1], num[++tot] = R[1] + 1;
num[++tot] = L[2], num[++tot] = R[2] + 1;
for(int i = 3; i <= n; ++i) {
int num1 = ((1LL * a1 * xx % m1 + 1LL * b1 * x % m1) % m1 + c1) % m1;
int num2 = ((1LL * a2 * yy % m2 + 1LL * b2 * y % m2) % m2 + c2) % m2;
L[i] = min(num1, num2) + 1, R[i] = max(num1, num2) + 1;
x = xx, xx = num1;
y = yy, yy = num2;
num[++tot] = L[i], num[++tot] = R[i] + 1;
}
sort(num + 1, num + tot + 1);
tot = unique(num + 1, num + tot + 1) - num - 1;
LL all = 0;
for(int i = 1; i <= n; ++i) {
all += R[i] - L[i] + 1;
L[i] = lower_bound(num + 1, num + tot + 1, L[i]) - num;
R[i] = lower_bound(num + 1, num + tot + 1, R[i] + 1) - num;
update(L[i], R[i]-1, 1, 1, tot);
printf("%d\n", query((all + 1) /2, 1, 1, tot));
}
return 0;
}

最新文章

  1. SQL数据操作和查询
  2. &quot;504 Gateway Time-out&quot;
  3. mysql中NULL和null的区别
  4. BZOJ2879 [Noi2012]美食节
  5. Android中log4j的运用
  6. QT设置标签字体大小和颜色
  7. Curl命令使用方法
  8. mysql 货币字段类型的存储
  9. SharePoint 2007 图片库视图不可用、页面标题不显示
  10. MySQL 复制 - 性能与扩展性的基石 1:概述及其原理
  11. 深入理解line-height与vertical-align——前端布局常用属性
  12. Python学习之路——函数的参数分类
  13. Android ANR(应用无响应)解决分析【转】
  14. kettle 6.1 按时间增量抽取数据
  15. windows环境telnet发送命令
  16. 51Nod 1199 Money out of Thin Air (树链剖分+线段树)
  17. python所有基础
  18. Mysql学习---全国省市区以及邮编数据库
  19. 【EF】EF实现大批量数据库插入操作
  20. 【 Linux 网络虚拟化 】Openvswitch

热门文章

  1. dnsperf
  2. 【java】使用jsp命令查看系统中java运行的程序及进程号
  3. 关于深度学习框架 TensorFlow、Theano 和 Keras
  4. linux免费https证书申请教程
  5. Lua table的remove函数
  6. ZYNQ笔记(5):软中断实现核间通信
  7. Python 3 + Selenium 3 实现汉堡王客户调查提交
  8. SQL系列(五)—— 排序(order by)
  9. vs2015下编译免费开源的jpeg库,ijg的jpeg.lib
  10. C# MemcacheHelper封装