题号 标题 已通过代码 题解/讨论 通过率 团队的状态
A String 点击查看 进入讨论 566/3539  通过
B Irreducible Polynomial 点击查看 规律 730/2290 未通过
C Governing sand 点击查看 进入讨论 388/2088  通过
D Number 点击查看 进入讨论 959/1469  通过
E Find the median 点击查看 离散化 88/985 OK
F Energy stones 点击查看 BIT 16/132 未通过
G Make Shan Happy 点击查看 进入讨论 3/29 未通过
H Pair 点击查看 数位DP 93/245 OK
I Chessboard 点击查看 进入讨论 17/83 未通过
J A+B problem 点击查看 进入讨论 1024/1844  通过
K Function 点击查看 进入讨论 8/49 未通过

E-Find the median

题意

n次操作,($n \le 400000$),每次给出$L_i, R_i$向集合中插入,让你把$[L_i, L_i+1, L_i+2, ... , R_i]$ 插入到集合中,同时输出集合的中位数。

集合一开始为空,($1 \le L_i, R[i] \le 1e9$)

思路

空间有限,所以不可以把两个端点间的一段单独拿出来当成一个点

动态开点也被卡了空间

具体思路还是离散化,我们可以中间的点和左端点看成一个点

把原来对闭区间的操作改为对左闭右开区间的操作

就是把原来的$[L_i, R_i]$ 更改为 $[L_i, R_i + 1)$

// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize(4)
#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <cassert>
// #include<bits/extc++.h>
// using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define fi first
#define se second
#define debug(x) cerr<<#x << " := " << x << endl;
#define bug cerr<<"-----------------------"<<endl;
#define FOR(a, b, c) for(int a = b; a <= c; ++ a) typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll; const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9+; template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
} /**********showtime************/
const int big = 1e9;
const int maxn = ;
int X[maxn],Y[maxn];
int L[maxn], R[maxn];
int a1,b1,c1,m1;
int a2,b2,c2,m2;
struct node{
int cnt;
ll sum;
int lazy;
int len;
} tree[maxn * ];
//离散化
vector<int>vec;
int getid(int x) {
return lower_bound(vec.begin(), vec.end(), x) - vec.begin() + ;
}
// void pushdown(int le,int ri,int rt) {
tree[rt<<].cnt += tree[rt].lazy;
tree[rt<<|].cnt += tree[rt].lazy;
tree[rt<<].lazy += tree[rt].lazy;
tree[rt<<|].lazy += tree[rt].lazy;
int mid = (le + ri) >> ; tree[rt<<].sum += 1ll*tree[rt].lazy * (vec[mid] - vec[le-]);
tree[rt<<|].sum += 1ll*tree[rt].lazy *(vec[ri] - vec[mid]);
tree[rt].lazy = ;
} void update(int L, int R, int le, int ri, int rt) {
if(le >= L && ri <= R) {
tree[rt].lazy++;
tree[rt].cnt++;
//因为每个节点表示【le实际值,ri实际值)的长度。
tree[rt].sum += 1ll*(vec[ri] - vec[le - ]);
return;
}
int mid = (le + ri) >> ;
if(tree[rt].lazy) pushdown(le,ri,rt);
if(mid >= L) {
update(L, R, le, mid, rt<<);
}
if(mid < R) {
update(L, R, mid+, ri, rt<<|);
}
tree[rt].sum = tree[rt<<].sum + tree[rt<<|].sum;
} int query(ll tot, int le, int ri, int rt) {
if(le == ri) { int cnt = tree[rt].cnt, res;
int lbound = vec[le-];
if(tot % cnt == ) {
res = lbound + tot / cnt - ;
}
else
res = lbound + tot / cnt;
return res; } int mid = (le + ri) >> ;
if(tree[rt].lazy) pushdown(le,ri,rt); ll lsum = tree[rt<<].sum;
if(lsum >= tot) return query(tot,le, mid, rt<<);
else return query(tot - lsum, mid+, ri, rt<<|);
}
int main(){ int n;
scanf("%d", &n);
scanf("%d%d%d%d%d%d", &X[], &X[], &a1, &b1, &c1, &m1);
scanf("%d%d%d%d%d%d", &Y[], &Y[], &a2, &b2, &c2, &m2); L[] = min(X[], Y[]) + ;
R[] = max(X[], Y[]) + ;
L[] = min(X[], Y[]) + ;
R[] = max(X[], Y[]) + ;
//因为我后面操作的是左闭右开区间,所以这里右端点++。
R[] ++; R[] ++;
vec.pb(L[]);vec.pb(R[] );
vec.pb(L[]);vec.pb(R[]);
for(int i=; i<=n; i++) {
X[i] = (1ll*a1 * X[i-] + 1ll*b1 * X[i-] + c1 )% m1;
Y[i] = (1ll*a2 * Y[i-] + 1ll*b2 * Y[i-] + c2 )% m2;
L[i] = min(X[i], Y[i]) + ;
R[i] = max(X[i], Y[i]) + ;
R[i] ++;
vec.pb(L[i]); vec.pb(R[i]);
}
sort(vec.begin(), vec.end());
vec.erase(unique(vec.begin(), vec.end()), vec.end());
for(int i=; i<=n; i++) {
L[i] = getid(L[i]);
R[i] = getid(R[i]);
} int tot = vec.size(); ll all = ; for(int i=; i<=n; i++) { update(L[i], R[i] - , , tot, ); all += 1ll*(vec[R[i]-] - vec[L[i] - ]); printf("%d\n", query((all + )/, , tot, ));
}
return ;
}

