-
Notifications
You must be signed in to change notification settings - Fork 0
/
CSES1645.cpp
78 lines (61 loc) · 1.31 KB
/
CSES1645.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
69
70
71
72
73
74
75
76
77
78
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define mp make_pair
#define pb push_back
const ll MOD = 1e9 + 7;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, ind;
cin >> n;
multiset<int> values;
pair<int, int> p[n];
map<int, int> mp;
vector< int > v[n + 1];
for(int i = 0; i < n; i++) {
cin >> p[i].F;
p[i].S = i + 1;
}
sort(p, p + n);
ind=1;
mp[p[0].F]=1;
for(int i=1; i<n; i++){
if(p[i].F!=p[i-1].F){
ind++;
mp[p[i].F]=ind;
}
}
for(int i=0; i<n; i++){
v[mp[p[i].F]].pb(p[i].S);
}
int a[n];
for(int i = 0; i < n; i++) {
if(i > 0 && p[i-1].F != p[i].F){
for(int j = 0; j < v[mp[p[i-1].F]].size(); j++) {
values.insert(v[mp[p[i-1].F]][j]);
}
}
auto it = values.lower_bound(p[i].second);
if(it == values.begin()) {
a[p[i].second - 1] = 0;
} else {
it--;
a[p[i].second - 1] = *it;
}
}
for(int i = 0; i < n; i++)
cout << a[i] << ' ';
return 0;
}
/*
RILY <3
NEVER GIVE UP!!!
*/