forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path199.cpp
More file actions
65 lines (56 loc) · 1.04 KB
/
199.cpp
File metadata and controls
65 lines (56 loc) · 1.04 KB
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
//ac
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
#define MAXN 1000000
#define _cp(a,b) ((a)<(b))
struct people {
public:
int s;
int b;
int idx;
bool operator < (const people &r) const {
if (s != r.s) return s < r.s;
return b > r.b;
}
};
vector<people> mm;
int n;
vector<int> ans;
int cmp(people a, people b) {
return b.b > a.b;
}
int b[MAXN], p[MAXN];
int subseq(int n){
int i,l,r,m,ret=0;
for (i=0;i<n;p[b[l]=i++]=b[l-1],ret+=(l>ret))
for (m=((l=1)+(r=ret))>>1;l<=r;m=(l+r)>>1)
//if (_cp(a[b[m]],a[i]))
// l=m+1;
if (cmp(mm[b[m]], mm[i]))
l=m+1;
else
r=m-1;
for (m=b[i=ret];i;ans[--i]=mm[m].idx,m=p[m]);
return ret;
}
int main() {
scanf("%d", &n);
mm.resize(n);
ans.resize(n);
for (int i = 0; i < n; ++i) {
scanf("%d %d", &mm[i].s, &mm[i].b);
mm[i].idx = i;
}
sort(mm.begin(), mm.end());
int ret = subseq(n);
printf("%d\n", ret);
for (int i = 0; i < ret; ++i) {
if (i) printf(" ");
printf("%d", ans[i] + 1);
}
printf("\n");
return 0;
}