CF1208

打的话貌似能够涨分的样子?

A

水题

B

枚举左端点,看看右端点的最近位置

开一个类似于桶的东西维护一下上一次出现位置

左端点左边就删掉,否则就要将上一次出现的位置删掉

时间复杂度\(O(n^2)\)或者\(O(n^2logn)\)取决于是否离散化

貌似一个log就是二分答案

然后\(O(n)\)check一遍

#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<vector>
#include<ctime>
#include<map>
#define LL long long
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
using namespace std;
const int N = 2003;
int a[N];
int pre[N];
map <int,int> m;
int n;
inline int read(){
int v = 0,c = 1;char ch = getchar();
while(!isdigit(ch)){
if(ch == '-') c = -1;
ch = getchar();
}
while(isdigit(ch)){
v = v * 10 + ch - 48;
ch = getchar();
}
return v * c;
}
int main(){
int ans = 0x3f3f3f3f;
n = read();
for(int i = 1;i <= n;++i){
a[i] = read();
if(!m[a[i]]) m[a[i]] = i;
else pre[i] = m[a[i]];
m[a[i]] = i;
// printf("%d\n",pre[i]);
}
bool flag = 1;
for(int i = 1;i <= n;++i){
m.clear();
int r = 0;
for(int j = 0;j < i;++j){
if(m[a[j]] == -1) {flag = 0;break;}
m[a[j]] = -1;
}
if(!flag) break;
for(int j = i;j <= n;++j){
if(m[a[j]] == -1) r = max(r,j);
else if(m[a[j]] != 0){
r = max(r,m[a[j]]);
m[a[j]] = j;
}
else m[a[j]] = j;
}
if(r != 0) ans = min(ans,r - i + 1);
else ans = 0;
}
cout << ans;
return 0;
}

听说貌似有\(O(n)\)做法不大会

C

构造题

分成四块考虑,因为题目中保证是\(4\)的倍数

首先,如果没有\(0-n^2-1\)这个限制

这样子肯定符合要求

\(\begin{array}{cccc}{0} & {0} & {1} & {1} \\ {0} & {0} & {1} & {1} \\ {2} & {2} & {3} & {3} \\ {2} & {2} & {3} & {3}\end{array}\)

但是这样肯定不符合题意

那么我们就对于给每一部分编号

把这一部分整体+4

\(\begin{array}{cccc}{0} & {4} & {1} & {5} \\ {8} & {12} & {9} & {13} \\ {2} & {6} & {3} & {7} \\ {10} & {14} & {11} & {15}\end{array}\)

如果没有保证\(n\)是\(4\)的倍数,那么这样构造一定不对,因为每一行都有数出现了奇数次

由于每一行每一列

每个\(4\)的倍数都只被加了两次

异或起来都答案是没有影响的

那么我们照着这样子构造就好了

D

感觉D是个一眼题,CD应该换一下位置的

最右边的\(0\)对应的位置一定是\(1\)

然后把\(1\)的贡献去掉之后,最右边的\(0\)一定是\(2\)

以此类推

线段树搞一搞就好了

#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<vector>
#include<ctime>
#define LL long long
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
using namespace std;
const int N = 2e5 + 3;
const LL INF = 1e15;
LL dis[N];
int an[N];
int n,root;
inline LL read(){
LL v = 0,c = 1;char ch = getchar();
while(!isdigit(ch)){
if(ch == '-') c = -1;
ch = getchar();
}
while(isdigit(ch)){
v = v * 10 + ch - 48;
ch = getchar();
}
return v * c;
}
struct Tree{
int t;
struct node{
LL maxx;
LL tag;int pos;
int lc,rc;
}a[N << 2];
inline void pushup(int u){
if(a[a[u].lc].maxx < a[a[u].rc].maxx) a[u].maxx = a[a[u].lc].maxx,a[u].pos = a[a[u].lc].pos;
else a[u].maxx = a[a[u].rc].maxx,a[u].pos = a[a[u].rc].pos;
}
inline void pushdown(int u,int l,int r){
if(!a[u].tag) return;
a[a[u].lc].maxx += a[u].tag;
a[a[u].rc].maxx += a[u].tag;
a[a[u].lc].tag += a[u].tag;
a[a[u].rc].tag += a[u].tag;
a[u].tag = 0;
return ;
}
inline void build(int &u,int l,int r){
if(!u) u = ++t;
if(l == r){
a[u].maxx = dis[l];
a[u].pos = l;
return ;
}
int mid = (l + r) >> 1;
build(a[u].lc,l,mid);build(a[u].rc,mid + 1,r);
pushup(u);
}
inline void updata(int u,int l,int r,int ll,int rr,LL w){
if(ll > rr) return;
if(l == ll && r == rr){
a[u].maxx += w;
a[u].tag += w;
return ;
}
pushdown(u,l,r);
int mid = (l + r) >> 1;
if(rr <= mid) updata(a[u].lc,l,mid,ll,rr,w);
else if(ll > mid) updata(a[u].rc,mid + 1,r,ll,rr,w);
else{
updata(a[u].lc,l,mid,ll,mid,w);
updata(a[u].rc,mid + 1,r,mid + 1,rr,w);
}
pushup(u);
}
inline int query(){return a[root].pos;}
}T;
int main(){
n = read();
for(int i = 1;i <= n;++i) dis[i] = read();
T.build(root,1,n);
// cout << "GG" << endl;
for(int i = 1;i <= n;++i){
int x = T.query();
an[x] = i;
T.updata(root,1,n,x + 1,n,-i);
T.updata(root,1,n,x,x,INF);
}
for(int i = 1;i <= n;++i) printf("%d ",an[i]);
return 0;
}

