-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbj_17299.cpp
More file actions
54 lines (44 loc) · 1013 Bytes
/
bj_17299.cpp
File metadata and controls
54 lines (44 loc) · 1013 Bytes
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 <iostream>
#include <algorithm>
#include <string.h>
#include <stack>
using namespace std;
int ans[1000001] = {};
int org[1000001] = {};
int org_cnt[1000001] = {};
int cnt[1000001] = {};
int N;
stack<pair<int, int> > ST;
int main() {
cin.tie(NULL);
cout.tie(NULL);
ios_base::sync_with_stdio(false);
cin >> N;
stack<pair<int, int> > q;
memset(ans, -1, sizeof(ans));
for(int i = 0; i < N; i++) {
int tar;
cin >> tar;
org[i] = tar;
cnt[tar]++;
}
for(int i = 0; i<N; i++) {
org_cnt[i] = cnt[org[i]];
}
for(int i = 0; i<N; i++) {
int target = org_cnt[i];
while(!ST.empty()) {
if(target > ST.top().first) {
ans[ST.top().second] = org[i];
ST.pop();
} else {
break;
}
}
ST.push(pair<int, int>(target, i));
}
for(int i = 0; i<N; i++) {
cout << ans[i] << " ";
}
return 0;
}