Codeforces Round #376 (Div. 2) D. 80-th Level Archeology
原题网址: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相关推荐
- 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 ...
- Codeforces Round #376 (Div. 2) B. Coupons and Discounts
题目链接:http://codeforces.com/contest/731/problem/B #include<bits/stdc++.h> #define MX 200007 usi ...
- Codeforces Round #376 (Div. 2) C. Socks
可能英语水平比较差,这个题我刚读起来是懵逼的. C. Socks time limit per test 2 seconds memory limit per test 256 megabytes i ...
- Codeforces Round #376 (Div. 2) D. 80-th Level Archeology(乱搞)
题目链接: codeforces731d 题意: 给你n个字符串,每个字符串的元素x取值范围在[1,c],问你能否将所有的x同时进行若干次加1(如果x==c,x变成1)使得字符串是按字典序从小到大排序 ...
- hash+set Codeforces Round #291 (Div. 2) C. Watto and Mechanism
题目传送门 1 /* 2 hash+set:首先把各个字符串的哈希值保存在set容器里,然后对于查询的每一个字符串的每一位进行枚举 3 用set的find函数查找是否存在替换后的字符串,理解后并不难. ...
- BFS Codeforces Round #297 (Div. 2) D. Arthur and Walls
题目传送门 1 /* 2 题意:问最少替换'*'为'.',使得'.'连通的都是矩形 3 BFS:搜索想法很奇妙,先把'.'的入队,然后对于每个'.'八个方向寻找 4 在2*2的方格里,若只有一个是'* ...
- 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. 题解:答案就是 ...
- Codeforces Round #510 (Div. 2)
Codeforces Round #510 (Div. 2) https://codeforces.com/contest/1042 A 二分 1 #include<iostream> 2 ...
- Codeforces Round #257 (Div. 2)
Codeforces Round #257 (Div. 2) https://codeforces.com/contest/450/ A 模拟 1 #include<bits/stdc++.h& ...
最新文章
- 中芯高层震荡未停:蒋尚义离职,梁孟松退出董事会,「台积电灵魂」加盟不足一年...
- Python快速学习06:词典
- Auto Lisp 标注子样式_FAIR 开放大规模细粒度词汇级标记数据集 LVIS,连披萨里的菠萝粒都能完整标注...
- 初探Apache Kylin【麒麟】
- 网络编程(part6)--OSI七层模型及四层模型(TCP/IP)
- 【spring】spring的事务传播性 hibernate/jpa等的事务隔离性
- Nginx 的多站点配置
- 前端MVC学习笔记第二课
- 新鲜出炉,程序员年度薪酬排行榜
- 【名企招聘】4月26日19点,涛思数据带着高薪岗位JD和精美周边来啦~
- 【问题整理】计算机相关
- 华为大数据与阿里大数据的区别
- vue项目为什么选择svg图标
- Tenth season fifth episode,Rachel‘s sister came again???????
- 十一个Python在线学习网站
- Java 散点图 数据库 代码_Java 创建Excel散点图
- iOS-规避iOS审核4.3规则的重心
- win10 jdk1.8迅雷下载
- sql 取第一条数据
- Axure课程设计-漫画APP界面/UI设计(免费分享.rp文件学习)