E

当时就硬是没想出来差分的技巧

首先每个位置可以取到的数肯定是

\([x - (w - len),x+(w -len)]\)这个区间的最大值

之后我们分两种情况讨论

首先

当\(len >= w -len\)时

这时候会长成这个样子

我们设\(d = w - len\)表示能够滑动的距离

对于一个位置\(x\)

首先,绿色部分是只能够从左向右取最大值\([x - d,x]\)

红色只能从右向左取最大值\([x,x + d]\)

中间部分呢?这一部分你会发现

这一部分其实可以和红色或者绿色任意一部分合起来算

这个时候注意不要把黄色部分重复计算就好

当\(len < w - len\)时

这个时候,中间的黄色部分的答案,就变成了序列中的最大值和\(0\)取max

因为中间部分是可以取到序列中的任意数

所以我们只需要维护区间最大值,这个东西随便搞搞吧

注意判断越界时要和\(0\)取max,表示可以不选

#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<vector>
#include<deque>
#include<ctime>
#define LL long long
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
using namespace std;
const int N = 1e6 + 3;
const int INF = 2e9;
int n,len,w;
int f[21][N];
LL ans[N];
int lg[N];
inline int read(){
int v = 0,c = 1;char ch = getchar();
while(!isdigit(ch)){
if(ch == '-') c = -1;
ch = getchar();
}
while(isdigit(ch)){
v = v * 10 + ch - 48;
ch = getchar();
}
return v * c;
}
inline void pre(){
for(int j = 1;(1 << j) <= len;++j){
for(int i = 1;i + (1 << j) - 1 <= len;++i)
f[j][i] = max(f[j - 1][i],f[j - 1][i + (1 << (j - 1))]);
}
}
inline int work(int l,int r){
int k = lg[r - l + 1];
return max(f[k][l],f[k][r - (1 << k) + 1]);
}
inline int query(int l,int r){
if(l < 1 || r > len) return max(0,work(max(1,l),min(len,r)));
else return work(l,r);
}
int main(){
lg[1] = 0;
for(int i = 2;i <= 1000000;++i) lg[i] = lg[i >> 1] + 1;
n = read(),w = read();
for(int i = 1;i <= n;++i){
len = read();
for(int j = 1;j <= len;++j) f[0][j] = read();
pre();
for(int i = 1;i <= len;++i){
int k = query(i,i + w - len);
ans[i + w - len] += k;
ans[i + w - len + 1] -= k;
}
for(int i = 1;i <= min(len,w - len);++i){
int k = query(i - w + len,i);
ans[i] += k;
ans[i + 1] -= k;
}
if(len < w - len){
int k = max(0,query(1,len));
ans[len + 1] += k;
ans[w - len + 1] -= k;
}
}
for(int i = 1;i <= w;++i) {ans[i] += ans[i - 1];printf("%lld ",ans[i]);}
return 0;
}

F

神仙题解\(SOS DP\)

题目大意求\((i,j,j)i < j < k\)使得\(a_i | (a_j \&a_i)\)最大

\(n <= 10^6,a_i < 2^{21}\)

考虑从从后向前枚举\(i\)

从高位向低位贪心

设\(dp_x\)表示\(x\)设个二进制集合被多少数完全包含

每次对于一个\(a_i\)

从大到小枚举所有位

如果这个位\(j\)不是\(1\)同时满足当前贪心的结果\(x\),\(x | (1 << j)\)被超过两个数包含(保证\(\&\)完之后有这个数)就将这一位加入贪心的答案

更新完答案之后就把每一位包含\(a_i\)的加入

时间复杂度貌似有点爆炸

但是我们发现如果\(dp_x >=2\)那么直接return

所以每个位置最多被更新两次

均摊是\(2^{21}\)的复杂度