H Pair

题意

给定A,B,C($A \le 1e9, B \le 1e9, C \le 1e9$),求满足

$$ (x \& y) > C $$

$$ (x \oplus y)  < C$$

的<x, y>对数。其中

$ 1 \le x \le A, 1 \le y \le B$

思路

数位DP,自己code了好久

/*
* @Author: chenkexing
* @Date: 2019-08-09 23:58:00
* @Last Modified by: chenkexing
* @Last Modified time: 2019-08-10 22:19:16
* @Link https://ac.nowcoder.com/acm/contest/887/H
*/
// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize(4)
#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <cassert>
// #include<bits/extc++.h>
// using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define fi first
#define se second
#define debug(x) cerr<<#x << " := " << x << endl;
#define bug cerr<<"-----------------------"<<endl;
#define FOR(a, b, c) for(int a = b; a <= c; ++ a) typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll; const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9+; template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
} /**********showtime************/
ll dp[][][][][][][];
//dp[len][limit1][limit2][ok1][ok2]
//由于两个数要大于0,所以多加上ok1,ok2.
//f1 &的, f2 ^的 // == 2 表示不行了
int shuA[],shuB[],shuC[];
ll dfs(int len, int limit1, int limit2, int ok1, int ok2, int f1, int f2){
if(f1 == && f2 == ) return ;
if(dp[len][limit1][limit2][ok1][ok2][f1][f2] != -)
return dp[len][limit1][limit2][ok1][ok2][f1][f2];
if(len == ) {
return ok1 && ok2 && (f1 == || f2 == );
} int up1 = , up2 = ;
if(limit1) up1 = shuA[len];
if(limit2) up2 = shuB[len];
ll res = ;
// cout<<len<<" " << up1<<" , " << up2<<endl;
for(int i=; i<=up1; i++) {
for(int j=; j<=up2; j++) { // if(len == 2)cout<<len << " " << i << " , " << j << " = " << f1 <<" , , " <<f2 << endl; if(f1 == || f2 == )
res += dfs(len-, limit1 && i == up1, limit2 && j == up2, ok1 || i, ok2 || j, f1, f2);
else {
int F1 = f1, F2 = f2;
if((i & j) < shuC[len]) F1 = ;
else if((i & j) > shuC[len]) F1 = max(F1, ); if((i ^ j) > shuC[len]) F2 = ;
else if((i ^ j) < shuC[len]) F2 = max(F2, );
res += dfs(len-, limit1 && i == up1, limit2 && j == up2, ok1 || i, ok2 || j, F1, F2);
}
} }
dp[len][limit1][limit2][ok1][ok2][f1][f2] = res;
return res;
} int main(){
int T; scanf("%d", &T);
while(T--) {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
memset(dp, -, sizeof(dp));
int len = ;
for(int i=; i<=len; i++) shuA[i] = a % , a = a >> ;
for(int i=; i<=len; i++) shuB[i] = b % , b = b >> ;
for(int i=; i<=len; i++) shuC[i] = c % , c = c >> ;
printf("%lld\n", dfs(len, , , , , , ));
}
return ;
}

