Codeforces 948 数论推导 融雪前缀和二分check 01字典树带删除
A.
全部空的放狗
B.
先O(NLOGNLOGN)处理出一个合数质因数中最大的质数是多少
因为p1 x1 x2的关系是 x2是p在x1之上的最小倍数 所以x1的范围是[x2-p+1,x2-1]要使最后答案尽可能小 要包含尽可能多的选择
p0 x0 x1关系同上
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int maxn = ;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
const int turn2[][] = {{, }, { -, }, {, }, {, -}, {, -}, { -, -}, {, }, { -, }};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
ll mod = 3e7;
int prime[];
//priority_queue<int, vector<int>, less<int>> que;
void init()
{
for (int i = ; i <= ; i++)
{
if (prime[i])
{
continue;
}
for (int j = i * ; j <= ; j += i)
{
prime[j] = i;
}
}
}
int main()
{
int n;
init();
cin >> n;
int anser = INT_MAX;
int now = prime[n];
//cout << prime[n] << endl;
int x1 = n - now + ;
for (int i = x1; i <= n; i++)
{
if (!prime[i])
{
continue;
}
anser = min(anser, i - prime[i] + );
//cout << i - prime[i] + 1 << endl;
}
cout << anser << endl;
}
C.
前缀和题
作温度的前缀和
二分出第i块雪在第j天融化
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
ll mod = 3e7;
const int maxn=1e5+;
ll v[maxn];
ll t[maxn];
ll pre[maxn];
ll ans[maxn];
ll add[maxn];
int main()
{
ll n;
cin >> n;
for(int i=;i<=n;i++)
{
scanf("%lld",v+i);
}
for(int i=;i<=n;i++)
{
scanf("%lld",t+i);
pre[i]=pre[i-]+t[i];
}
pre[n+]=2e18+;
for(int i=;i<=n;i++)
{
ll now=v[i]+pre[i-];
int aim=upper_bound(pre,pre+n+,now)-pre;
//cout<<aim<<endl;
if(aim==n+)
continue;
add[aim]+=t[aim]-(pre[aim]-now);
//cout<<t[aim]-(pre[aim]-now)<<endl;
ans[aim]--;
}
for(int i=;i<=n;i++)
{
ans[i]+=ans[i-];
}
for(int i=;i<=n;i++)
{
ll anser=(ans[i]+i)*t[i]+add[i];
cout<<anser<<" ";
}
cout<<endl; }
D.01字典树带删除路径(用数组维护)
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
ll mod = 3e7;
const int maxn = 3e5 + ;
int n, m;
int ch[ * maxn][];
int sum[ * maxn];
int a[maxn];
int b[maxn];
int node_cnt;
inline void read(int &jqk)
{
jqk = ;
char c = ;
int p = ;
while (c < '' || c > '')
{
if (c == '-')
{
p = -;
}
c = getchar();
}
while (c >= '' && c <= '')
{
jqk = (jqk << ) + (jqk << ) + c - '';
c = getchar();
}
jqk *= p;
}
void Insert(int x)
{
int cur = ;
for (int i = ; i >= ; i--)
{
int idx = (x >> i) & ;
if (!ch[cur][idx])
{
//ch[node_cnt][1] = ch[node_cnt][0] = 0;
ch[cur][idx] = ++node_cnt;
}
cur = ch[cur][idx];
sum[cur]++;
}
}
int getans(int x)
{
int anser = ;
int cur = ;
for (int i = ; i >= ; i--)
{
int idx = (x >> i) & ;
if (!ch[cur][idx] || !sum[ch[cur][idx]])
{
idx ^= ;
anser += ( << i);
}
cur = ch[cur][idx];
sum[cur]--;
}
return anser;
}
int main()
{
int n;
read(n);
for (int i = ; i <= n; i++)
{
read(a[i]);
}
for (int i = ; i <= n; i++)
{
read(b[i]);
Insert(b[i]);
}
for (int i = ; i <= n; i++)
{
cout << getans(a[i]) << " ";
}
cout << endl;
}
Codeforces 948 数论推导 融雪前缀和二分check 01字典树带删除的更多相关文章
- Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树
A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...
- [BZOJ4260] Codechef REBXOR (01字典树,异或前缀和)
Description Input 输入数据的第一行包含一个整数N,表示数组中的元素个数. 第二行包含N个整数A1,A2,-,AN. Output 输出一行包含给定表达式可能的最大值. Sample ...
- P4551 最长异或路径 (01字典树,异或前缀和)
题目描述 给定一棵 n 个点的带权树,结点下标从 1 开始到 N .寻找树中找两个结点,求最长的异或路径. 异或路径指的是指两个结点之间唯一路径上的所有边权的异或. 输入输出格式 输入格式: 第一行一 ...
- codeforces 842 D. Vitya and Strange Lesson(01字典树+思维+贪心)
题目链接:http://codeforces.com/contest/842/problem/D 题解:像这种求一段异或什么的都可以考虑用字典树而且mex显然可以利用贪心+01字典树,和线段树差不多就 ...
- Codeforces 979 D. Kuro and GCD and XOR and SUM(异或和,01字典树)
Codeforces 979 D. Kuro and GCD and XOR and SUM 题目大意:有两种操作:①给一个数v,加入数组a中②给出三个数x,k,s:从当前数组a中找出一个数u满足 u ...
- Codeforces Round #311 (Div. 2) E - Ann and Half-Palindrome(字典树+dp)
E. Ann and Half-Palindrome time limit per test 1.5 seconds memory limit per test 512 megabytes input ...
- Codeforces 954 dijsktra 离散化矩阵快速幂DP 前缀和二分check
A B C D 给你一个联通图 给定S,T 要求你加一条边使得ST的最短距离不会减少 问你有多少种方法 因为N<=1000 所以N^2枚举边数 迪杰斯特拉两次 求出Sdis 和 Tdis 如果d ...
- C - Monitor CodeForces - 846D (二维前缀和 + 二分)
Recently Luba bought a monitor. Monitor is a rectangular matrix of size n × m. But then she started ...
- Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset(01字典树求最大异或值)
http://codeforces.com/contest/706/problem/D 题意:有多种操作,操作1为在字典中加入x这个数,操作2为从字典中删除x这个数,操作3为从字典中找出一个数使得与给 ...
随机推荐
- socket的补充
- tomcat简单性能优化
1.内存使用配置 2.最大连接数配置
- PixelShuffle
- legend3---Homestead常用操作代码
legend3---Homestead常用操作代码 一.总结 一句话总结: 在虚拟机里面改变文件windows里面也会变,在windows里面改变虚拟机里面也会变,所以可以在windows里面编程或者 ...
- MIME 类型,ContentType
MIME (Multipurpose Internet Mail Extensions) 是描述消息内容类型的因特网标准. MIME 消息能包含文本.图像.音频.视频以及其他应用程序专用的数据. 官方 ...
- IFG以太网帧间隙
交换机的线速 描述交换机性能可以使用“线速”这个概念,那它是什么意思呢?所谓的线速是指经过交换机处理的理想状态下最大数据率.描述数据率可以用bps(bit per second)和mpps(milli ...
- hibernate+spring mvc,解决hibernate对象懒加载,json序列化失败
在使用spring MVC时,@ResponseBody 注解的方法返回一个有懒加载对象的时候出现了异常,以登录为例: @RequestMapping("login") @Resp ...
- lua源码学习篇四:字节码指令
在llimits.h文件中定义了指令的类型.其实就是32个字节. typedef lu_int32 Instruction; 上节说到变量最终会存入proto的数组k中,返回的索引放在expdesc ...
- 测开之路一百四十五:SQLAlchemy与后台模板整合之新增、查询、删除
实现在页面上点击展示页就展示内容,点击新增页就触发新增功能 项目结构 admin.__init__ from flask import Blueprint admin = Blueprint('adm ...
- Linux下安装redis-4.0.10
1.下载redis-4.0.10 在redis官网(https://redis.io/download)下载redis-4.0.10 2.将安装包上传至Linux服务器 在Linux服务器根目录下创建 ...