F:考虑对于每个字母对求出删掉哪些字符集会造成字符串不合法,只要考虑相邻出现的该字母对即可,显然这可以在O(np2)(或小常数O(np3))内求出。然后再对每个字符集判断是否能通过一步删除转移而来即可。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 100010
#define M 17
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,m,c[N],b[N],cnt[M],ans;
char s[N];
bool a[M][M],f[1<<M],g[1<<M];
signed main()
{
#ifndef ONLINE_JUDGE
freopen("f.in","r",stdin);
freopen("f.out","w",stdout);
const char LL[]="%I64d\n";
#endif
n=read(),m=read();
scanf("%s",s+1);for (int i=1;i<=n;i++) cnt[c[i]=s[i]-'a']++;
for (int i=0;i<m;i++)
for (int j=0;j<m;j++)
{
a[i][j]=read();
if (i<=j&&!a[i][j])
{
memset(g,0,sizeof(g));int last=-1,s=0;
for (int x=1;x<=n;x++)
{
if (c[x]==i||c[x]==j)
{
if (last==i+j-c[x]) g[s]=1;
last=c[x];s=0;
}
else s|=(1<<c[x]);
}
for (int x=1;x<(1<<m);x++)
if (!g[x]&&!(x&(1<<i))&&!(x&(1<<j)))
{
for (int t=x,y=t&-t;t;t^=y,y=t&-t)
g[x]|=g[x^y];
}
for (int x=0;x<(1<<m);x++) f[x]|=g[x];
}
}
ans=n;
for (int i=1;i<(1<<m);i++)
{
if (!f[i])
{
f[i]=1;
for (int j=0;j<m;j++)
if ((i&(1<<j))&&!f[i^(1<<j)]) {f[i]=0;break;}
}
if (!f[i])
{
int tot=n;
for (int j=0;j<m;j++) if (i&(1<<j)) tot-=cnt[j];
ans=min(ans,tot);
}
}
cout<<ans;
return 0;
//NOTICE LONG LONG!!!!!
}

  G:考虑一个数被删掉对一个区间产生的贡献,只考虑某一侧,显然如果该区间内该数为最大值,贡献即为该侧区间长度,否则为其到下一个比他大的数的距离。离线后扫过去维护贡献,线段树实现区间加一次函数即可。又卡我常!

#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 1000010
#define tree lazy
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,m,a[N],nxt[N],L[N<<2],R[N<<2];
ll ans[N],lazy[N<<2][2];
struct data{int l,r,i;ll ans;
}q[N];
bool cmp(const data&a,const data&b)
{
return a.l<b.l;
}
void build(int k,int l,int r)
{
L[k]=l,R[k]=r;lazy[k][0]=lazy[k][1]=0;
if (l==r) return;
int mid=l+r>>1;
build(k<<1,l,mid);
build(k<<1|1,mid+1,r);
}
void down(int k)
{
tree[k<<1][0]+=tree[k][0],tree[k<<1|1][0]+=tree[k][0],tree[k][0]=0;
tree[k<<1][1]+=tree[k][1],tree[k<<1|1][1]+=tree[k][1],tree[k][1]=0;
}
ll query(int k,int p)
{
if (L[k]==R[k]) return 1ll*lazy[k][1]*p+lazy[k][0];
down(k);
int mid=L[k]+R[k]>>1;
if (p<=mid) return query(k<<1,p);
else return query(k<<1|1,p);
}
void add(int k,int l,int r,int u,int x)
{
if (L[k]==l&&R[k]==r) {lazy[k][1]++;lazy[k][0]+=x;return;}
down(k);
int mid=L[k]+R[k]>>1;
if (r<=mid) add(k<<1,l,r,u,x);
else if (l>mid) add(k<<1|1,l,r,u,x);
else add(k<<1,l,mid,u,x),add(k<<1|1,mid+1,r,u,x);
}
void add(int k,int l,int r,int x)
{
if (L[k]==l&&R[k]==r) {lazy[k][0]+=x;return;}
down(k);
int mid=L[k]+R[k]>>1;
if (r<=mid) add(k<<1,l,r,x);
else if (l>mid) add(k<<1|1,l,r,x);
else add(k<<1,l,mid,x),add(k<<1|1,mid+1,r,x);
}
void solve()
{
nxt[n+1]=n+1;
for (int i=n;i>=1;i--)
{
int j=i+1;
while (a[j]<a[i]) j=nxt[j];
nxt[i]=j;
}
build(1,1,n);
sort(q+1,q+m+1,cmp);
int cur=0;
for (int i=1;i<=n;i++)
{
while (q[cur+1].l==i) cur++,q[cur].ans-=query(1,q[cur].r);
add(1,i,nxt[i]-1,1,-i);
if (nxt[i]<=n) add(1,nxt[i],n,nxt[i]-i-1);
}
for (int i=1;i<=m;i++) q[i].ans+=query(1,q[i].r);
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("g.in","r",stdin);
freopen("g.out","w",stdout);
#endif
n=read(),m=read();
for (int i=1;i<=n;i++) a[i]=read();
a[0]=a[n+1]=n+1;
for (int i=1;i<=m;i++) q[i].l=read();
for (int i=1;i<=m;i++) q[i].r=read();
for (int i=1;i<=m;i++) q[i].i=i;
solve();
reverse(a+1,a+n+1);for (int i=1;i<=m;i++) q[i].l=n-q[i].l+1,q[i].r=n-q[i].r+1,swap(q[i].l,q[i].r);
solve();
for (int i=1;i<=m;i++) q[i].ans+=q[i].r-q[i].l+1;
for (int i=1;i<=m;i++) ans[q[i].i]=q[i].ans;
for (int i=1;i<=m;i++) printf("%I64d ",ans[i]);
return 0;
//NOTICE LONG LONG!!!!!
}

  场上什么傻逼题都写不出来,自闭了。

