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


정렬한다음 중복값 제거하고 최장증가수열 응용했음

풀려고 한지 몇일 됬는데 이거만 계속 생각하고 있을 시간도없고 어렵기도하고 드뎌품


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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
 
typedef struct {
    int first;
    int second;
} Animal;
 
vector<Animal> animal;
int cash[500002= { 0 };
int ans=0;
 
int cmp(const Animal &a, const Animal &b)
{
    if (a.first != b.first) return a.first < b.first;
    else return a.second > b.second;
}
 
void search(int target, int left, int right)
{
    if (left > right)
    {
        if (ans < right+1)
        {
            ans = right+1;
        }
        
        if (cash[right + 1< target)
        {
            cash[right + 1= target;
        }
        return;
    }
 
    int mid = (left + right) / 2;
 
    if (cash[mid] >= target)
    {
        search(target, mid+1, right);
    }
    else
    {
        search(target, left, mid-1);
    }
    return;
}
 
 
 
int main()
{
    int n;
    int index=0;
 
    scanf("%d", &n);
 
    if (n == 0)
    {
        printf("%d\n"0);
        return 0;
    }
 
    while (n--)
    {
        int dum;
        Animal dummy;
        scanf(" %d %d %d",&dum, &dummy.first, &dummy.second);
        animal.push_back(dummy);
    }
 
    sort(animal.begin(), animal.end(),cmp);
 
    for (int i = 1; i < animal.size(); i++)
    {
        if ((animal[i].first == animal[index].first) && (animal[i].second == animal[index].second))
        {
            continue;
        }
        else
        {
            index++;
            animal[index].first = animal[i].first;
            animal[index].second = animal[i].second;
        }
    }
 
    cash[0= 1000000000;
    for (int i = 0; i <= index; i++)
    {
        search(animal[i].second, 0, ans);
    }
 
    printf("%d\n", ans);
 
    return 0;
}
cs



다음문제 골라서 옴