Submission #796916

# Submission time Handle Problem Language Result Execution time Memory
796916 2023-07-28T23:11:12 Z ashcomp LIS (INOI20_lis) C++14
100 / 100
1142 ms 98920 KB
#include<bits/stdc++.h>

using namespace std;
 
#define all(x) x.begin() , x.end()
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define pb push_back
#define qb pop_back
#define F first
#define S second
#define wall cerr<<"--------------------------------------"<<endl
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#pragma GCC optimize("Ofast")
 
typedef long long ll;
typedef double db;

const ll INF = 1e9;
const ll maxn = 2e6 + 10;
const ll SQRT = 2e3 + 10;

int n , Ps[maxn] , Vl[maxn] , a[maxn] , T[maxn];

int Lz[maxn<<2] , Ar[maxn<<2];
void Build(int tl=1 , int tr=n , int v=1)
{
        if(tl==tr){
                Ar[v] = tl;
                return;
        }
        int mid=(tl+tr)>>1 , ml=(v<<1) , mr=(v<<1)|1;
        Build(tl,mid,ml); Build(mid+1,tr,mr);
        Ar[v] = max(Ar[ml],Ar[mr]);
}
inline void Shift(int tl , int tr , int v)
{
        int ml=(v<<1) , mr=(v<<1)|1;
        Ar[v] += Lz[v];
        Ar[v] = max(0,Ar[v]);
        if(tl!=tr){
                Lz[ml] += Lz[v];
                Lz[mr] += Lz[v];
        }
        Lz[v] = 0;
}
void Upd(int l , int r , int tl=1 , int tr=n , int v=1)
{
        Shift(tl,tr,v);
        if(l>r)return;
        if(l==tl && r==tr){
                Lz[v] --;
                Shift(tl,tr,v);
                return;
        }
        int mid=(tl+tr)>>1 , ml=(v<<1) , mr=(v<<1)|1;
        Upd(l,min(r,mid),tl,mid,ml);
        Upd(max(l,mid+1),r,mid+1,tr,mr);
        Ar[v] = max(Ar[ml],Ar[mr]);
}
void Change(int pos , int tl=1 , int tr=n , int v=1)
{
        Shift(tl,tr,v);
        if(tl==tr){
                Ar[v] = 0;
                return;
        }
        int mid=(tl+tr)>>1 , ml=(v<<1) , mr=(v<<1)|1;
        if(pos<=mid)Change(pos,tl,mid,ml);
        else Change(pos,mid+1,tr,mr);
        Ar[v] = max(Ar[ml],Ar[mr]);
}
int Find(int val , int tl=1 , int tr=n , int v=1)
{
        Shift(tl,tr,v);
        if(tl==tr){
                return tl;
        }
        int mid=(tl+tr)>>1 , ml=(v<<1) , mr=(v<<1)|1;
        Shift(tl,mid,ml); Shift(mid+1,tr,mr);
        if(Ar[ml]>=val){
                return Find(val,tl,mid,ml);
        }else{
                return Find(val,mid+1,tr,mr);
        }
}
// just to find the array
/******/

struct segment
{
        int seg[SQRT<<2];
        void build(int tl=1 , int tr=SQRT , int v=1)
        {
                seg[v] = INF;
                if(tl==tr){
                        return;
                }
                int mid=(tl+tr)>>1 , ml=(v<<1) , mr=(v<<1)|1;
                build(tl,mid,ml); build(mid+1,tr,mr);
        }
        void upd(int pos , int val , int tl=1 , int tr=SQRT , int v=1)
        {
                if(tl==tr){
                        seg[v] = min(val,seg[v]);
                        return;
                }
                int mid=(tl+tr)>>1 , ml=(v<<1) , mr=(v<<1)|1;
                if(pos<=mid)upd(pos , val , tl , mid , ml);
                else upd(pos , val , mid+1 , tr , mr);
                seg[v] = min(seg[ml] , seg[mr]);
        }
        int ask(int l , int r , int tl=1 , int tr=SQRT , int v=1)
        {
                if(l>r)return INF;
                if(l==tl && r==tr){
                        return seg[v];
                }
                int mid=(tl+tr)>>1 , ml=(v<<1) , mr=(v<<1)|1;
                return min(ask(l,min(r,mid),tl,mid,ml) , 
                        ask(max(l,mid+1),r,mid+1,tr,mr));
        }
        int node()
        {
                return seg[1];
        }
}seg[SQRT+1];

