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为从字典中找出一个数使得与给 ...
随机推荐
- @清晰掉 spi协议及工作原理分析
说明.文章摘自:SPI协议及其工作原理浅析 http://bbs.chinaunix.net/thread-1916003-1-1.html 一.概述. SPI, Serial Perripheral ...
- JNI写本地日志文件
调试JNI库 我喜欢反编译APK 然后替换.so文件 然后再编译成APK 其中写日志的话 用fopen("/sdcard/lei.txt","wb+")
- 通过同步上下文方式更新winform中的控件信息
SynchronizationContext 类是一个基类,可提供不带同步的自由线程上下文. 此类实现的同步模型的目的是使公共语言运行库内部的异步/同步操作能够针对不同的异步模型采取正确的行为.此模型 ...
- ICML 2019 分析
ICML 2019 分析 Word Embeddings Understanding the Origins of Bias in Word Embeddings Popular word embed ...
- 【漏洞复现】永恒之蓝 ms17-010 漏洞利用 攻击手法
日期:2018-07-21 21:09:16 介绍:永恒之蓝利用的 ms17-010 漏洞,拿 Shell.查看文件.获取密码. 0x01.实验环境 攻击机 系统:macOS Sierra 10.12 ...
- Java使用JDBC连接Hive
最近一段时间,处理过一个问题,那就是hive jdbc的连接问题,其实也不是大问题,就是url写的不对,导致无法连接.问题在于HiveServer2增加了别的安全验证,导致正常的情况下,传递的参数无法 ...
- vs2010发布网站时有些文件没有发布出去的解决办法。
项目中包含了一些ttf字体文件做为图标使用,可是发布时发现生成的目录中没有这个文件,这种情况这么设置一下就可以解决: 1,在文件上点击右键,选择“属性”. 2,在弹出的属性窗口中,更改“生成操作”为“ ...
- Linux中MySQL5.7设置utf8编码格式步骤
关于编码问题,真的是弄得我很郁闷,网上找的帖子这方面也很多但都无济于事,晚上终于找到一篇有效的,特此贴上. 转自Ubuntu中MySQL5.7设置utf8编码格式步骤 1.首先打开终端 2.输入mys ...
- diff patch比较文件打补丁
比较文件将结果保存到patch文件:diff -u test1.txt test2.txt > patchfile test1.txt应用patch文件,并备份(test1.txt.orig): ...
- vue 格式化时间的插件库
格式化时间的插件库 点击进入 moment.js网址 ,在这里可以找到需要引入的script标签 点击进入 moment.js的文档 在文档中可以找到对应的格式和例子 此文来源于: https://w ...