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)的更多相关文章

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

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

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

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

  5. Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2) G. Polygons 数论

    G. Polygons Description You are given two integers

  6. 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 列的价值定义为 ...

  7. 线段树维护最后一个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序列. 思路: 首 ...

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

  9. 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]; ...

随机推荐

  1. [转]IDE 、SATA、SCSI 的区别

    IDE IDE的英文全称为“Integrated Drive Electronics”,即“电子集成驱动器”,它的 本意是指把“硬盘控制器”与“盘体”集成在一起的硬盘驱动器 .把盘体与控制器集成在 一 ...

  2. Acer笔记本如何装系统?

    一.准备工作 1.一个有win7或者XP系统的电脑(制作启动盘用) 2.一个8G以上的U盘 3.win7&win8系统包(win8.1下载地址:http://pan.baidu.com/s/1 ...

  3. [转]Git 代码撤销、回滚到任意版本(当误提代码到本地或master分支时)

    两种情况(场景) 情况一      代码还只在本地,未push到运程仓库,想把代码还原到上一次commit的代码,此时操作为代码撤销 解决方案: 1 git reset [--hard|soft|mi ...

  4. OpenJudge 计算概论1007:点评赛车

    总时间限制: 1000ms 内存限制: 65536kB描述4名专家对4款赛车进行评论1)A说:2号赛车是最好的:2)B说:4号赛车是最好的:3)C说:3号赛车不是最好的:4)D说: B说错了.事实上只 ...

  5. Maltego更新到4.2.4.12374

    Maltego更新到4.2.4.12374   这次更新修改多个bug,并增加一些的特性和功能.主要变化如下: (1)允许用户直接复制实例的属性,以粘贴方式创建新实体. (2)右击网址类实体,右键菜单 ...

  6. 小D课堂 - 零基础入门SpringBoot2.X到实战_第9节 SpringBoot2.x整合Redis实战_40、Redis工具类封装讲解和实战

    笔记 4.Redis工具类封装讲解和实战     简介:高效开发方式 Redis工具类封装讲解和实战         1.常用客户端 https://redisdesktop.com/download ...

  7. 移动端IM系统的协议选型:UDP还是TCP?(转)

    源: 移动端IM系统的协议选型:UDP还是TCP?

  8. 【转】项目搬迁,快捷导出环境依赖包到requirements.txt

    项目搬迁的时候,需要把当前的环境依赖包导出,然后到部署项目的服务器上安装依赖. 我们可以通过下面的命令执行,把依赖包导出到requirements.txt文件里. 生成requirements.txt ...

  9. Python记录-基础语法入门

    # -*- coding: utf-8 -*- #数字计算 a=1 b=2 print(a+b) print(a*b) print((a+b)/1) #浮点数 print((a+b)//2) ##保留 ...

  10. Python手册 3.7

    Python手册 3.7 下载地址:https://pan.baidu.com/s/1dPzwwP3ehnyLUNWTsB2QJg 关注微信公众号获取提取码: 输入:py99   获取提取码