-
Notifications
You must be signed in to change notification settings - Fork 0
/
1216.cpp
68 lines (64 loc) · 1.23 KB
/
1216.cpp
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
63
64
65
66
67
68
#include <iostream>
#include <cstdio>
using namespace std;
const int maxn = 20005;
int M;
int arr[maxn];
int currentSize = 0;
void insert()
{
int x, hole = ++currentSize;
scanf("%d", &x);
for (; hole > 1 && x < arr[hole >> 1]; hole >>= 1)
arr[hole] = arr[hole >> 1];
arr[hole] = x;
}
void find()
{
int x;
scanf("%d", &x);
int min = 2147483647, idx = 0;
for (int i = 1; i <= currentSize; ++i)
{
if (arr[i] <= x) continue;
if (arr[i] < min)
{
idx = i;
min = arr[i];
}
}
printf("%d\n", idx);
}
void decrease()
{
int hole, v;
scanf("%d%d", &hole, &v);
int x = arr[hole] - v;
for (; hole > 1 && x < arr[hole >> 1]; hole >>= 1)
arr[hole] = arr[hole >> 1];
arr[hole] = x;
}
int main()
{
scanf("%d", &M);
char order[10];
while (M--)
{
scanf("%s", &order);
switch (order[0])
{
case 'i':
insert();
break;
case 'f':
find();
break;
case 'd':
decrease();
break;
default:
break;
}
}
return 0;
}