int main()
{
        ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
        cin>>n;
        for(int i=1; i<=n; i++){
                cin>>Ps[i]>>Vl[i];
        }
        Build();
        for(int i=n; i>=1; i--){
                int pos = Find(Ps[i]);
                Change(pos);
                Upd(pos+1,n);
                a[pos] = Vl[i];
                T[pos] = i;
        }
        // we found the array
        /***/
        vector<pll> ve;
        for(int i=1; i<=n; i++){
                ve.push_back({a[i],i});
        }
        sort(all(ve));
        int res = 1;
        a[ve[0].S] = 1;
        for(int i=1; i<n; i++){
                if(ve[i].F != ve[i-1].F){
                        res++;
                }
                a[ve[i].S] = res;
        }
        // comperes
        /**/
        for(int i=1; i<=SQRT; i++){
                seg[i].build();
        }
        for(int i=1; i<=n; i++){
                seg[1].upd(a[i],T[i]);
                for(int j=2; j<=a[i]; j++){
                        int x = seg[j-1].ask(1,a[i]-1);
                        x = max(x , T[i]);
                        seg[j].upd(a[i],x);
                }
        }
        for(int i=1; i<=n; i++)a[i]=0;
        for(int i=1; i<=SQRT; i++){
                int x = seg[i].node();
                //cout<<x<<"\n";
                if(x==INF)continue;
                a[x] = i;
        }
        for(int i=1; i<=n; i++){
                a[i] = max(a[i-1],a[i]);
        }
        for(int i=1; i<=n; i++)cout<<a[i]<<"\n";
        return 0;
}
/*
6
1 7
2 10
2 11
2 8
4 10
1 2
*/
/*
ans =
1
2
2
3
3
4
*/
/*
by
          _____                    _____                    _____                    _____                  
         /\    \                  /\    \                  /\    \                  /\    \                 
        /::\    \                /::\    \                /::\____\                /::\    \                
       /::::\    \              /::::\    \              /:::/    /                \:::\    \               
      /::::::\    \            /::::::\    \            /:::/    /                  \:::\    \              
     /:::/\:::\    \          /:::/\:::\    \          /:::/    /                    \:::\    \             
    /:::/__\:::\    \        /:::/__\:::\    \        /:::/____/                      \:::\    \            
   /::::\   \:::\    \       \:::\   \:::\    \      /::::\    \                      /::::\    \           
  /::::::\   \:::\    \    ___\:::\   \:::\    \    /::::::\    \   _____    ____    /::::::\    \          
 /:::/\:::\   \:::\    \  /\   \:::\   \:::\    \  /:::/\:::\    \ /\    \  /\   \  /:::/\:::\    \         
/:::/  \:::\   \:::\____\/::\   \:::\   \:::\____\/:::/  \:::\    /::\____\/::\   \/:::/  \:::\____\        
\::/    \:::\  /:::/    /\:::\   \:::\   \::/    /\::/    \:::\  /:::/    /\:::\  /:::/    \::/    /        
 \/____/ \:::\/:::/    /  \:::\   \:::\   \/____/  \/____/ \:::\/:::/    /  \:::\/:::/    / \/____/         
          \::::::/    /    \:::\   \:::\    \               \::::::/    /    \::::::/    /                  
           \::::/    /      \:::\   \:::\____\               \::::/    /      \::::/____/                   
           /:::/    /        \:::\  /:::/    /               /:::/    /        \:::\    \                   
          /:::/    /          \:::\/:::/    /               /:::/    /          \:::\    \                  
         /:::/    /            \::::::/    /               /:::/    /            \:::\    \                 
        /:::/    /              \::::/    /               /:::/    /              \:::\____\                
        \::/    /                \::/    /                \::/    /                \::/    /                
         \/____/                  \/____/                  \/____/                  \/____/                 
                                                                                                            
*/
//NOGHRE SHODANAM BAD NIST :_)
# Verdict Execution time Memory Grader output
1 Correct 20 ms 40532 KB Output is correct
2 Correct 22 ms 40624 KB Output is correct
3 Correct 25 ms 40756 KB Output is correct
4 Correct 37 ms 40720 KB Output is correct
5 Correct 26 ms 40652 KB Output is correct
6 Correct 24 ms 40696 KB Output is correct
7 Correct 29 ms 40752 KB Output is correct
8 Correct 37 ms 40784 KB Output is correct
9 Correct 29 ms 40772 KB Output is correct
10 Correct 29 ms 40692 KB Output is correct
11 Correct 32 ms 40768 KB Output is correct
12 Correct 30 ms 40776 KB Output is correct
13 Correct 32 ms 40664 KB Output is correct
14 Correct 31 ms 40720 KB Output is correct
15 Correct 26 ms 40744 KB Output is correct
16 Correct 29 ms 40660 KB Output is correct
17 Correct 31 ms 40652 KB Output is correct
18 Correct 32 ms 40768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 40532 KB Output is correct
2 Correct 22 ms 40624 KB Output is correct
3 Correct 25 ms 40756 KB Output is correct
4 Correct 37 ms 40720 KB Output is correct
5 Correct 26 ms 40652 KB Output is correct
6 Correct 24 ms 40696 KB Output is correct
7 Correct 29 ms 40752 KB Output is correct
8 Correct 37 ms 40784 KB Output is correct
9 Correct 29 ms 40772 KB Output is correct
10 Correct 29 ms 40692 KB Output is correct
11 Correct 32 ms 40768 KB Output is correct
12 Correct 30 ms 40776 KB Output is correct
13 Correct 32 ms 40664 KB Output is correct
14 Correct 31 ms 40720 KB Output is correct
15 Correct 26 ms 40744 KB Output is correct
16 Correct 29 ms 40660 KB Output is correct
17 Correct 31 ms 40652 KB Output is correct
18 Correct 32 ms 40768 KB Output is correct
19 Correct 194 ms 52468 KB Output is correct
20 Correct 190 ms 52612 KB Output is correct
21 Correct 179 ms 51620 KB Output is correct
22 Correct 198 ms 51816 KB Output is correct
23 Correct 224 ms 52492 KB Output is correct
24 Correct 209 ms 52428 KB Output is correct
25 Correct 207 ms 52508 KB Output is correct
26 Correct 205 ms 52428 KB Output is correct
27 Correct 215 ms 52392 KB Output is correct
28 Correct 218 ms 52508 KB Output is correct
29 Correct 223 ms 52532 KB Output is correct
30 Correct 208 ms 52500 KB Output is correct
31 Correct 222 ms 52488 KB Output is correct
32 Correct 218 ms 52408 KB Output is correct
33 Correct 227 ms 52428 KB Output is correct
34 Correct 225 ms 52512 KB Output is correct
35 Correct 215 ms 52512 KB Output is correct
36 Correct 225 ms 52512 KB Output is correct
37 Correct 230 ms 52492 KB Output is correct
38 Correct 230 ms 52484 KB Output is correct
39 Correct 214 ms 52416 KB Output is correct
40 Correct 228 ms 52512 KB Output is correct
41 Correct 148 ms 50844 KB Output is correct
42 Correct 45 ms 42360 KB Output is correct
43 Correct 140 ms 50216 KB Output is correct
44 Correct 112 ms 46456 KB Output is correct
45 Correct 36 ms 41552 KB Output is correct
46 Correct 24 ms 40832 KB Output is correct
47 Correct 86 ms 45492 KB Output is correct
48 Correct 68 ms 43716 KB Output is correct
49 Correct 32 ms 41432 KB Output is correct
50 Correct 24 ms 40836 KB Output is correct
51 Correct 62 ms 43516 KB Output is correct
52 Correct 136 ms 47664 KB Output is correct
53 Correct 121 ms 46932 KB Output is correct
54 Correct 107 ms 46384 KB Output is correct
55 Correct 41 ms 42072 KB Output is correct
56 Correct 94 ms 45796 KB Output is correct
57 Correct 53 ms 42572 KB Output is correct
58 Correct 49 ms 42384 KB Output is correct
59 Correct 29 ms 41192 KB Output is correct
60 Correct 132 ms 47172 KB Output is correct
61 Correct 24 ms 40772 KB Output is correct
62 Correct 72 ms 43864 KB Output is correct
63 Correct 49 ms 42360 KB Output is correct
64 Correct 98 ms 45888 KB Output is correct
65 Correct 90 ms 45688 KB Output is correct
66 Correct 40 ms 42036 KB Output is correct
67 Correct 76 ms 43992 KB Output is correct
68 Correct 58 ms 43260 KB Output is correct
69 Correct 89 ms 45492 KB Output is correct
70 Correct 37 ms 41552 KB Output is correct
71 Correct 1089 ms 98916 KB Output is correct
72 Correct 1114 ms 98840 KB Output is correct
73 Correct 1075 ms 98920 KB Output is correct
74 Correct 1079 ms 98916 KB Output is correct
75 Correct 1087 ms 98860 KB Output is correct
76 Correct 1142 ms 98916 KB Output is correct