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. code first System.Data.Entity.Infrastructure.CommitFailedException: An error was reported while committing a database transaction but it could not be determined whether the transaction succeeded

    System.Data.Entity.Infrastructure.CommitFailedException: An error was reported while committing a da ...

  2. Vue/Element-ui 安装搭建开发环境(一)

    Element 是饿了么全段开发团队推出的一套基于 vue.js2.0 的 PC Web 端开发框架. Element 中文文档:https://element.eleme.cn/#/zh-CN 1. ...

  3. ffplay播放PCM裸流

    ffplay -f s16le -ar 48000 -ac 2 d:\lei.pcm

  4. Mybaits查询返回值是List类型的

    查询返回值是list类型的 1 首先在接口中写方法 public interface EmployeeMapper { public List<Employee> getEmpsByLas ...

  5. 洛谷P4095新背包问题

    传送 这道题最最暴力的方法就是对于每一个询问都跑一边多重背包问题,但显然q不会那么友好的让我们用暴力过掉这道题. 考虑优化.我们可以先把裸的多重背包搞成二进制优化后的多重背包.但是复杂度依然无法接受. ...

  6. 修改web项目发布路径

    Eclipse中用Tomcat发布的Web项目,更改其部署路径 我的Eclipse的工作目录是D:/workspace先配置Tomcat 选择你的tomcat版本 点击next 这里先不要把项目添加进 ...

  7. VC CString,int,string,char*之间的转换

    CString转string : CString strMfc = "test"; std::string strStr; strStr = strMfc.GetBuffer(); ...

  8. java利用zip解压slpk文件

    public static void main(String[] args) { File file = new File("C:\\Users\\Administrator\\Deskto ...

  9. mysql添加字段索引失败 BLOB/TEXT column 'col2' used in key specification without a key length

    看了下该表的数据结构发现col2字段类型是text ,查询了下发现是:MySQL只能将BLOB/TEXT类型字段设置索引为BLOB/TEXT数据的钱N个字符.索引指定下col2的长度就可以了 : al ...

  10. Linux_用户权限管理

    目录 目录 用户管理 useradd创建用户 userdel删除用户 usermod修改用户账号 passwd修改用户密码 用户权限设置 用户组管理 查看用户的属组 修改用户组gpasswd 为没有家 ...