区间并。

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

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

#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. mysql 事务,锁,与四大隔离级别

    概念 事务 原子性:事务必须是一个自动工作的单元,要么全部执行,要么全部不执行. 一致性:事务结束的时候,所有的内部数据都是正确的. 隔离性:并发多个事务时,各个事务不干涉内部数据,处理的都是另外一个 ...

  2. codevs 1332 上白泽慧音

    1332 上白泽慧音  时间限制: 1 s  空间限制: 128000 KB     题目描述 Description 在幻想乡,上白泽慧音是以知识渊博闻名的老师.春雪异变导致人间之里的很多道路都被大 ...

  3. bzoj 1696: [Usaco2007 Feb]Building A New Barn新牛舍 ——中位数排序

    Description 经过多年的积蓄,农夫JOHN决定造一个新的牛舍.他知道所有N(2 <= N <= 10,000)头牛的吃草位置,所以他想把牛舍造在最方便的地方. 每一头牛吃草的位置 ...

  4. 【NOI】2004 郁闷的出纳员

    [算法]平衡树(treap) [题解] treap知识见数据结构. 解法,具体细节见程序. #include<cstdio> #include<algorithm> #incl ...

  5. 01-QQ 3-最终重构版 Demo示例程序源代码

      源代码下载链接:01-QQ 3.zip292.5 KB // QQAppDelegate.h Map // //  QQAppDelegate.h //  01-QQ // //  Created ...

  6. webpack 4 :从0配置到项目搭建

    webpack4发布以来,我写项目都是用脚手架,即使再简单的项目,真的是really shame..虽然道听途说了很多 webpack4 的特性,却没有尝试过,因为它给人的感觉就是,em...很难.但 ...

  7. 一键前端代理,一行命令开启nginx容器,代理前端页面

    我们在前端开发的过程中,在对接口时候,往往需要跨域请求,那么及其简便的方法就是使用nginx反向代理,但是存在几点缺点 1.在新的一个项目下,我们需要找到安装nginx目录的nginx.conf文件并 ...

  8. Python模块学习 - ConfigParser

    配置文件 很多软件都用到了配置文件,像git运行的时候会读取~/gitconfig,MySQL运行的时候会读取/etc/my.cnf,Python 提供的包管理工具pip命令,也会去读取~/.pip/ ...

  9. golang锁记

    golang中有两个锁实现 atomic的CAS实现锁 首先是inter cpu,熟悉汇编的人都知道,inter指令集有个lock,如果某个指令集前面加个lock,那么在多核状态下,某个核执行到这个前 ...

  10. 【bzoj4530】大融合(LCT的子树维护)

    LCT维护子树并没有想象中的那么难,在这里只是复习下. (其他的维护子树的题目,可见:“共价大爷游长沙”) 只要记录下虚边连接的信息就好了. #include<bits/stdc++.h> ...