Codeforces Round #Pi (Div. 2) ABCDEF已更新
3 seconds
256 megabytes
standard input
standard output
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi — a coordinate on the Oxaxis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values mini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city
The first line of the input contains integer n (2 ≤ n ≤ 105) — the number of cities in Lineland. The second line contains the sequence ofn distinct integers x1, x2, ..., xn ( - 109 ≤ xi ≤ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow inascending order.
Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.
- 4
-5 -2 2 7
- 3 12
3 9
4 7
5 12
- 2
-1 1
- 2 2
2 2- 题解:水题
- #include<iostream>
- #include<cstdio>
- #include<cmath>
- #include<algorithm>
- #include<queue>
- #include<cstring>
- #define PAU putchar(' ')
- #define ENT putchar('\n')
- using namespace std;
- const int maxn=+,inf=-1u>>;
- int A[maxn],n;
- inline int read(){
- int x=,sig=;char ch=getchar();
- for(;!isdigit(ch);ch=getchar())if(ch=='-')sig=;
- for(;isdigit(ch);ch=getchar())x=*x+ch-'';
- return sig?x:-x;
- }
- inline void write(int x){
- if(x==){putchar('');return;}if(x<)putchar('-'),x=-x;
- int len=,buf[];while(x)buf[len++]=x%,x/=;
- for(int i=len-;i>=;i--)putchar(buf[i]+'');return;
- }
- void init(){
- n=read();for(int i=;i<=n;i++)A[i]=read();
- write(A[]-A[]);PAU;
- write(A[n]-A[]);ENT;
- for(int i=;i<n;i++){
- write(min(A[i]-A[i-],A[i+]-A[i]));PAU;
- write(max(A[i]-A[],A[n]-A[i]));ENT;
- }
- write(A[n]-A[n-]);PAU;
- write(A[n]-A[]);ENT;
- return;
- }
- void work(){
- return;
- }
- void print(){
- return;
- }
- int main(){init();work();print();return ;}
- /*
- 4
- -5 -2 2 7
- */
1 second
256 megabytes
standard input
standard output
Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.
Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned aregistration number during the registration procedure at the library — it's a unique integer from 1 to 106. Thus, the system logs events of two forms:
- "+ ri" — the reader with registration number ri entered the room;
- "- ri" — the reader with registration number ri left the room.
The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.
Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.
Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.
The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ ri" or "- ri", where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers).
It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.
Print a single integer — the minimum possible capacity of the reading room.
- 6
+ 12001
- 12001
- 1
- 1200
+ 1
+ 7
- 3
- 2
- 1
- 2
- 2
- 2
+ 1
- 1
- 1
In the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3.
题解:我的神奇的维护贡献的做法:窝萌设A[i]表示第i个时刻的人数,每次来了一个没有出现过的减号就把它前面所有的贡献维护一下,来了一个出现过的减号就把它后面的贡献维护一下,来了一个加号就把当前贡献加1好了。。。。。。。。。QAQ。。。。
当时在pretest上奋斗了很久。。。。。
- #include<iostream>
- #include<cstdio>
- #include<cmath>
- #include<algorithm>
- #include<queue>
- #include<cstring>
- #define PAU putchar(' ')
- #define ENT putchar('\n')
- using namespace std;
- const int maxn=,maxm=+;
- const int HASHSIZE=;
- int first[HASHSIZE],next[maxn],v[maxn],sz;
- bool find(int val){
- int x=val%HASHSIZE;
- if(x<) x+=HASHSIZE;
- for(int i=first[x];i;i=next[i]) if(v[i]==val)return true;
- return false;
- }
- void insert(int val){
- int x=val%HASHSIZE;
- if(x<) x+=HASHSIZE;
- for(int i=first[x];i;i=next[i]) if(v[i]==val) {return;}
- v[++sz]=val;
- next[sz]=first[x];
- first[x]=sz;
- }
- void remove(int val){
- int x=val%HASHSIZE;
- if(x<) x+=HASHSIZE;
- if(!first[x]) {return;}
- if(v[first[x]]==val){
- first[x]=next[first[x]];
- return;
- }
- for(int i=first[x];next[i];i=next[i]) if(v[next[i]]==val) {next[i]=next[next[i]];return;}
- }
- inline int read(){
- int x=,sig=;char ch=getchar();
- for(;!isdigit(ch);ch=getchar())if(ch=='-')sig=;
- for(;isdigit(ch);ch=getchar())x=*x+ch-'';
- return sig?x:-x;
- }
- inline void write(int x){
- if(x==){putchar('');return;}if(x<)putchar('-'),x=-x;
- int len=,buf[];while(x)buf[len++]=x%,x/=;
- for(int i=len-;i>=;i--)putchar(buf[i]+'');return;
- }
- int n,A[maxm];
- void init(){
- n=read();int x;int ans=;char s[];
- for(int i=;i<=n;i++){
- scanf("%s",s);A[i]+=A[i-];
- if(s[]=='+'){
- x=read();insert(x);A[i]++;
- }else{
- x=read();
- if(find(x)){remove(x);A[i+]--;
- //for(int j=i;j<=n;j++)A[j]--;
- }
- else for(int j=;j<i;j++){
- A[j]++;
- }
- }
- //printf("---%d---\n",i);for(int i=1;i<=n;i++)write(A[i]),PAU;ENT;
- }
- for(int i=;i<=n;i++)ans=max(ans,A[i]);write(ans);
- //ENT;
- //for(int i=1;i<=n;i++)write(A[i]),PAU;ENT;
- return;
- }
- void work(){
- return;
- }
- void print(){
- return;
- }
- int main(){init();work();print();return ;}
- /*
- 6
- + 12001
- - 12001
- - 1
- - 1200
- + 1
- + 7
- 2
- - 1
- + 2
- 2
- - 1
- - 2
- 2
- + 1
- - 1
- */
1 second
256 megabytes
standard input
standard output
Polycarp loves geometric progressions very much. Since he was only three years old, he loves only the progressions of length three. He also has a favorite integer k and a sequence a, consisting of n integers.
He wants to know how many subsequences of length three can be selected from a, so that they form a geometric progression with common ratio k.
A subsequence of length three is a combination of three such indexes i1, i2, i3, that 1 ≤ i1 < i2 < i3 ≤ n. That is, a subsequence of length three are such groups of three elements that are not necessarily consecutive in the sequence, but their indexes are strictly increasing.
A geometric progression with common ratio k is a sequence of numbers of the form b·k0, b·k1, ..., b·kr - 1.
Polycarp is only three years old, so he can not calculate this number himself. Help him to do it.
The first line of the input contains two integers, n and k (1 ≤ n, k ≤ 2·105), showing how many numbers Polycarp's sequence has and his favorite number.
The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — elements of the sequence.
Output a single number — the number of ways to choose a subsequence of length three, such that it forms a geometric progression with a common ratio k.
- 5 2
1 1 2 2 4
- 4
- 3 1
1 1 1
- 1
- 10 3
1 2 6 2 3 6 9 18 3 9
- 6
In the first sample test the answer is four, as any of the two 1s can be chosen as the first element, the second element can be any of the 2s, and the third element of the subsequence must be equal to 4.
题解:STL大法好,sort一下然后疯狂的upper,lower就行。。。懒得写代码了。。。
- #include <bits/stdc++.h>
- #define Pii pair <ll, int>
- #define ll long long
- using namespace std;
- const int MAXN = ;
- Pii arr[MAXN];
- int main()
- {
- ll n, k;
- while(~scanf("%I64d%I64d", &n, &k))
- {
- for(int i = ; i < n; ++i)
- {
- scanf("%I64d", &arr[i].first);
- arr[i].second = i;
- }
- sort(arr, arr + n);
- ll ans = ;
- for(int i = ; i < n - ; ++i)
- {
- if(arr[i].first % k == )//枚举中间的数
- {
- //arr[i]/k的个数
- ll cnt1 = upper_bound(arr, arr + n, Pii(arr[i].first / k, arr[i].second - )) - lower_bound(arr, arr + n, Pii(arr[i].first / k, ));
- //arr[i]×k的个数
- ll cnt2 = upper_bound(arr, arr + n, Pii(arr[i].first * k, n)) - lower_bound(arr, arr + n, Pii(arr[i].first * k, arr[i].second + ));
- ans += cnt1 * cnt2;
- }
- }
- printf("%I64d\n", ans);
- }
- return ;
- }
1 second
256 megabytes
standard input
standard output
Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consisting of n square cells (that is, on a 1 × n table).
At the beginning of the game Alice puts k ships on the field without telling their positions to Bob. Each ship looks as a 1 × a rectangle (that is, it occupies a sequence of a consecutive squares of the field). The ships cannot intersect and even touch each other.
After that Bob makes a sequence of "shots". He names cells of the field and Alice either says that the cell is empty ("miss"), or that the cell belongs to some ship ("hit").
But here's the problem! Alice like to cheat. May be that is why she responds to each Bob's move with a "miss".
Help Bob catch Alice cheating — find Bob's first move, such that after it you can be sure that Alice cheated.
The first line of the input contains three integers: n, k and a (1 ≤ n, k, a ≤ 2·105) — the size of the field, the number of the ships and the size of each ship. It is guaranteed that the n, k and a are such that you can put k ships of size a on the field, so that no two ships intersect or touch each other.
The second line contains integer m (1 ≤ m ≤ n) — the number of Bob's moves.
The third line contains m distinct integers x1, x2, ..., xm, where xi is the number of the cell where Bob made the i-th shot. The cells are numbered from left to right from 1 to n.
Print a single integer — the number of such Bob's first move, after which you can be sure that Alice lied. Bob's moves are numbered from 1 to m in the order the were made. If the sought move doesn't exist, then print "-1".
- 11 3 3
5
4 8 6 1 11
- 3
- 5 1 3
2
1 5
- -1
- 5 1 3
1
3
- 1
- 题解:二分练习题
2 seconds
256 megabytes
standard input
standard output
Berland has n cities, the capital is located in city s, and the historic home town of the President is in city t (s ≠ t). The cities are connected by one-way roads, the travel time for each of the road is a positive integer.
Once a year the President visited his historic home town t, for which his motorcade passes along some path from s to t (he always returns on a personal plane). Since the president is a very busy man, he always chooses the path from s to t, along which he will travel the fastest.
The ministry of Roads and Railways wants to learn for each of the road: whether the President will definitely pass through it during his travels, and if not, whether it is possible to repair it so that it would definitely be included in the shortest path from the capital to the historic home town of the President. Obviously, the road can not be repaired so that the travel time on it was less than one. The ministry of Berland, like any other, is interested in maintaining the budget, so it wants to know the minimum cost of repairing the road. Also, it is very fond of accuracy, so it repairs the roads so that the travel time on them is always a positive integer.
The first lines contain four integers n, m, s and t (2 ≤ n ≤ 105; 1 ≤ m ≤ 105; 1 ≤ s, t ≤ n) — the number of cities and roads in Berland, the numbers of the capital and of the Presidents' home town (s ≠ t).
Next m lines contain the roads. Each road is given as a group of three integers ai, bi, li (1 ≤ ai, bi ≤ n; ai ≠ bi; 1 ≤ li ≤ 106) — the cities that are connected by the i-th road and the time needed to ride along it. The road is directed from city ai to city bi.
The cities are numbered from 1 to n. Each pair of cities can have multiple roads between them. It is guaranteed that there is a path froms to t along the roads.
Print m lines. The i-th line should contain information about the i-th road (the roads are numbered in the order of appearance in the input).
If the president will definitely ride along it during his travels, the line must contain a single word "YES" (without the quotes).
Otherwise, if the i-th road can be repaired so that the travel time on it remains positive and then president will definitely ride along it, print space-separated word "CAN" (without the quotes), and the minimum cost of repairing.
If we can't make the road be such that president will definitely ride along it, print "NO" (without the quotes).
- 6 7 1 6
1 2 2
1 3 10
2 3 7
2 4 8
3 5 3
4 5 2
5 6 1
- YES
CAN 2
CAN 1
CAN 1
CAN 1
CAN 1
YES
- 3 3 1 3
1 2 10
2 3 10
1 3 100
- YES
YES
CAN 81
- 2 2 1 2
1 2 1
1 2 2
- YES
NO
The cost of repairing the road is the difference between the time needed to ride along it before and after the repairing.
In the first sample president initially may choose one of the two following ways for a ride: 1 → 2 → 4 → 5 → 6 or1 → 2 → 3 → 5 → 6.
题解:太神奇了!正反跑最短路,然后怎么弄数量呢?然后有:总数量=s出发的*t出发的,妈妈呀。。。
1 second
256 megabytes
standard input
standard output
King of Berland Berl IV has recently died. Hail Berl V! As a sign of the highest achievements of the deceased king the new king decided to build a mausoleum with Berl IV's body on the main square of the capital.
The mausoleum will be constructed from 2n blocks, each of them has the shape of a cuboid. Each block has the bottom base of a 1 × 1meter square. Among the blocks, exactly two of them have the height of one meter, exactly two have the height of two meters, ..., exactly two have the height of n meters.
The blocks are arranged in a row without spacing one after the other. Of course, not every arrangement of blocks has the form of a mausoleum. In order to make the given arrangement in the form of the mausoleum, it is necessary that when you pass along the mausoleum, from one end to the other, the heights of the blocks first were non-decreasing (i.e., increasing or remained the same), and then — non-increasing (decrease or remained unchanged). It is possible that any of these two areas will be omitted. For example, the following sequences of block height meet this requirement:
- [1, 2, 2, 3, 4, 4, 3, 1];
- [1, 1];
- [2, 2, 1, 1];
- [1, 2, 3, 3, 2, 1].
Suddenly, k more requirements appeared. Each of the requirements has the form: "h[xi] signi h[yi]", where h[t] is the height of the t-th block, and a signi is one of the five possible signs: '=' (equals), '<' (less than), '>' (more than), '<=' (less than or equals), '>=' (more than or equals). Thus, each of the k additional requirements is given by a pair of indexes xi, yi (1 ≤ xi, yi ≤ 2n) and sign signi.
Find the number of possible ways to rearrange the blocks so that both the requirement about the shape of the mausoleum (see paragraph 3) and the k additional requirements were met.
The first line of the input contains integers n and k (1 ≤ n ≤ 35, 0 ≤ k ≤ 100) — the number of pairs of blocks and the number of additional requirements.
Next k lines contain listed additional requirements, one per line in the format "xi signi yi" (1 ≤ xi, yi ≤ 2n), and the sign is on of the list of the five possible signs.
Print the sought number of ways.
- 3 0
- 9
- 3 1
2 > 3
- 1
- 4 1
3 = 6
- 3
- 题解:窝萌观察这个数列,最小的数一定是在两端或者是挤在一边,窝萌删掉这样两个数后仍然满足。。。
可以设dp[i][j]表示数列中i~j这一段的合法数量,按刚才的规律分治即可。至于约束条件狂讨论就行了,(然而明显不可写。。。
Codeforces Round #Pi (Div. 2) ABCDEF已更新的更多相关文章
- map Codeforces Round #Pi (Div. 2) C. Geometric Progression
题目传送门 /* 题意:问选出3个数成等比数列有多少种选法 map:c1记录是第二个数或第三个数的选法,c2表示所有数字出现的次数.别人的代码很短,思维巧妙 */ /***************** ...
- 构造 Codeforces Round #Pi (Div. 2) B. Berland National Library
题目传送门 /* 题意:给出一系列读者出行的记录,+表示一个读者进入,-表示一个读者离开,可能之前已经有读者在图书馆 构造:now记录当前图书馆人数,sz记录最小的容量,in数组标记进去的读者,分情况 ...
- Codeforces Round #527 (Div. 3) ABCDEF题解
Codeforces Round #527 (Div. 3) 题解 题目总链接:https://codeforces.com/contest/1092 A. Uniform String 题意: 输入 ...
- Codeforces Round #531 (Div. 3) ABCDEF题解
Codeforces Round #531 (Div. 3) 题目总链接:https://codeforces.com/contest/1102 A. Integer Sequence Dividin ...
- Codeforces Round #Pi (Div. 2) D. One-Dimensional Battle Ships set区间分解
D. One-Dimensional Battle ShipsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/co ...
- codeforces Round #Pi (div.2) 567ABCD
567A Lineland Mail题意:一些城市在一个x轴上,他们之间非常喜欢写信交流.送信的费用就是两个城市之间的距离,问每个城市写一封信给其它城市所花费的最小费用和最大的费用. 没什么好说的.直 ...
- Codeforces Round #Pi (Div. 2) D. One-Dimensional Battle Ships set乱搞
D. One-Dimensional Battle ShipsTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/con ...
- Codeforces Round #Pi (Div. 2) C. Geometric Progression map
C. Geometric Progression Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
- Codeforces Round #Pi (Div. 2) B. Berland National Library set
B. Berland National LibraryTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...
随机推荐
- 咱也玩玩Wordpress
博客暂时转移到了 -> www.zhyfzy.ga 域名改成.com啦 -> www.zhyfzy.com
- python-集合(第二篇(七):集合)
第二篇(七):集合 python 集合 集合标准操作 摘要: 说明: ·类似于数学中学的集合,Python中的集合可以实现去重的功能,通过set()函数来实现: ·sets支持x in set, ...
- WCF,WebAPI,WCFREST和WebService的区别
Web ServiceIt is based on SOAP and return data in XML form.It support only HTTP protocol.It is not o ...
- sql-从查询结果创建一个永久表
语法: select x into new_tableName from ori_tableName 例如: SELECT [site] ,[day] ,[val]/31.4 [val] into ...
- 让ie6/7/8兼容css3的圆角阴影等特殊效果的方法 PIE1.0.0及placeholder在这些IE下生效的方法
PIE地址:http://css3pie.com/ 使用方法1: #login,#AnnouncementBox { border:3px solid #fff; -webkit-border-r ...
- 常用CDN公共库
Jquery <script src="http://lib.sinaapp.com/js/jquery/1.7.2/jquery.min.js"></scrip ...
- Junit4_单元测试
不多说,直接练习学习. 1.将Junit4单元测试包引入项目:项目右键——“属性”,选择“Java Build Path”,然后到右上选择“Libraries”标签,之后在最右边点击“Add Libr ...
- grunt 合并压缩任务
module.exports = function(grunt) { // LiveReload的默认端口号,你也可以改成你想要的端口号 var lrPort = 35729; // 使用connec ...
- 【JQuery学习历程】2.JQuery选择器
基本选择器 选择器 描述 返回 示例 #id 根据给定的id匹配元素 单个元素 $("#myId") .class 根据给定的class类匹配元素 集合元素 $(".my ...
- Aspnet MVC 异步调用
一个简图来描述下Aspnet MVC下的异步调用 { request } / \/ -------ISS------- > work thread | \ | \ route - aysn co ...