区间并。

对于上下两个数字,如果不一样,那么可以计算出哪一段范围内可以保证字典序,并且后面所有位置都无需再考虑。对所有范围求交集就是答案了。

求交集写起来有点烦,直接对不可取的范围求并即可。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<ctime>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar();
x = ;
while(!isdigit(c)) c = getchar();
while(isdigit(c))
{
x = x * + c - '';
c = getchar();
}
} vector<int>v[];
int n,c,L,R,len[],ans[]; bool check(int a,int b)
{
if(v[a].size()<=v[b].size()) return ;
for(int j=;j<v[b].size();j++) if(v[a][j]!=v[b][j]) return ;
return ;
} int main()
{
scanf("%d%d",&n,&c);
for(int i=;i<n;i++)
{
scanf("%d",&len[i]);
for(int j=;j<len[i];j++)
{
int x; scanf("%d",&x);
v[i].push_back(x);
}
} for(int i=;i<n;i++)
{
for(int j=;j<len[i];j++)
{
if(v[i-].size()-<j) break;
if(v[i-][j]!=v[i][j])
{
if(v[i-][j]>v[i][j])
{
ans[]++;
ans[c-v[i-][j]+]--; ans[c-v[i][j]+]++;
ans[c]--;
}
else
{
ans[c-v[i][j]+]++;
ans[c-v[i-][j]+]--;
}
break;
}
} } for(int i=;i<=c;i++) ans[i]=ans[i]+ans[i-]; int fail=; int q;
for(int i=;i<=c-;i++) if(ans[i]==) q=i,fail=; for(int i=;i<n;i++)
{
if(check(i-,i))
{
fail=; break;
}
} if(fail==) printf("-1\n");
else printf("%d\n",q); return ;
}

CodeForces 731D 80-th Level Archeology的更多相关文章

  1. 【codeforces 731D】80-th Level Archeology

    [题目链接]:http://codeforces.com/contest/731/problem/D [题意] 给你n个象形文; 每个象形文由l[i]个数字组成; 你可以把所有的组成象形文的数字同时增 ...

  2. Codeforces Round #376 (Div. 2) D. 80-th Level Archeology —— 差分法 + 线段扫描法

    题目链接:http://codeforces.com/contest/731/problem/D D. 80-th Level Archeology time limit per test 2 sec ...

  3. 80-th Level Archeology

    80-th Level Archeology time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  4. Educational Codeforces Round 80 (Rated for Div. 2)

    A. Deadline 题目链接:https://codeforces.com/contest/1288/problem/A 题意: 给你一个 N 和 D,问是否存在一个 X , 使得 $x+\lce ...

  5. Educational Codeforces Round 80 A-E简要题解

    contest链接:https://codeforces.com/contest/1288 A. Deadline 题意:略 思路:根据题意 x + [d/(x+1)] 需要找到一个x使得上式小于等于 ...

  6. Educational Codeforces Round 80 (Rated for Div. 2)D E

    D枚举子集 题:https://codeforces.com/contest/1288/problem/D题意:给定n个序列,每个序列m个数,求第i个和第j个序列组成b序列,b序列=max(a[i][ ...

  7. Codeforces Round #80 Div.1 D

    思路:考虑离线操作,以y为关键字排序,对于y相同的一起操作,然后考虑y的范围,当y<=sqrt(n)时,直接O(n)预处理出f[x]表示f[x]+f[x+y]+f[x+2*y]+..+f[x+k ...

  8. Codeforces 731D Funny Game

    Description Once upon a time Petya and Gena gathered after another programming competition and decid ...

  9. Codeforces731D 80-th Level Archeology

    考虑将两个单词变成有序,我们可以得到一个或者两个旋转次数的区间. 然后考虑将两组单词变成有序,比如[l,mid]和[mid+1,r],对于mid和mid+1这两个单词我们可以求出使他们有序的旋转次数的 ...

随机推荐

  1. [LeetCode] Binary Tree Level Order Traversal 与 Binary Tree Zigzag Level Order Traversal,两种按层次遍历树的方式,分别两个队列,两个栈实现

    Binary Tree Level Order Traversal Given a binary tree, return the level order traversal of its nodes ...

  2. [C#] 类型学习笔记二:详解对象之间的比较

    继上一篇对象类型后,这里我们一起探讨相等的判定. 相等判断有关的4个方法 CLR中,和相等有关系的方法有这么4种: (1) 最常见的 == 运算符 (2) Object的静态方法ReferenceEq ...

  3. MongoDB入门(2)- MongoDB安装

    windows安装 下载文件,解压缩即可.下载地址 每次运行mongod --dbpath D:/MongoDB/data 命令行来启动MongoDB实在是不方便,把它作为Windows服务,这样就方 ...

  4. HDU 5950Recursive sequence ICPC沈阳站

    Recursive sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  5. 元类编程-- 实现orm,以django Model为例

    # 需求 import numbers class Field: pass class IntField(Field): # 数据描述符 def __init__(self, db_column, m ...

  6. 用Photoshop制作一寸照片

    好了简单介绍一下自己如何制作一寸照片.   工具/原料   Photoshop CS4 更高版本也可以 方法/步骤   1 打开你要修改的照片 2 选择裁剪工具设置参数   选择最佳位置裁剪   选择 ...

  7. 【比赛】STSRM 09

    第一题 题意:n个点,每个点坐标pi属性ai,从右往左将遇到的点向左ai范围内的点消除,后继续扫描. 现可以在扫描开始前提前消除从右往左任意点,问最少消除数(提前+扫描). n,pi,ai<=1 ...

  8. 【转载】VS2013安装需要IE10

    因为需要移动办公,需要给笔记本搭建编程环境.安装VS2013时遇到了小麻烦,提示我,需要安装IE10. 然后我很听话的按照提供的超链接,到了官网,下载了最新的IE11,然后安装,结果告诉我下载的IE版 ...

  9. POJ 3061 Subsequence ( 尺取法)

    题目链接 Description A sequence of N positive integers (10 < N < 100 000), each of them less than ...

  10. [转]python os模块 常用命令

    python编程时,经常和文件.目录打交道,这是就离不了os模块.os模块包含普遍的操作系统功能,与具体的平台无关.以下列举常用的命令 1. os.name()——判断现在正在实用的平台,Window ...