#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
#define all(x) x.begin() , x.end()
#define sze(x) (ll)(x.size())
typedef long long ll;
const ll maxn = 1e6 + 17 , maxa = 1.5e3 , inf = 2e16;
struct segtree {
ll sz = 1;
vector<ll> val;
void build(ll x , ll lx , ll rx){
if(rx - lx == 1){
val[x] = 1;
return;
}
ll m = (rx + lx) >> 1 , ln = (x << 1) + 1 , rn = ln + 1;
build(ln , lx , m); build(rn , m , rx);
val[x] = val[ln] + val[rn];
return;
}
void build(){
build(0 , 0 , sz);
return;
}
void init(ll n){
while(sz < n) sz <<= 1;
val.resize(sz << 1);
build();
return;
}
void set(ll i , ll x , ll lx , ll rx){
if(rx - lx == 1){
val[x] = 0;
return;
}
ll m = (rx + lx) >> 1 , ln = (x << 1) + 1 , rn = ln + 1;
if(i < m){
set(i , ln , lx , m);
} else {
set(i , rn , m , rx);
}
val[x] = val[ln] + val[rn];
return;
}
void set(ll i){
set(i , 0 , 0 , sz);
return;
}
ll cal(ll k , ll x , ll lx , ll rx){
if(rx - lx == 1){
return lx;
}
ll m = (rx + lx) >> 1 , ln = (x << 1) + 1 , rn = ln + 1;
if(val[ln] >= k){
return cal(k , ln , lx , m);
}
return cal(k - val[ln] , rn , m , rx);
}
ll cal(ll k){
ll h = cal(k , 0 , 0 , sz);
set(h);
return h;
}
};
struct mintree {
ll sz = 1;
vector<ll> val;
void init(ll n){
while(sz < n) sz <<= 1;
val.assign(sz << 1 , inf);
return;
}
void set(ll i , ll k , ll x , ll lx , ll rx){
if(rx - lx == 1){
val[x] = min(val[x] , k);
return;
}
ll m = (rx + lx) >> 1 , ln = (x << 1) + 1 , rn = ln + 1;
if(i < m){
set(i , k , ln , lx , m);
} else {
set(i , k , rn , m , rx);
}
val[x] = min(val[ln] , val[rn]);
return;
}
void set(ll i , ll k){
set(i , k , 0 , 0 , sz);
return;
}
ll cal(ll l , ll r , ll x , ll lx , ll rx){
if(rx <= l || lx >= r) return inf;
if(rx <= r && lx >= l) return val[x];
ll m = (rx + lx) >> 1 , ln = (x << 1) + 1 , rn = ln + 1;
ll a = cal(l , r , ln , lx , m) , b = cal(l , r , rn , m , rx);
return min(a , b);
}
ll cal(ll l , ll r){
return cal(l , r , 0 , 0 , sz);
}
};
segtree st;
mintree mt[maxa];
ll t[maxn] , a[maxn] , p[maxn] , x[maxn] , ans[maxn];
vector<ll> v;
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll n;
cin>>n;
for(ll i = 0 ; i < n ; i++){
cin>>p[i]>>x[i];
v.push_back(x[i]);
}
sort(all(v));
v.resize(distance(v.begin() , unique(all(v))));
st.init(n);
for(ll i = n - 1 ; ~i ; i--){
ll j = st.cal(p[i]);
t[j] = i;
a[j] = lower_bound(all(v) , x[i]) - v.begin() + 1;
}
ll vs = sze(v);
for(ll i = 1 ; i <= vs ; i++){
mt[i].init(vs + 1);
}
for(ll i = 0 ; i < n ; i++){
mt[1].set(a[i] , t[i]);
for(ll j = 2 ; j <= a[i] ; j++){
ll h = max(t[i] , mt[j - 1].cal(0 , a[i]));
mt[j].set(a[i] , h);
}
}
for(ll j = 1 ; j <= vs ; j++){
ll h = mt[j].cal(0 , vs + 1);
if(h == inf) break;
ans[h] = j;
}
cout<<"1\n";
for(ll i = 1 ; i < n ; i++){
ans[i] = max(ans[i] , ans[i - 1]);
cout<<ans[i]<<'\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
652 KB |
Output is correct |
4 |
Correct |
5 ms |
724 KB |
Output is correct |
5 |
Correct |
4 ms |
724 KB |
Output is correct |
6 |
Correct |
3 ms |
596 KB |
Output is correct |
7 |
Correct |
5 ms |
724 KB |
Output is correct |
8 |
Correct |
4 ms |
736 KB |
Output is correct |
9 |
Correct |
7 ms |
1024 KB |
Output is correct |
10 |
Correct |
4 ms |
724 KB |
Output is correct |
11 |
Correct |
6 ms |
980 KB |
Output is correct |
12 |
Correct |
3 ms |
596 KB |
Output is correct |
13 |
Correct |
5 ms |
724 KB |
Output is correct |
14 |
Correct |
6 ms |
724 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
7 ms |
724 KB |
Output is correct |
17 |
Correct |
7 ms |
980 KB |
Output is correct |
18 |
Correct |
5 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
652 KB |
Output is correct |
4 |
Correct |
5 ms |
724 KB |
Output is correct |
5 |
Correct |
4 ms |
724 KB |
Output is correct |
6 |
Correct |
3 ms |
596 KB |
Output is correct |
7 |
Correct |
5 ms |
724 KB |
Output is correct |
8 |
Correct |
4 ms |
736 KB |
Output is correct |
9 |
Correct |
7 ms |
1024 KB |
Output is correct |
10 |
Correct |
4 ms |
724 KB |
Output is correct |
11 |
Correct |
6 ms |
980 KB |
Output is correct |
12 |
Correct |
3 ms |
596 KB |
Output is correct |
13 |
Correct |
5 ms |
724 KB |
Output is correct |
14 |
Correct |
6 ms |
724 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
7 ms |
724 KB |
Output is correct |
17 |
Correct |
7 ms |
980 KB |
Output is correct |
18 |
Correct |
5 ms |
724 KB |
Output is correct |
19 |
Correct |
76 ms |
15032 KB |
Output is correct |
20 |
Correct |
85 ms |
15184 KB |
Output is correct |
21 |
Correct |
74 ms |
14320 KB |
Output is correct |
22 |
Correct |
82 ms |
14400 KB |
Output is correct |
23 |
Correct |
103 ms |
15040 KB |
Output is correct |
24 |
Correct |
103 ms |
15124 KB |
Output is correct |
25 |
Correct |
105 ms |
15260 KB |
Output is correct |
26 |
Correct |
109 ms |
15124 KB |
Output is correct |
27 |
Correct |
102 ms |
15076 KB |
Output is correct |
28 |
Correct |
106 ms |
15060 KB |
Output is correct |
29 |
Correct |
106 ms |
15224 KB |
Output is correct |
30 |
Correct |
107 ms |
15116 KB |
Output is correct |
31 |
Correct |
118 ms |
15108 KB |
Output is correct |
32 |
Correct |
110 ms |
15100 KB |
Output is correct |
33 |
Correct |
107 ms |
15116 KB |
Output is correct |
34 |
Correct |
108 ms |
15120 KB |
Output is correct |
35 |
Correct |
110 ms |
15120 KB |
Output is correct |
36 |
Correct |
118 ms |
15112 KB |
Output is correct |
37 |
Correct |
111 ms |
15080 KB |
Output is correct |
38 |
Correct |
108 ms |
15096 KB |
Output is correct |
39 |
Correct |
109 ms |
15132 KB |
Output is correct |
40 |
Correct |
111 ms |
15124 KB |
Output is correct |
41 |
Correct |
71 ms |
12864 KB |
Output is correct |
42 |
Correct |
16 ms |
2740 KB |
Output is correct |
43 |
Correct |
61 ms |
12064 KB |
Output is correct |
44 |
Correct |
52 ms |
7912 KB |
Output is correct |
45 |
Correct |
12 ms |
2144 KB |
Output is correct |
46 |
Correct |
3 ms |
724 KB |
Output is correct |
47 |
Correct |
45 ms |
6456 KB |
Output is correct |
48 |
Correct |
35 ms |
4644 KB |
Output is correct |
49 |
Correct |
8 ms |
1876 KB |
Output is correct |
50 |
Correct |
4 ms |
1236 KB |
Output is correct |
51 |
Correct |
30 ms |
4388 KB |
Output is correct |
52 |
Correct |
75 ms |
9416 KB |
Output is correct |
53 |
Correct |
68 ms |
8368 KB |
Output is correct |
54 |
Correct |
55 ms |
7624 KB |
Output is correct |
55 |
Correct |
15 ms |
2392 KB |
Output is correct |
56 |
Correct |
52 ms |
7104 KB |
Output is correct |
57 |
Correct |
23 ms |
3288 KB |
Output is correct |
58 |
Correct |
21 ms |
3096 KB |
Output is correct |
59 |
Correct |
7 ms |
1492 KB |
Output is correct |
60 |
Correct |
76 ms |
8644 KB |
Output is correct |
61 |
Correct |
3 ms |
980 KB |
Output is correct |
62 |
Correct |
34 ms |
4492 KB |
Output is correct |
63 |
Correct |
20 ms |
3096 KB |
Output is correct |
64 |
Correct |
51 ms |
7008 KB |
Output is correct |
65 |
Correct |
48 ms |
6728 KB |
Output is correct |
66 |
Correct |
12 ms |
2136 KB |
Output is correct |
67 |
Correct |
38 ms |
4976 KB |
Output is correct |
68 |
Correct |
25 ms |
3648 KB |
Output is correct |
69 |
Correct |
46 ms |
6456 KB |
Output is correct |
70 |
Correct |
13 ms |
2108 KB |
Output is correct |
71 |
Correct |
585 ms |
74284 KB |
Output is correct |
72 |
Correct |
617 ms |
74272 KB |
Output is correct |
73 |
Correct |
594 ms |
74344 KB |
Output is correct |
74 |
Correct |
622 ms |
74240 KB |
Output is correct |
75 |
Correct |
618 ms |
74216 KB |
Output is correct |
76 |
Correct |
624 ms |
74208 KB |
Output is correct |