Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2) (1208F,1208G,1208H)
1208 F
大意: 给定序列$a$, 求$\text{$a_i$|$a_j$&$a_k$}(i<j<k)$的最大值
枚举$i$, 从高位到低位贪心, 那么问题就转化为给定$x$, 求判断$[i+1,n]$内二进制包含$x$的个数是否不少于$2$, 可以对每个状态, 维护最远的两个位置即可.
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc tr[o].l
#define rc tr[o].r
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head const int N = 3e6+10;
int n, a[N], vis[N], pre[N];
pii dp[N];
void add(int x, int p) {
if (dp[x].x&&dp[x].y) return;
if (dp[x].x==p||dp[x].y==p) return;
if (!dp[x].y) dp[x].y = p;
else dp[x].x = p;
REP(i,0,21) if (x>>i&1) add(x^1<<i,p);
}
int main() {
scanf("%d", &n);
REP(i,1,n) scanf("%d",a+i);
PER(i,1,n) add(a[i],i);
REP(i,1,n-2) vis[i] = 1;
int ans = 0;
PER(d,0,21) {
REP(i,1,n) if (vis[i]) {
if (a[i]>>d&1^1) {
pre[i] ^= 1<<d;
if (!dp[pre[i]].y||dp[pre[i]].x<=i) vis[i] = -1;
}
}
REP(i,1,n) if (vis[i]==1) ans |= 1<<d;
REP(i,1,n) if (vis[i]==-1) {
if (ans>>d&1) vis[i] = 0;
else vis[i] = 1, pre[i] ^= 1<<d;
}
}
printf("%d\n", ans);
}
1208 G
大意: 求$k$个不同边数的有相同外接圆正多边形, 使得顶点数最少.
显然所有多边形一定共用一个顶点$P$, 每个点就可以用它到$P$的距离来表示, 比如$k$边形表示为$0,\frac{1}{k},...,\frac{k-1}{k}$.
答案就为不同的分数个数, 那么考虑添加一个$k$边形, 它的贡献就是所有未出现过的因子的$\varphi$之和.
当$k$为$1$时直接取三角形即可, 其余情况把$\varphi$的前$n$项排序后取前$k+2$大即为答案, 这是因为对于一个$x$边形, 它的所有因子$y$满足$\varphi(y)\le \varphi(x),y<x$, 所以枚举到$x$时它的因子一定已经算过了.
1208 H
大意: 给定树, 每个点为蓝色或红色, 给定叶子颜色, 其余点记$b$为蓝儿子数, $r$为红儿子数, 若$b-r\ge k$为蓝色, 否则为红色. 要求实现三种操作: (1)求点$v$的颜色 (2)改变叶子$v$的颜色 (3)$k$的值改为$h$
Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2) (1208F,1208G,1208H)的更多相关文章
- Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-D. Restore Permutation-构造+树状数组
Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-D. Restore Permutation-构造+树状数组 [Pro ...
- Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-C. Magic Grid-构造
Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-C. Magic Grid-构造 [Problem Descripti ...
- Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-E. Let Them Slide-思维+数据结构
Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-E. Let Them Slide-思维+数据结构 [Problem ...
- Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2) F. Bits And Pieces sosdp
F. Bits And Pieces 题面 You are given an array
- Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2) G. Polygons 数论
G. Polygons Description You are given two integers
- RMQ+差分处理(Let Them Slide)Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)
题意:https://codeforc.es/contest/1208/problem/E 现有n行w列的墙,每行有一排连续方块,一排方块可以左右连续滑动,且每个方块都有一个价值,第i 列的价值定义为 ...
- 线段树维护最后一个0的位置(Restore Permutation)Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)
题意:https://codeforc.es/contest/1208/problem/D 给你长度为n的序列,s[i]的值为p[1]到p[i-1]中比p[i]小的数的和,让你求出p序列. 思路: 首 ...
- Codeforces Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)
传送门 A. XORinacci 手玩三四项发现序列就是 $a,b,a\ xor\ b,a,b,...$,直接输出即可 #include<iostream> #include<cst ...
- Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)E(多重集维护)
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;long long ans[1000007]; ...
随机推荐
- make 实例 一 3463
######################################################################### # # Makefile used for buil ...
- NTC3950-10K温度传感器
一.计算公式 补充: B=3950 R=10K T2=25度 查RT表,25度对应的是10K 电路: 热敏电阻与上拉电阻R813分压,获取温度与Vo电压的关系,在根据Vo折算出与MCU ADC的数值. ...
- JVM 类加载器的双亲委托机制
1.类加载器的层次结构 在双亲委托机制中,各个加载器按照父子关系形成了树形结构(逻辑意义),除了根加载器之外,其余的类加载器都有且只有一个父加载器. public class MyTest13 { p ...
- markdown如何在表格内换行?
答:使用<br>即可在表格内换行
- pip安装各种模块
date: 2019-08-20 19:27:09 pip install requests pip install xpinyin pip install redis
- Spring cloud微服务安全实战-3-6API安全机制之数据校验
校验:非空.唯一性等校验 密码的加密:密码加密来存储. 如何做https的访问 校验 一个层面是接口层面,另外一个层面是数据库层面. Springboot给我们提供了简单的封装 校验的包里面还有其他的 ...
- matlab学习笔记1--matlab工作界面
一起来学matlab-matlab学习笔记1--matlab工作界面 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考书籍 <matlab 程序设计与综合应用>张德丰等著 感谢 ...
- Python json序列化时default/object_hook指定函数处理
在Python中,json.dumps函数接受参数default用于指定一个函数,该函数能够把自定义类型的对象转换成可序列化的基本类型.json.loads函数接受参数objec_thook用于指定函 ...
- django.db.utils.OperationalError: (1251, 'Client does not support authentication protocol requested by server; consider upgrading MySQL client')
1.打开MySQL: cmd里 net start mysql mysql -hlocalhost -uroot -p回车 进入mysql数据库 2. 命令如下: 1.use mysql; 2.alt ...
- (十四)访问标志 Access_flags
一.概念 上一章节讲到了常量池,如下图,常量池之后便是访问标志acess_flags,占2个字节(u2). 二.例子 编写一个接口. public interface Test{ public fin ...