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为从字典中找出一个数使得与给 ...
随机推荐
- 解决CsvWriter:中文乱码、末尾行多一行空格(/r)、非第一列空字符串""显示null问题
一:主要内容 解决CsvWriter存csv,csv文件打开后中文乱码问题 解决CsvWriter存csv,csv文件最后一行总是多一行空行的问题 解决CsvWriter存csv,csv文件不是第一列 ...
- lnmp源码搭建
Nginx工作原理 这里需要结合Apache的工作,对PHP文件处理过程的区别 1:Nginx是通过php-fpm这个服务来处理php文件 2:Apache是通过libphp5.so ...
- Git:目录
ylbtech-Git:目录 1.返回顶部 1. https://git-scm.com/ 2. 2.返回顶部 1.Easy Git Integration Tools https://marketp ...
- lambda表达式使用解析
1.Predicate/Consumer/Function/Supplier介绍 Predicate boolean test(T t); Consumer accpet(T t); Function ...
- Octavia 创建 Listener、Pool、Member、L7policy、L7 rule 与 Health Manager 的实现与分析
目录 文章目录 目录 创建 Listener 创建 Pool 创建 Member CalculateDelta HandleNetworkDeltas AmphoraePostNetworkPlug ...
- Apache监控调优
apache是一款对静态资源处理得比较好的中间件,但是对动态请求处理得不是很好,tomcat则正好相反. apache运用得比较多得工作模式主要是Prefork和Worker两种模式 1.Prefor ...
- oracle dis系列课程总结
oracle dis系列课程总结 1 bbed安装和介绍 --1 bbed的安装--(Oracle Block Brower and EDitor Tool) 2 controlfile 丢失的恢复 ...
- 彻底理解RSA算法原理
1. 什么是RSA RSA算法是现今使用最广泛的公钥密码算法,也是号称地球上最安全的加密算法.在了解RSA算法之前,先熟悉下几个术语 根据密钥的使用方法,可以将密码分为对称密码和公钥密码 对称密码:加 ...
- idea中配置tomcat详细
1:首先要添加一个tomcat流程 2:配置tomcat: 3:配置tomcat中的deployment(就是配置你需要部署的工程) 4:配置tomcat中需要输出的日志logs 5:启动 tomca ...
- codeforces 1156E Special Segments of Permutation
题目链接:https://codeforc.es/contest/1156/problem/E 题目大意: 在数组p中可以找到多少个不同的l,r满足. 思路: ST表+并查集. ST表还是需要的,因为 ...