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. Groovy语言学习--语法基础(3)

    侧重点可能是groovy metaClass基元类的概念,有点像java的反射,因为java反射目前基本也没研究过,就mark一下,后续若有用到就深入研究一下. 基础语法的东西貌似差不多八九不离十了, ...

  2. WPF仿网易云音乐系列(二、歌单创建窗口+登录设置模块)

    老衲牺牲午休时间写博客,都快把自己感动了,-_-!! 之前上一篇随笔,我看了下评论,有部分人说WPF已经凉凉了,这个我觉得,这只是一个达到自己目的的工具而已,只要自己能用这个工具,得心应手的做出自己想 ...

  3. flask 跨域请求

    Flask中,跨域请求主要有两种方式: 1.在响应头信息中添加允许跨域 如下,使用装饰器app.after_request(我这里的web是定义的蓝图),这样在每次请求后,加入header 2.使用第 ...

  4. Python入门-从HelloWorld开始

    前言 最近在招聘网上看了许多公司的招聘要求,发现很多公司希望求职者能会Python,特别是一些自动化测试的职位,以前对Python只是介于听说或是一些简单的了解,所以既然市场有需求,那么我们就来学习一 ...

  5. c++构造函数成员初始化中赋值和初始化列表两种方式的区别

    先总结下: 由于类成员初始化总在构造函数执行之前 1)从必要性: a. 成员是类或结构,且构造函数带参数:成员初始化时无法调用缺省(无参)构造函数 b. 成员是常量或引用:成员无法赋值,只能被初始化 ...

  6. H5 66-清除浮动方式二

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. ES6 Promise 详解

    一.概念 Promise,从语法上来讲,它是一个对象,是一个构造函数,可以获取 异步操作 的信息. 简单来讲,就是用同步的方式写异步代码,用来解决回调问题. 二.特点 Promise 对象有两个特点: ...

  8. R语言绘制茎叶图

    与直方图相比,茎叶图更能细致的看出数据分布情况! 代码: > x<-c(25, 45, 50, 54, 55, 61, 64, 68, 72, 75, 75,+ 78, 79, 81, 8 ...

  9. jconsole & jvisualvm远程监视websphere服务器JVM的配置案

    jconsole是JDK里自带的一个工具,可以监测Java程序运行时所有对象的申请.释放等动作,将内存管理的所有信息进行统计.分析.可视化.我们可以根据这些信息判断程序是否有内存泄漏问题. 使用jco ...

  10. python文件读和写

    fileHandle = open ( 'G:/qqfile/1.txt','w' )fileHandle.write('abcd')#写文件 地址要用反斜杠fileHandle.close() fi ...