题目链接

传送门

题意

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

思路

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

当时写的动态开点线段树没卡过去,赛后机房大佬用动态开点过了,\(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. Shell脚本之二 变量、字符串和数组

    一.Shell 变量 1.1 定义变量 定义变量时,变量名不加美元符号($),如: your_name="runoob.com" 注意,变量名和等号之间不能有空格,这可能和你熟悉的 ...

  2. 【原创】在windows下使用xampp搭建phpcms v9

    我的操作环境: 操作系统:windows 7       64 位操作系统(有点古老,哈哈) 1.下载php环境和phpcmsv9源代码:phpcms v9 的源码:phpcms_v9.5.10_UT ...

  3. [转帖]HashMap、HashTable、ConcurrentHashMap的原理与区别

    HashMap.HashTable.ConcurrentHashMap的原理与区别 http://www.yuanrengu.com/index.php/2017-01-17.html 2017年1月 ...

  4. 『正睿OI 2019SC Day7』

    简单数论 质因子分解 素性测试 素性测试指的是对一个正整数是否为质数的判定,一般来说,素性测试有两种算法: \(1.\) 试除法,直接尝试枚举因子,时间复杂度\(O(\sqrt n)\). \(2.\ ...

  5. Asp.Net Core Web Api 使用 Swagger 生成 api 说明文档

    最近使用 Asp.Net Core Web Api 开发项目服务端.Swagger 是最受欢迎的 REST APIs 文档生成工具之一,进入我的视野.以下为学习应用情况的整理. 一.Swagger 介 ...

  6. C#MVC中ViewData和ViewBag的使用

    ViewBag和ViewData的区别 ViewData ViewBag 它是key/value字典集合 它是dynamic类型对象 从asp.net mvc1就有了 从asp.netmvc3才有 基 ...

  7. Java之路---Day18(List集合)

    2019-11-05-23:03:28 List集合: java.util.List 接口继承自 Collection 接口,是单列集合的一个重要分支,习惯性地会将实现了List 接口的对象称为Lis ...

  8. toString()和Object.prototype.toString.call() 不一样

    var arr=[1,2,3];arr.toString()//输出“1,2,3”Object.prototype.toString.call(arr)//输出 "[object Array ...

  9. 从 Vue 的视角学 React(四)—— 组件传参

    组件化开发的时候,参数传递是非常关键的环节 哪些参数放在组件内部管理,哪些参数由父组件传入,哪些状态需要反馈给父组件,都需要在设计组件的时候想清楚 但实现这些交互的基础,是明白组件之间参数传递的方式, ...

  10. linux 如何修改默认的FTP帐号或密码

    wdlinux_lamp,wdlinux_lnmp的系统安装好后,默会创建一个FTP用户用户名是:wdlinux密码是:wdlinux.cn 如想修改密码或用户名,先找个ssh工具,有关ssh客户端的 ...