设为首页 加入收藏

TOP

Codeforces Round #Pi (Div. 2) (ABCD题解)(二)
2015-11-21 00:55:27 来源: 作者: 【 】 浏览:6
Tags:Codeforces Round #Pi Div. ABCD 题解
ct 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.

Output

Print a single integer — the minimum possible capacity of the reading room.

Sample test(s) Input
6
+ 12001
- 12001
- 1
- 1200
+ 1
+ 7
Output
3
Input
2
- 1
- 2
Output
2
Input
2
+ 1
- 1
Output
1
Note

In the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3.

?

题目大意:一共n个操作,+ i表示标号为i的人进会场,-i表示标号为i的人出会场,问会场的最小容量

?

题目分析:用个set模拟一下

?

?

#include 
  
   
#include 
   
     #include 
    
      using namespace std; set 
     
       st; int main() { int n, ans = 0;; scanf(%d, &n); while(n --) { char s[2]; int id; scanf(%s %d, s, &id); if(s[0] == '+') st.insert(id); //进去 else { if(!st.count(id)) //本来就在里面的出来 ans ++; else st.erase(id); //之前进去的出来 } ans = max(ans, (int) st.size()); } printf(%d , ans); }
     
    
   
  

?

?

?

?

C. Geometric Progression time limit per test:1 second memory limit per test:256 megabytes

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.

Input

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

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.

Sample test(s) Input
5 2
1 1 2 2 4
Output
4
Input
3 1
1 1 1
Output
1
Input
10 3
1 2 6 2 3 6 9 18 3 9
Output
6
Note

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.


?

题目大意:n个数,问能找到多少组三个数,它们的下标严格递增且公比为k

?

题目分析:ai那么大,数组不够,直接上map,fir表示中间那个数出现的次数,sec表示第一个数出现的次数,每次按公比k找满足条件的数

?

?

#include 
  
   
#include
    #define ll long long using namespace std; map 
    
      fir, sec; int main() { int n, k; ll ans = 0; scanf(%d %d, &n, &k); for(int i = 0; i < n; i++) { int a; scanf(%d, &a); if(a % k == 0) { ans += fir[a / k]; fir[a] += sec[a / k]; } sec[a] ++; } printf(%I64d , ans); }
    
  

?

?

?

?

D. One-Dimensional Battle Ships time limit per test:1 second memory limit per test:256 megabytes

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 cons

首页 上一页 1 2 3 下一页 尾页 2/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇POJ 1741 Tree(树分治|ltc男人八.. 下一篇hdu 2120 Ice_cream's world I

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: