Find the median(2019年牛客多校第七场E题+左闭右开线段树)
题目链接
题意
每次往集合里面添加一段连续区间的数,然后询问当前集合内的中位数。
思路
思路很好想,但是卡内存。
当时写的动态开点线段树没卡过去,赛后机房大佬用动态开点过了,\(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题+左闭右开线段树)的更多相关文章
- Distance(2019年牛客多校第八场D题+CDQ+树状数组)
题目链接 传送门 思路 这个题在\(BZOJ\)上有个二维平面的版本(\(BZOJ2716\)天使玩偶),不过是权限题因此就不附带链接了,我也只是在算法进阶指南上看到过,那个题的写法是\(CDQ\), ...
- 2019年牛客多校第四场 B题xor(线段树+线性基交)
题目链接 传送门 题意 给你\(n\)个基底,求\([l,r]\)内的每个基底是否都能异或出\(x\). 思路 线性基交板子题,但是一直没看懂咋求,先偷一份咖啡鸡板子写篇博客吧~ 线性基交学习博客:传 ...
- Palindrome Mouse(2019年牛客多校第六场C题+回文树+树状数组)
目录 题目链接 题意 思路 代码 题目链接 传送门 题意 问\(s\)串中所有本质不同的回文子串中有多少对回文子串满足\(a\)是\(b\)的子串. 思路 参考代码:传送门 本质不同的回文子串肯定是要 ...
- generator 1(2019年牛客多校第五场B题+十进制矩阵快速幂)
目录 题目链接 思路 代码 题目链接 传送门 思路 十进制矩阵快速幂. 代码 #include <set> #include <map> #include <deque& ...
- Explorer(2019年牛客多校第八场E题+线段树+可撤销并查集)
题目链接 传送门 题意 给你一张无向图,每条边\(u_i,v_i\)的权值范围为\([L_i,R_i]\),要经过这条边的条件是你的容量要在\([L_i,R_i]\),现在问你你有多少种容量使得你可以 ...
- 2019年牛客多校第三场 F题Planting Trees(单调队列)
题目链接 传送门 题意 给你一个\(n\times n\)的矩形,要你求出一个面积最大的矩形使得这个矩形内的最大值减最小值小于等于\(M\). 思路 单调队列滚动窗口. 比赛的时候我的想法是先枚举长度 ...
- 2019牛客多校第八场 F题 Flowers 计算几何+线段树
2019牛客多校第八场 F题 Flowers 先枚举出三角形内部的点D. 下面所说的旋转没有指明逆时针还是顺时针则是指逆时针旋转. 固定内部点的答案的获取 anti(A)anti(A)anti(A)或 ...
- 牛客多校第三场 G Removing Stones(分治+线段树)
牛客多校第三场 G Removing Stones(分治+线段树) 题意: 给你n个数,问你有多少个长度不小于2的连续子序列,使得其中最大元素不大于所有元素和的一半 题解: 分治+线段树 线段树维护最 ...
- 2020牛客多校第八场K题
__int128(例题:2020牛客多校第八场K题) 题意: 有n道菜,第i道菜的利润为\(a_i\),且有\(b_i\)盘.你要按照下列要求给顾客上菜. 1.每位顾客至少有一道菜 2.给顾客上菜时, ...
随机推荐
- nexus没有授权导致的错误
错误详情信息: 错误信息: [ERROR] Failed to execute goal on project blog: Could not resolve dependencies for pro ...
- 福州大学软件工程1916|W班 第10、11次作业成绩排名
作业链接 项目Alpha冲刺(团队) 事后诸葛亮(团队) 评分细则 博客评分标准 本次作业包括现场Alpha答辩评分(映射总分为100分)+博客分(总分130分)+贡献度得分,其中博客分由以下部分组成 ...
- .NET技术webconfig加密操作
webconfig 加密 aspnet_regiis.exe -pef secion physical_directory -prov provider section表示要加密的配置节 phy ...
- GCN(Graph Convolutional Network)的简单公式推导
第一步:从前一个隐藏层到后一个隐藏层,对结点进行特征变换 第二步:对第一步进行具体实现 第三步:对邻接矩阵进行归一化(行之和为1) 邻接矩阵A的归一化,可以通过度矩阵D来实现(即通过D^-1*A来实现 ...
- linux免费https证书申请教程
linux免费https证书申请教程直接去阿里云 菜单有个证书服务进去有个购买证书菜单 选择免费的 然后会提示写个人资料 然后系统生成csr 然后提交审核这个时候会有份邮件 文件下载上传到你的服务器 ...
- 什么是 ZFS文件系统?ZFS概念及特点简介
什么是 ZFS? ZFS(Zettabyte File System)是由SUN公司的Jeff Bonwick领导设计的一种基于Solaris的文件系统,最初发布于20014年9月14日. SUN被O ...
- Collection 接口的 toArray 方法
Collection 接口的 toArray 方法 方法签名 Object[] toArray() 返回包含此 collection 中所有元素的数组. T[] toArray(T[] a) 返回包含 ...
- Django中使用CORS实现跨域请求(转)
原文:https://blog.csdn.net/zizle_lin/article/details/81381322 跨域请求: 请求url包含协议.网址.端口,任何一种不同都是跨域请求. ...
- Git系列 —— github提交一个空目录
转载自github提交一个空目录 github默认不上传空目录,有的时候需要空目录来保持程序的结构. 两种场景 1.始终保持空目录,即时里面有文件,也全部忽略掉. 建立一个.gitignore文件放到 ...
- 客观->感官->意识->语言->思维->世界观、科学->思想
客观->感官->意识->语言->思维->世界观.科学->思想