Educational Codeforces Round 60 Div. 2的更多相关文章

  1. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  2. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  3. Educational Codeforces Round 60 (Rated for Div. 2) 题解

    Educational Codeforces Round 60 (Rated for Div. 2) 题目链接:https://codeforces.com/contest/1117 A. Best ...

  4. Educational Codeforces Round 84 (Div. 2)

    Educational Codeforces Round 84 (Div. 2) 读题读题读题+脑筋急转弯 = =. A. Sum of Odd Integers 奇奇为奇,奇偶为偶,所以n,k奇偶性 ...

  5. Educational Codeforces Round 60 (Rated for Div. 2)

    A. Best Subsegment 题意 找 连续区间的平均值  满足最大情况下的最长长度 思路:就是看有几个连续的最大值 #include<bits/stdc++.h> using n ...

  6. Educational Codeforces Round 60 (Rated for Div. 2)D(思维,DP,快速幂)

    #include <bits/stdc++.h>using namespace std;const long long mod = 1e9+7;unordered_map<long ...

  7. Educational Codeforces Round 60 (Rated for Div. 2)E(思维,哈希,字符串,交互)

    #include <bits/stdc++.h>using namespace std;int main(){ string t; cin>>t; int n=t.size() ...

  8. Educational Codeforces Round 60 (Rated for Div. 2) 即Codeforces Round 1117 C题 Magic Ship

    time limit per test 2 second memory limit per test 256 megabytes input standard inputoutput standard ...

  9. Educational Codeforces Round 60 (Rated for Div. 2) D. Magic Gems(矩阵快速幂)

    题目传送门 题意: 一个魔法水晶可以分裂成m个水晶,求放满n个水晶的方案数(mol1e9+7) 思路: 线性dp,dp[i]=dp[i]+dp[i-m]; 由于n到1e18,所以要用到矩阵快速幂优化 ...

随机推荐

  1. 解决在ubuntu上启动的django项目在windows进行访问无法访问的问题

    windows想要访问VMware中Ubuntu Server中Debug模式下的django服务,需要设置django允许非本机ip访问. 设置方法:1.查看虚拟机ip(建议VMware中设置Ubu ...

  2. Charles 抓包工具安装和采坑记录

    Charles 抓包工具安装和采坑记录 网络抓包是解决网络问题的第一步,也是网络分析的基础.网络出现问题,第一步肯定是通过抓包工具进行路径分析,看哪一步出现异常.做网络爬虫,第一步就是通过抓包工具对目 ...

  3. python--递归(附利用栈和队列模拟递归)

    博客地址:http://www.cnblogs.com/yudanqu/ 一.递归 递归调用:一个函数,调用的自身,称为递归调用 递归函数:一个可以调用自身的函数称为递归函数 凡是循环能干的事,递归都 ...

  4. 图片自适应完美兼容IE8

    <!DOCTYPE html><html lang="en"><head> <meta charset="gb2312" ...

  5. 启发式合并 splay合并 线段树合并基础

    Gold is everywhen! - somebody 启发式合并 将小的集合一个个插入到大的集合. 每次新集合大小至少比小集合大一倍,因此每个元素最多合并\(\log n\)次,总复杂度为\(n ...

  6. Python文本处理

    文本处理 (一)对文本操作的流程: 打开文件,得到文件句柄并赋值给一个变量 通过句柄对文件进行操作 关闭文件 open(file, mode='r', buffering=None, encoding ...

  7. rest-framework解析器,url控制,分页,响应器,渲染器,版本控制

    解析器 1.json解析器 发一个json格式的post请求.后台打印: request_data---> {'title': '北京折叠'} request.POST---> <Q ...

  8. 树遍历(广度优先 vs 深度优先)

    const data = [ { id: '01', text: '湖北省', children: [ { id: '01001', text: '武汉市', children: [ { id: '0 ...

  9. React-Native之轮播组件looped-carousel的介绍与使用

    React-Native之轮播组件looped-carousel的介绍与使用 一,关于react-native轮播组件的介绍与对比 1,react-native-swiper在动态使用网页图片,多张图 ...

  10. laravel创建项目

    composer create-project --prefer-dist laravel/laravel=5.5.* blog