#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<vector>
#include<ctime>
#define LL long long
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
using namespace std;
const int N = 1e6 + 3;
int a[N];
int cnt[N << 2];
int n;
inline int read(){
int v = 0,c = 1;char ch = getchar();
while(!isdigit(ch)){
if(ch == '-') c = -1;
ch = getchar();
}
while(isdigit(ch)){
v = v * 10 + ch - 48;
ch = getchar();
}
return v * c;
}
int ans = 0;
inline void ins(int x,int d){
if(cnt[x] >= 2) return;
if(d == -1){cnt[x]++;return;}
ins(x,d - 1);
if(x & (1 << d)) ins(x ^ (1 << d),d - 1);
}
inline int query(int x){
int now = 0;
for(int i = 20;i >= 0;--i) if(((x & (1 << i)) == 0) && cnt[now | (1 << i)] >= 2) now |= 1 << i;
return now | x;
}
int main(){
n = read();
for(int i = 1;i <= n;++i) a[i] = read();
for(int i = n;i >= 1;--i){
if(i <= n - 2) ans = max(ans,query(a[i]));
ins(a[i],20);
}
printf("%d\n",ans);
return 0;
}

CF1208的更多相关文章

  1. CF-1208 C.Magic Grid

    题目 大意:构造一个n行n列的矩阵,使得每一行,每一列的异或和都相等,n是4的倍数. 先看4*4的矩阵,我们很容易构造出符合要求的矩阵,比如 0    1    2    3 4    5    6  ...

  2. CF1208题解

    C \(\begin{aligned}\ 0 0 1 1\\ 0 0 1 1\\ 2 2 3 3\\ 2 2 3 3\\ \end{aligned}\)将每个四方格分别加上\(0,4,8,12\) D ...

  3. CF1208 Red Blue Tree

    题目链接 问题分析 这是蒟蒻第一道3500!不过话说luogu上两个题解的程序都是假的可还行(2019.11.1)-- 为了方便叙述,下面我们约定 : \([c]\) 的值为 \(1\) 当且仅当 \ ...

  4. cf1208 E Let Them Slide(差分+RMQ\单调队列)

    题意 如题目的图所示,每行都可以左右移动,但是数字不允许断开,且不许越界(宽度为w). 单独求每一列的最大的和为多少. 思路 对于每一列来说,在每一行上都有一个可以取到的区间, 所以,对于一列来说,答 ...

  5. cf1208 D Restore Permutation (二分+树状数组)

    题意 让你构造一个长度为n的序列,记为p1……pn,(这个序列是1~n的全排列的一种) 给你n个数,记为s1……sn,si的值为p1……pi-1中小于pi的数的和. 思路 显然,应该倒着来,也就是从p ...

随机推荐

  1. kubernetes1.4新特性:支持Docker新特性

    (一)背景资料 在Kubernetes1.2中这个第三方组件就是go-dockerclient,这是一个GO语言写的docker客户端,支持Dockerremote API,这个项目在https:// ...

  2. Navicat连接MySQL8.0版本时 建议升级连接客户端这个提示怎么办

    开始->mysql 8.0 command line client ->执行下面的命令//开启mysql服务mysql.server start//进入mysqlmysql -u root ...

  3. websocket实现数据库更新时前端页面实时刷新

    websocket实现数据库更新时前端页面实时刷新 javaweb 目录(?)[+] userjsp ManagerServletjava 如题,实现以上功能,我知道主要有两大种思路: 轮询:轮询的原 ...

  4. oracle函数 nls_charset_id(c1)

    [功能]返回字符集名称参应id值 [参数]c1,字符型 [返回]数值型 sql> select nls_charset_id('zhs16gbk') from dual; nls_charset ...

  5. PyODPS DataFrame 处理笛卡尔积的几种方式

    PyODPS 提供了 DataFrame API 来用类似 pandas 的接口进行大规模数据分析以及预处理,本文主要介绍如何使用 PyODPS 执行笛卡尔积的操作. 笛卡尔积最常出现的场景是两两之间 ...

  6. HZOJ string

    正解炸了…… 考试的时候想到了正解,非常高兴的打出来了线段树,又调了好长时间,对拍了一下发现除了非常大的点跑的有点慢外其他还行.因为复杂度算着有点高…… 最后正解死于常数太大……旁边的lyl用同样的算 ...

  7. [Pytorch]基于混和精度的模型加速

    这篇博客是在pytorch中基于apex使用混合精度加速的一个偏工程的描述,原理层面的解释并不是这篇博客的目的,不过在参考部分提供了非常有价值的资料,可以进一步研究. 一个关键原则:“仅仅在权重更新的 ...

  8. 【微信小程序】下载并预览文档——pdf、word、excel等多种类型

    .wxml文件 <view data-url="https://XXX/upload/zang." data-type="excel" catchtap= ...

  9. setTimeout与setInterval有何区别?

    ①setTimeout和setInterval的语法相同.它们都有两个参数,一个是将要执行的代码字符串,还有一个是以毫秒为单位的时间间隔,当过了那个时间段之后就将执行那段代码. ②不过这两个函数还是有 ...

  10. Spring的注解@Qualifier注解

    @Qualifier注解了,qualifier的意思是合格者,通过这个标示,表明了哪个实现类才是我们所需要的,我们修改调用代码,添加@Qualifier注解,需要注意的是@Qualifier的参数名称 ...