2019nc#7的更多相关文章

  1. 2019nc#2

    A Eddy Walker 题意 你有n个点(0-n-1),按顺序形成一个环,初始时你在0的位子,你随机顺时针走一步或者逆时针走一步, 一旦你走到一个点后,环上所有点都被经过至少一次后,你就必须停下来 ...

  2. 2019nc#10

    题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A Blackjack 点击查看 背包DP 32/109 补好了 B Coffee Chicken 点击查看 进入讨论 738/2992  通过 ...

  3. 2019nc#9

    题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A The power of Fibonacci 点击查看 进入讨论 69/227 未通过 B Quadratic equation 点击查看 ...

  4. 2019NC#8

    题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A All-one Matrices 点击查看 单调栈+前缀和 326/2017  通过 B Beauty Values 点击查看 进入讨论 8 ...

  5. 2019nc#6

    https://ac.nowcoder.com/acm/contest/886#question 题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A Garbage Classificatio ...

  6. 2019nc#5

    题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A digits 2 点击查看 1017/2384  通过 B generator 1 点击查看 567/3692  通过 C generato ...

  7. 2019nc#4

    题号 标题 已通过代码 题解 通过率 团队的状态 A meeting 点击查看 树直径 604/2055   B xor 点击查看 线段树维护线性基交 81/861 未通过 C sequence 点击 ...

  8. 2019nc#3

    题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A Graph Games 点击查看 进入讨论 18/292 未通过 B Crazy Binary String 点击查看 1107/3615 ...

  9. 2019NC#1

    LINK B Integration 题意: 给定$a_1,a_2,...,a_n$, 计算 $$\frac{1}{π}\int_{0}^{\infty}\frac{1}{\prod\limits_{ ...

随机推荐

  1. 原创:微信小程序开发要点总结

    废话不多少,下面是对我从开发微信小程序的第一步开始到发布的总结,觉得对您有帮助的话,可以赞赏下,以对我表示鼓励. 一:首先注册登录微信公众平台,这个平台很重要,以后查文档全在上面看.https://m ...

  2. 通过mark和reset方法重复利用InputStream

    InputStreammarkreset 在这篇博客中我们已经简单的知道可以通过缓存InputStream来重复利用一个InputStream,但是这种方式的缺点也是明显的,就是要缓存一整个Input ...

  3. Scala的常用小技巧

    1."RichString.java".stripSuffix(".java") == "RichString" "http:// ...

  4. 面试必问之ArrayList

    ArrayList概述 (1)ArrayList 是一种变长的集合类,基于定长数组实现. (2)ArrayList 允许空值和重复元素,当往 ArrayList 中添加的元素数量大于其底层数组容量时, ...

  5. 封装 Gson 解析Json到对象是否失败

    在使用Google的 Gson 类库解析 Json 数据时,难免会出现解析失败的情况. 在这种情况下,使用 if(obj == null) 是不可行的,fromJson 方法会自动生成对象的实例,所以 ...

  6. centos开发环境安装

    执行 yum install gcc gcc-c++ gcc-g77 flex bison autoconf automake bzip2-devel zlib-devel ncurses-devel ...

  7. 1和new Number(1)有什么区别

    1和new Number(1)有什么区别 author: @Tiffanysbear 总结,两者的区别就是原始类型和包装对象的区别. 什么是包装对象 对象Number.String.Boolean分别 ...

  8. JWT详解

    目录 1.前言 2.JWT的数据结构 2.1 Header 2.2 Payload 2.3 Signature 2.4 Base64URL 3. JWT的实现   1.前言 定义:JSON Web T ...

  9. .netcore持续集成测试篇之搭建内存服务器进行集成测试一

    系列目录 在web项目里,我们把每一层的代码的单元测试都通过并不代表程序能正常运行,因为这个过程缺失了http管道,很多时候我们还还需要把项目布在iis环境中或者在vs里启动iis express服务 ...

  10. 精通Android4.0开发视频【张泽华】-完整版下载

    观看须知: 本视频教程为黑马程序员 张泽华老师历经2年时间整理 适合有JavaWeb基础同学学习,教程采用的AVI方式发布,所以看起来很流畅. 视频概括: 1. 本套视频不同于市面上任何一套andro ...