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字典树带删除的更多相关文章

  1. Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树

    A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...

  2. [BZOJ4260] Codechef REBXOR (01字典树,异或前缀和)

    Description Input 输入数据的第一行包含一个整数N,表示数组中的元素个数. 第二行包含N个整数A1,A2,-,AN. Output 输出一行包含给定表达式可能的最大值. Sample ...

  3. P4551 最长异或路径 (01字典树,异或前缀和)

    题目描述 给定一棵 n 个点的带权树,结点下标从 1 开始到 N .寻找树中找两个结点,求最长的异或路径. 异或路径指的是指两个结点之间唯一路径上的所有边权的异或. 输入输出格式 输入格式: 第一行一 ...

  4. codeforces 842 D. Vitya and Strange Lesson(01字典树+思维+贪心)

    题目链接:http://codeforces.com/contest/842/problem/D 题解:像这种求一段异或什么的都可以考虑用字典树而且mex显然可以利用贪心+01字典树,和线段树差不多就 ...

  5. 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 ...

  6. 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 ...

  7. Codeforces 954 dijsktra 离散化矩阵快速幂DP 前缀和二分check

    A B C D 给你一个联通图 给定S,T 要求你加一条边使得ST的最短距离不会减少 问你有多少种方法 因为N<=1000 所以N^2枚举边数 迪杰斯特拉两次 求出Sdis 和 Tdis 如果d ...

  8. C - Monitor CodeForces - 846D (二维前缀和 + 二分)

    Recently Luba bought a monitor. Monitor is a rectangular matrix of size n × m. But then she started ...

  9. Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset(01字典树求最大异或值)

    http://codeforces.com/contest/706/problem/D 题意:有多种操作,操作1为在字典中加入x这个数,操作2为从字典中删除x这个数,操作3为从字典中找出一个数使得与给 ...

随机推荐

  1. 身份证最后一位按照ISO7064:1983.MOD11-2校验码

    居民身份证号码,根据[中华人民共和国国家标准 GB 11643-1999]中有关公民身份号码的规定,公民身份号码是特征组合码,由十七位数字本体码和一位数字校验码组成.排列顺序从左至右依次为:六位数字地 ...

  2. iOS证书发布推送相关知识科普

    账号种类 1.企业账号 299美刀 -- 可以自己发布App,不能发布到App Store 2.个人/公司账号 99美刀 -- 可以发布到App Store, 不可以自己发布不限安装数量的App 个人 ...

  3. laravel Route::resource() 资源路由

    格式: Route::resource('/order', 'OrderController', ['as' => 'admin']); 框架自动创建路由及其对应控制器中的方法: 请求方式 路由 ...

  4. JVM参数设置-jdk8参数设置

    JVM参数设置 1.基本参数 参数名称 含义 默认值   -Xms 初始堆大小 内存的1/64 默认(MinHeapFreeRatio参数可以调整)空余堆内存小于40%时,JVM就会增大堆直到-Xmx ...

  5. Ubuntu C/C++的编译环境

    Ubuntu缺省情况下,并没有提供C/C++的编译环境,因此还需要手动安装.但是如果单独安装gcc以及g++比较麻烦,幸运的是,Ubuntu提供了一个build-essential软件包.查看该软件包 ...

  6. framework7 底部弹层popup js关闭方法

    <div class="u-sd-btns"> <button>同意</button> <button class="popup ...

  7. Python中的Django框架中prefetch_related()函数对数据库查询的优化

    实例的背景说明 假定一个个人信息系统,需要记录系统中各个人的故乡.居住地.以及到过的城市.数据库设计如下: Models.py 内容如下: ? 1 2 3 4 5 6 7 8 9 10 11 12 1 ...

  8. Gradle之Gradle 源码分析(四)

    Gradle 的启动 constructTaskGraph runTasks finishBuild gradle 脚本如何编译和执 插件调用流程 一.Gradle 的启动 1.1 整体实现图 1.2 ...

  9. 2d平台怪物逻辑

    2d来回巡逻 遇到坑会自动转向 可配置单次方向行走的时间,转向等待时间等 using System; using System.Collections; using System.Collection ...

  10. k8s--资源控制器

    资源控制器 1.什么是控制器 Kubernetes中内建了很多controller (控制器) ,这些相当于一个状态机,用来控制Pod的具体状态和行为 Pod 的分类 自主式 Pod:Pod 退出了, ...