반응형

https://www.acmicpc.net/problem/3755

 

3755번: Double Queue

The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Bucharest, equipped with a modern computing environment provided by IBM Romania, and using modern information technologies. As usual, each client of the bank is identified by a

www.acmicpc.net

 

 

[ 문제풀이 ]

 

1. priority_queue를 두 개 선언해, 오름차순과 내림차순으로 각각 저장합니다.

 

2. visited 배열을 만들어 현재 K 고객이 서비스를 이용한 상태인지 그렇지 않은 상태인지 저장합니다.

 

3. 입력되는 명령어에 따라 값을 출력해줍니다.

 

[ 소스코드 ]

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
55
56
57
58
59
60
61
62
#include<iostream>
#include<queue>
 
using namespace std;
 
int visited[1000000];
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    int cmd;
    priority_queue<pair<intint>vector<pair<int,int>>, greater<>> greater;
    priority_queue<pair<intint>vector<pair<intint>>, less<>> less;
 
    while (1) {
        cin >> cmd;
 
        if (cmd == 1) {
            int K, P;
            cin >> K >> P;
            greater.push({ P,K });
            less.push({ P,K });
            visited[K] = 0;
        }
        else if (cmd == 2) {
            while (1) {
                if (less.empty()) {
                    cout << 0 << '\n';
                    break;
                }
                const int K = less.top().second;
                less.pop();
                if (visited[K] != 1) {
                    visited[K] = 1;
                    cout << K << '\n';
                    break;
                }
            }
        }
        else if (cmd == 3) {
            while (1) {
                if (greater.empty()) {
                    cout << 0 << '\n';
                    break;
                }
                const int K = greater.top().second;
                greater.pop();
                if (visited[K] != 1) {
                    visited[K] = 1;
                    cout << K << '\n';
                    break;
                }
            }
        }
        else {
            return 0;
        }
    }
}
cs
반응형

+ Recent posts