Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 세그먼트트리
- 다이나믹프로그래밍
- 유니온파인드
- 분할정복
- DFS
- 알고리즘문제해결전략
- 백트래킹
- 동적계획법
- 스택
- 분리집합
- 문자열
- 이분탐색
- stack
- 그리디
- 너비우선탐색
- backtracking
- BFS
- acm
- priority_queue
- union-find
- 완전탐색
- Algospot
- BOJ
- 알고스팟
- 종만북
- Greedy
- 백준
- DP
- 재귀
- 누적합
Archives
- Today
- Total
DAMPER's 낙서장
7662 이중 우선순위 큐 본문
728x90
7662번: 이중 우선순위 큐
입력 데이터는 표준입력을 사용한다. 입력은 T개의 테스트 데이터로 구성된다. 입력의 첫 번째 줄에는 입력 데이터의 수를 나타내는 정수 T가 주어진다. 각 테스트 데이터의 첫째 줄에는 Q에 적
www.acmicpc.net
<아이디어>
처음에 이 문제를 접했을 때에는 문제이름이 이중 우선순위 큐여서 우선순위가 다른 priority_queue를 2개 선언해서 두개로 돌렸는데 다시 생각해보니 말도 안되는 방법이었다...
그래서 map을 사용해서 value 값을 counting 용도로 쓰면서 naive하게 진행.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#include <bits/stdc++.h>
using namespace std;
#define swap(a,b) (a)^=(b)^=(a)^=(b)
#define endl '\n'
typedef long long lld;
int main()
{
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
int tc;
cin>>tc;
while(tc--)
{
int k, num;
map<int, int> mp;
cin>>k;
char order;
for(int i=0;i<k;i++)
{
cin>>order>>num;
if(order=='I') mp[num] += 1;
if(order=='D')
{
map<int, int>::iterator it;
if(mp.empty()) continue;
if(num==1)
{
it = mp.end();
it--;
it->second -= 1;
if(it->second==0) mp.erase(it);
}
if(num==-1)
{
it = mp.begin();
it->second -= 1;
if(it->second==0) mp.erase(it);
}
}
}
if(mp.empty()) cout<<"EMPTY\n";
else
{
map<int, int>::iterator a = mp.begin(), b = mp.end();
b--;
cout<<b->first<<' '<<a->first<<endl;
}
}
return 0;
}
|
cs |

728x90
'Problem Solving > BOJ 문제풀이' 카테고리의 다른 글
5525 IOIOI (0) | 2021.01.11 |
---|---|
1992 쿼드트리 (0) | 2021.01.11 |
1541 잃어버린 괄호 (0) | 2021.01.05 |
11687 팩토리얼 0의 개수 (0) | 2021.01.04 |
14889 스타트와 링크 (0) | 2021.01.02 |