题目链接

传送门

题意

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

思路

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

当时写的动态开点线段树没卡过去,赛后机房大佬用动态开点过了,\(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;
}

Find the median(2019年牛客多校第七场E题+左闭右开线段树)的更多相关文章

  1. Distance(2019年牛客多校第八场D题+CDQ+树状数组)

    题目链接 传送门 思路 这个题在\(BZOJ\)上有个二维平面的版本(\(BZOJ2716\)天使玩偶),不过是权限题因此就不附带链接了,我也只是在算法进阶指南上看到过,那个题的写法是\(CDQ\), ...

  2. 2019年牛客多校第四场 B题xor(线段树+线性基交)

    题目链接 传送门 题意 给你\(n\)个基底,求\([l,r]\)内的每个基底是否都能异或出\(x\). 思路 线性基交板子题,但是一直没看懂咋求,先偷一份咖啡鸡板子写篇博客吧~ 线性基交学习博客:传 ...

  3. Palindrome Mouse(2019年牛客多校第六场C题+回文树+树状数组)

    目录 题目链接 题意 思路 代码 题目链接 传送门 题意 问\(s\)串中所有本质不同的回文子串中有多少对回文子串满足\(a\)是\(b\)的子串. 思路 参考代码:传送门 本质不同的回文子串肯定是要 ...

  4. generator 1(2019年牛客多校第五场B题+十进制矩阵快速幂)

    目录 题目链接 思路 代码 题目链接 传送门 思路 十进制矩阵快速幂. 代码 #include <set> #include <map> #include <deque& ...

  5. Explorer(2019年牛客多校第八场E题+线段树+可撤销并查集)

    题目链接 传送门 题意 给你一张无向图,每条边\(u_i,v_i\)的权值范围为\([L_i,R_i]\),要经过这条边的条件是你的容量要在\([L_i,R_i]\),现在问你你有多少种容量使得你可以 ...

  6. 2019年牛客多校第三场 F题Planting Trees(单调队列)

    题目链接 传送门 题意 给你一个\(n\times n\)的矩形,要你求出一个面积最大的矩形使得这个矩形内的最大值减最小值小于等于\(M\). 思路 单调队列滚动窗口. 比赛的时候我的想法是先枚举长度 ...

  7. 2019牛客多校第八场 F题 Flowers 计算几何+线段树

    2019牛客多校第八场 F题 Flowers 先枚举出三角形内部的点D. 下面所说的旋转没有指明逆时针还是顺时针则是指逆时针旋转. 固定内部点的答案的获取 anti(A)anti(A)anti(A)或 ...

  8. 牛客多校第三场 G Removing Stones(分治+线段树)

    牛客多校第三场 G Removing Stones(分治+线段树) 题意: 给你n个数,问你有多少个长度不小于2的连续子序列,使得其中最大元素不大于所有元素和的一半 题解: 分治+线段树 线段树维护最 ...

  9. 2020牛客多校第八场K题

    __int128(例题:2020牛客多校第八场K题) 题意: 有n道菜,第i道菜的利润为\(a_i\),且有\(b_i\)盘.你要按照下列要求给顾客上菜. 1.每位顾客至少有一道菜 2.给顾客上菜时, ...

随机推荐

  1. Docker环境下的前后端分离项目部署与运维(六)搭建MySQL集群

    单节点数据库的弊病 大型互联网程序用户群体庞大,所以架构必须要特殊设计 单节点的数据库无法满足性能上的要求 单节点的数据库没有冗余设计,无法满足高可用 单节点MySQL的性能瓶领颈 2016年春节微信 ...

  2. 2018-2019-2 网络对抗技术 20165318 Exp 8 Web基础

    2018-2019-2 网络对抗技术 20165318 Exp 8 Web基础 原理与实践说明 实践内容概述 基础问题回答 实践过程记录 1.Web前端:HTML 2.Web前端:javascipt ...

  3. MPI linux Ubuntu cluster 集群

    在局域网内安装mpi,并进行并行计算.MPICH3. 下载源码: wget http://www.mpich.org/static/downloads/3.3.1/mpich-3.3.1.tar.gz ...

  4. docker 学习操作记录 5

    记录5 * Overheard at KubeCon: "microk8s.status just blew my mind". https://microk8s.io/docs/ ...

  5. 如何下载最新版本和旧版本的eclipse?

    1.进入官网,点击download,进入download界面,如果想要最新的版本的eclipse,直接点击下载即可,如图所示: 2.如果想下载旧版本的eclipse的话,可以点击上图的的downloa ...

  6. keras学习入门一

    基本概念 1. 张量 tensor 所有的数据类型都可以看成是张量,可以看成是向量,矩阵在推广 张量的阶,有时候也叫维度,或是轴(axis) 0阶张量如 [] ,5 也叫做标量 1阶张量 如 [ 1, ...

  7. Mybatis架构与原理

    一.简介 MyBatis 是一款优秀的持久层框架.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集 Mybatis可以将Sql语句配置在XML文件中,避免将Sql语句硬编码 ...

  8. 【转载】 Windows系统电脑通过设备管理器查看电脑配置信息

    在采购电脑或者使用电脑的过程中,有时候我们需要查看到电脑的所有设备硬件信息,此时就可以通过Windows系统自带的设备管理器界面来查看该电脑所有的设备配置信息,包括CPU型号频率.内存.硬盘型号以及容 ...

  9. 小tips:JS/CSS实现字符串单词首字母大写

    css实现: text-transform:capitalize; JS代码一: String.prototype.firstUpperCase = function(){ return this.r ...

  10. powershell 远程下载并执行

    远程下载文件到本地并执行cmd.exe /c powershell.exe -ExecutionPolicy bypass -noprofile -windowstyle hidden (new-ob ...