CSUOJ 1554 SG Value
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 }
夜空中最亮的星,照亮我前行