码迷,mamicode.com
首页 > 其他好文 > 详细

CSUOJ 1554 SG Value

时间:2015-04-01 23:14:14      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:

1554: SG Value

Time Limit: 5 Sec  Memory Limit: 256 MB
Submit: 140  Solved: 35

Description

The SG value of a set (multiset) is the minimum positive integer that could not be constituted of the number in this set.
You will be start with an empty set, now there are two opertions:
1. insert a number x into the set;
2. query the SG value of current set.

 

Input

Input contains multiple test cases. Each test case starts with a number N (0 < N <= 1e5) -- the total number of opertions.
The next N lines contain one opertion each.
1 x means insert a namber x into the set;
2 means query the SG value of current set.

 

Output

For each query output the SG value of current set.

 

Sample Input

5
2
1 1
2
1 1
2

Sample Output

1
2
3

HINT

 

Source

 

解题:答案爆INT啊。。。注意溢出

技术分享
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 priority_queue<int,vector<int>,greater<int> >q;
 5 int n,op;
 6 int main(){
 7     while(~scanf("%d",&n)){
 8         while(!q.empty()) q.pop();
 9         LL ans = 0;
10         while(n--){
11             scanf("%d",&op);
12             if(op == 1){
13                 scanf("%d",&op);
14                 q.push(op);
15             }else{
16                 while(!q.empty() && q.top() <= ans + 1){
17                     ans += q.top();
18                     q.pop();
19                 }
20                 printf("%lld\n",ans+1);
21             }
22         }
23     }
24     return 0;
25 }
View Code

 

CSUOJ 1554 SG Value

标签:

原文地址:http://www.cnblogs.com/crackpotisback/p/4385452.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!