原题网址:http://codeforces.com/contest/731/problem/D


对于相邻的两行,我们可以求出合法的答案区间,然后对所有的区间取一下区间并。因为只有最后一次询问,所以对于区间并,可以用差分维护,那么区间并的总复杂度只要O(C)了。

vara:array[0..1,0..1000050] of longint;cf:array[-1..1000050] of int64;n,c,last,now,cnt,tot,i:longint;
function max(a,b:longint):longint;begin if (a>b) then exit(a) else exit(b); end;
function min(a,b:longint):longint;begin if (a<b) then exit(a) else exit(b); end;
procedure print(x:longint);beginwriteln(x);halt;end;
beginread(n,c);last:=0;now:=1;cnt:=1;read(a[now][0]);for i:=1 to a[now][0] doread(a[now][i]);while (cnt<n) dobeginlast:=last xor 1;now:=now xor 1;inc(cnt);read(a[now][0]);for i:=1 to a[now][0] doread(a[now][i]);for i:=1 to max(a[last][0],a[now][0]) doif (i>min(a[last][0],a[now][0]))thenbeginif (a[last][0]>a[now][0])then print(-1);endelsebeginif (a[last][i]=a[now][i]) then continue;inc(tot);if (a[last][i]<a[now][i])thenbegininc(cf[0]);dec(cf[c-a[now][i]+1]);inc(cf[c-a[last][i]+1]);dec(cf[c]);endelsebegininc(cf[c-a[last][i]+1]);dec(cf[c-a[now][i]+1]);end;break;end;end;for i:=0 to c do cf[i]:=cf[i-1]+cf[i];for i:=0 to c do if (cf[i]=tot) then print(i);print(-1);
end.

Codeforces Round #376 (Div. 2) D. 80-th Level Archeology相关推荐

  1. 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 ...

  2. Codeforces Round #376 (Div. 2) B. Coupons and Discounts

    题目链接:http://codeforces.com/contest/731/problem/B #include<bits/stdc++.h> #define MX 200007 usi ...

  3. Codeforces Round #376 (Div. 2) C. Socks

    可能英语水平比较差,这个题我刚读起来是懵逼的. C. Socks time limit per test 2 seconds memory limit per test 256 megabytes i ...

  4. Codeforces Round #376 (Div. 2) D. 80-th Level Archeology(乱搞)

    题目链接: codeforces731d 题意: 给你n个字符串,每个字符串的元素x取值范围在[1,c],问你能否将所有的x同时进行若干次加1(如果x==c,x变成1)使得字符串是按字典序从小到大排序 ...

  5. hash+set Codeforces Round #291 (Div. 2) C. Watto and Mechanism

    题目传送门 1 /* 2 hash+set:首先把各个字符串的哈希值保存在set容器里,然后对于查询的每一个字符串的每一位进行枚举 3 用set的find函数查找是否存在替换后的字符串,理解后并不难. ...

  6. BFS Codeforces Round #297 (Div. 2) D. Arthur and Walls

    题目传送门 1 /* 2 题意:问最少替换'*'为'.',使得'.'连通的都是矩形 3 BFS:搜索想法很奇妙,先把'.'的入队,然后对于每个'.'八个方向寻找 4 在2*2的方格里,若只有一个是'* ...

  7. Codeforces Round #434 (Div. 2)【A、B、C、D】

    Codeforces Round #434 (Div. 2) codeforces 858A. k-rounding[水] 题意:已知n和k,求n的最小倍数x,要求x后缀至少有k个0. 题解:答案就是 ...

  8. Codeforces Round #510 (Div. 2)

    Codeforces Round #510 (Div. 2) https://codeforces.com/contest/1042 A 二分 1 #include<iostream> 2 ...

  9. Codeforces Round #257 (Div. 2)

    Codeforces Round #257 (Div. 2) https://codeforces.com/contest/450/ A 模拟 1 #include<bits/stdc++.h& ...

最新文章

  1. 中芯高层震荡未停:蒋尚义离职,梁孟松退出董事会,「台积电灵魂」加盟不足一年...
  2. Python快速学习06:词典
  3. Auto Lisp 标注子样式_FAIR 开放大规模细粒度词汇级标记数据集 LVIS,连披萨里的菠萝粒都能完整标注...
  4. 初探Apache Kylin【麒麟】
  5. 网络编程(part6)--OSI七层模型及四层模型(TCP/IP)
  6. 【spring】spring的事务传播性 hibernate/jpa等的事务隔离性
  7. Nginx 的多站点配置
  8. 前端MVC学习笔记第二课
  9. 新鲜出炉,程序员年度薪酬排行榜
  10. 【名企招聘】4月26日19点,涛思数据带着高薪岗位JD和精美周边来啦~
  11. 【问题整理】计算机相关
  12. 华为大数据与阿里大数据的区别
  13. vue项目为什么选择svg图标
  14. Tenth season fifth episode,Rachel‘s sister came again???????
  15. 十一个Python在线学习网站
  16. Java 散点图 数据库 代码_Java 创建Excel散点图
  17. iOS-规避iOS审核4.3规则的重心
  18. win10 jdk1.8迅雷下载
  19. sql 取第一条数据
  20. Axure课程设计-漫画APP界面/UI设计(免费分享.rp文件学习)

热门文章

  1. 2022年智能住宅行业发展前景
  2. 思科Nexus 9000.端口配置路由模式直连不通
  3. Sql Server 数据类型
  4. 热门API接口它来啦 新鲜出炉
  5. 掌握坐标轴的log转换
  6. linux查看wifi 密码,linux查看wifi 密码
  7. fsk调制matlab 仿真,基于MATLAB对FSK信号调制与解调的仿真
  8. 编写一个截取字符串的函数,输入为一个字符串和字节数, 输出为按字节截取的字符串。 但是要保证汉字不被截半个。
  9. day2-MySQL规约
  10. JS判断网页是否在微信中打开