Submission #789139

# Submission time Handle Problem Language Result Execution time Memory
789139 2023-07-21T06:13:16 Z winter0101 Event Hopping 2 (JOI21_event2) C++14
100 / 100
135 ms 29156 KB
#include<bits/stdc++.h>
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
#define pil pair<int,long long>
const int maxn=1e5+9;
struct line{
int l,r,id;
bool operator < (const line &p)const {
return r<p.r;
}
}a[maxn];
int st[maxn][21];
vector<int>del[maxn];
int suf[maxn];
int pos[maxn];
struct cus{
int u;
bool operator < (const cus &p)const {
return pos[u]<pos[p.u];
}
};
int p[maxn];
int f[maxn];
int afs[maxn];
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("temp.INP","r",stdin);
    //freopen("temp.OUT","w",stdout);
    int n,k;
    cin>>n>>k;
    for1(i,1,n){
    cin>>a[i].l>>a[i].r;
    a[i].id=i;
    }
    sort(a+1,a+1+n);
    for1(i,1,n){
    pos[a[i].id]=i;
    int l=1,r=i-1,ans=0;
    while (l<=r){
        int mid=(l+r)/2;
        if (a[mid].r<=a[i].l){
            l=mid+1;
            ans=mid;
        }
        else r=mid-1;
    }
    del[ans].pb(i);
    f[i]=1+p[ans];
    p[i]=max(p[i-1],f[i]);
    f[i]--;
    }
    set<int>num;
    for1(i,1,n+1)num.insert(i);
    for1(i,0,0){
    for (auto v:del[i]){
        num.erase(v);
    }
    }
    st[n+1][0]=n+1;
    a[n+1].l=a[n+1].r=1e9+1;
    for1(i,1,n){
    st[i][0]=*(num.begin());
    for (auto v:del[i]){
        num.erase(v);
    }
    }
    for1(j,1,20){
    for1(i,1,n+1){
    st[i][j]=st[st[i][j-1]][j-1];
    }
    }
    set<int>best;
    set<int>::iterator it2;
    best.insert(0);
    for2(i,n,1){
    for (auto v:del[i]){
        best.insert(suf[v]);
    }
    it2=best.end();
    it2--;
    suf[i]=(*it2)+1;
    }
    for1(i,1,n){
    suf[i]--;
    }
    int maxnum=0;
    multiset<cus>t;
    multiset<cus>::iterator it;
    for1(i,1,n){
    if (sz(t)==k){
        //cout<<"vai l";
        break;
    }
    if (t.empty()){
        int id=pos[i];
        if (f[id]+1+suf[id]>=k){
            t.insert({i});
            maxnum=f[id]+1+suf[id];
        }
        continue;
    }
    else {
        it=t.upper_bound({i});
        int nw=maxnum;
        //if (i==3)cout<<maxnum<<" "<<k<<'\n';
        if (it==t.end()){
            it--;
            //cout<<maxnum<<'\n';
            int id1=pos[(*it).u];
            if (a[id1].r>a[pos[i]].l)continue;
            nw-=suf[id1];
            nw++;
            nw+=suf[pos[i]];
            //if (i==3)cout<<nw<<'\n';
            int u=id1;
            //if (i==3)cout<<st[id1][20]<<'\n';
            for2(j,20,0){
            int id2=st[u][j];
            if (a[id2].r<=a[pos[i]].l){
                nw+=(1<<j);
                u=st[u][j];
            }
            }
            if (nw>=k){
                t.insert({i});
                maxnum=nw;
            }
            continue;
        }
        else if (it==t.begin()){
            int id1=pos[(*it).u];
            if (a[pos[i]].r>a[id1].l)continue;
            nw-=f[id1];
            nw++;
            nw+=f[pos[i]];
            int u=pos[i];
            for2(j,20,0){
            int id2=st[u][j];
            if (a[id2].r<=a[id1].l){
                nw+=(1<<j);
                u=st[u][j];
            }
            }
            if (nw>=k){
                t.insert({i});
                maxnum=nw;
            }
            continue;
        }
        else {
           int id2=pos[(*it).u];
           it--;
           int id1=pos[(*it).u];
           if (a[id1].r>a[pos[i]].l)continue;
           if (a[pos[i]].r>a[id2].l)continue;
           int u=id1;
           for2(j,20,0){
           int id3=st[u][j];
           if (a[id3].r<=a[id2].l){
            nw-=(1<<j);
            u=st[u][j];
           }
           }
           nw++;
           u=id1;
           for2(j,20,0){
           int id3=st[u][j];
           if (a[id3].r<=a[pos[i]].l){
            nw+=(1<<j);
            u=st[u][j];
           }
           }
           u=pos[i];
           for2(j,20,0){
           int id3=st[u][j];
           if (a[id3].r<=a[id2].l){
            nw+=(1<<j);
            u=st[u][j];
           }
           }
           if (nw>=k){
            t.insert({i});
            maxnum=nw;
           }
           continue;
        }
    }
    }
    //cout<<maxnum;
    if (sz(t)<k){
        cout<<-1;
        return 0;
    }
    vector<int>as;
    for(auto v:t)as.pb(v.u);
    sort(all(as));
    for (auto v:as)cout<<v<<'\n';




}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2692 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 99 ms 26220 KB Output is correct
5 Correct 96 ms 27920 KB Output is correct
6 Correct 103 ms 27588 KB Output is correct
7 Correct 94 ms 27104 KB Output is correct
8 Correct 100 ms 28196 KB Output is correct
9 Correct 96 ms 27888 KB Output is correct
10 Correct 97 ms 27616 KB Output is correct
11 Correct 97 ms 27168 KB Output is correct
12 Correct 85 ms 23528 KB Output is correct
13 Correct 83 ms 23344 KB Output is correct
14 Correct 83 ms 23244 KB Output is correct
15 Correct 77 ms 22804 KB Output is correct
16 Correct 67 ms 21872 KB Output is correct
17 Correct 73 ms 21836 KB Output is correct
18 Correct 67 ms 21836 KB Output is correct
19 Correct 68 ms 21796 KB Output is correct
20 Correct 67 ms 21772 KB Output is correct
21 Correct 68 ms 21836 KB Output is correct
22 Correct 70 ms 21752 KB Output is correct
23 Correct 70 ms 21860 KB Output is correct
24 Correct 71 ms 21872 KB Output is correct
25 Correct 76 ms 21708 KB Output is correct
26 Correct 74 ms 21684 KB Output is correct
27 Correct 73 ms 21672 KB Output is correct
28 Correct 62 ms 23048 KB Output is correct
29 Correct 60 ms 22064 KB Output is correct
30 Correct 66 ms 21844 KB Output is correct
31 Correct 62 ms 21744 KB Output is correct
32 Correct 74 ms 21860 KB Output is correct
33 Correct 89 ms 21776 KB Output is correct
34 Correct 89 ms 22468 KB Output is correct
35 Correct 68 ms 22264 KB Output is correct
36 Correct 66 ms 22140 KB Output is correct
37 Correct 84 ms 22332 KB Output is correct
38 Correct 90 ms 22300 KB Output is correct
39 Correct 83 ms 22316 KB Output is correct
40 Correct 77 ms 22196 KB Output is correct
41 Correct 78 ms 22124 KB Output is correct
42 Correct 58 ms 21708 KB Output is correct
43 Correct 75 ms 22392 KB Output is correct
44 Correct 80 ms 22192 KB Output is correct
45 Correct 72 ms 22152 KB Output is correct
46 Correct 81 ms 22152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 1 ms 2692 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 1 ms 2692 KB Output is correct
12 Correct 1 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2684 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 1 ms 2696 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 1 ms 2644 KB Output is correct
19 Correct 1 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 1 ms 2644 KB Output is correct
23 Correct 1 ms 2644 KB Output is correct
24 Correct 1 ms 2644 KB Output is correct
25 Correct 1 ms 2644 KB Output is correct
26 Correct 1 ms 2688 KB Output is correct
27 Correct 2 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 1 ms 2692 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 1 ms 2692 KB Output is correct
12 Correct 1 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2684 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 1 ms 2696 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 1 ms 2644 KB Output is correct
19 Correct 1 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 1 ms 2644 KB Output is correct
23 Correct 1 ms 2644 KB Output is correct
24 Correct 1 ms 2644 KB Output is correct
25 Correct 1 ms 2644 KB Output is correct
26 Correct 1 ms 2688 KB Output is correct
27 Correct 2 ms 2644 KB Output is correct
28 Correct 3 ms 3216 KB Output is correct
29 Correct 3 ms 3156 KB Output is correct
30 Correct 4 ms 3212 KB Output is correct
31 Correct 3 ms 3156 KB Output is correct
32 Correct 3 ms 3156 KB Output is correct
33 Correct 3 ms 3156 KB Output is correct
34 Correct 4 ms 3348 KB Output is correct
35 Correct 4 ms 3396 KB Output is correct
36 Correct 4 ms 3412 KB Output is correct
37 Correct 4 ms 3412 KB Output is correct
38 Correct 3 ms 3284 KB Output is correct
39 Correct 4 ms 3412 KB Output is correct
40 Correct 4 ms 3412 KB Output is correct
41 Correct 4 ms 3284 KB Output is correct
42 Correct 3 ms 3284 KB Output is correct
43 Correct 4 ms 3284 KB Output is correct
44 Correct 4 ms 3212 KB Output is correct
45 Correct 4 ms 3284 KB Output is correct
46 Correct 3 ms 3216 KB Output is correct
47 Correct 3 ms 3284 KB Output is correct
48 Correct 3 ms 3284 KB Output is correct
49 Correct 3 ms 3284 KB Output is correct
50 Correct 3 ms 3284 KB Output is correct
51 Correct 3 ms 3284 KB Output is correct
52 Correct 3 ms 3284 KB Output is correct
53 Correct 3 ms 3284 KB Output is correct
54 Correct 4 ms 3220 KB Output is correct
55 Correct 4 ms 3412 KB Output is correct
56 Correct 5 ms 3412 KB Output is correct
57 Correct 4 ms 3412 KB Output is correct
58 Correct 4 ms 3476 KB Output is correct
59 Correct 3 ms 3484 KB Output is correct
60 Correct 4 ms 3492 KB Output is correct
61 Correct 3 ms 3412 KB Output is correct
62 Correct 3 ms 3472 KB Output is correct
63 Correct 3 ms 3412 KB Output is correct
64 Correct 3 ms 3284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2692 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 99 ms 26220 KB Output is correct
5 Correct 96 ms 27920 KB Output is correct
6 Correct 103 ms 27588 KB Output is correct
7 Correct 94 ms 27104 KB Output is correct
8 Correct 100 ms 28196 KB Output is correct
9 Correct 96 ms 27888 KB Output is correct
10 Correct 97 ms 27616 KB Output is correct
11 Correct 97 ms 27168 KB Output is correct
12 Correct 85 ms 23528 KB Output is correct
13 Correct 83 ms 23344 KB Output is correct
14 Correct 83 ms 23244 KB Output is correct
15 Correct 77 ms 22804 KB Output is correct
16 Correct 67 ms 21872 KB Output is correct
17 Correct 73 ms 21836 KB Output is correct
18 Correct 67 ms 21836 KB Output is correct
19 Correct 68 ms 21796 KB Output is correct
20 Correct 67 ms 21772 KB Output is correct
21 Correct 68 ms 21836 KB Output is correct
22 Correct 70 ms 21752 KB Output is correct
23 Correct 70 ms 21860 KB Output is correct
24 Correct 71 ms 21872 KB Output is correct
25 Correct 76 ms 21708 KB Output is correct
26 Correct 74 ms 21684 KB Output is correct
27 Correct 73 ms 21672 KB Output is correct
28 Correct 62 ms 23048 KB Output is correct
29 Correct 60 ms 22064 KB Output is correct
30 Correct 66 ms 21844 KB Output is correct
31 Correct 62 ms 21744 KB Output is correct
32 Correct 74 ms 21860 KB Output is correct
33 Correct 89 ms 21776 KB Output is correct
34 Correct 89 ms 22468 KB Output is correct
35 Correct 68 ms 22264 KB Output is correct
36 Correct 66 ms 22140 KB Output is correct
37 Correct 84 ms 22332 KB Output is correct
38 Correct 90 ms 22300 KB Output is correct
39 Correct 83 ms 22316 KB Output is correct
40 Correct 77 ms 22196 KB Output is correct
41 Correct 78 ms 22124 KB Output is correct
42 Correct 58 ms 21708 KB Output is correct
43 Correct 75 ms 22392 KB Output is correct
44 Correct 80 ms 22192 KB Output is correct
45 Correct 72 ms 22152 KB Output is correct
46 Correct 81 ms 22152 KB Output is correct
47 Correct 1 ms 2644 KB Output is correct
48 Correct 1 ms 2644 KB Output is correct
49 Correct 1 ms 2644 KB Output is correct
50 Correct 1 ms 2644 KB Output is correct
51 Correct 2 ms 2644 KB Output is correct
52 Correct 1 ms 2644 KB Output is correct
53 Correct 1 ms 2644 KB Output is correct
54 Correct 2 ms 2644 KB Output is correct
55 Correct 1 ms 2692 KB Output is correct
56 Correct 1 ms 2644 KB Output is correct
57 Correct 1 ms 2692 KB Output is correct
58 Correct 1 ms 2644 KB Output is correct
59 Correct 2 ms 2644 KB Output is correct
60 Correct 2 ms 2684 KB Output is correct
61 Correct 2 ms 2644 KB Output is correct
62 Correct 1 ms 2696 KB Output is correct
63 Correct 2 ms 2644 KB Output is correct
64 Correct 1 ms 2644 KB Output is correct
65 Correct 1 ms 2644 KB Output is correct
66 Correct 2 ms 2644 KB Output is correct
67 Correct 2 ms 2644 KB Output is correct
68 Correct 1 ms 2644 KB Output is correct
69 Correct 1 ms 2644 KB Output is correct
70 Correct 1 ms 2644 KB Output is correct
71 Correct 1 ms 2644 KB Output is correct
72 Correct 1 ms 2688 KB Output is correct
73 Correct 2 ms 2644 KB Output is correct
74 Correct 3 ms 3216 KB Output is correct
75 Correct 3 ms 3156 KB Output is correct
76 Correct 4 ms 3212 KB Output is correct
77 Correct 3 ms 3156 KB Output is correct
78 Correct 3 ms 3156 KB Output is correct
79 Correct 3 ms 3156 KB Output is correct
80 Correct 4 ms 3348 KB Output is correct
81 Correct 4 ms 3396 KB Output is correct
82 Correct 4 ms 3412 KB Output is correct
83 Correct 4 ms 3412 KB Output is correct
84 Correct 3 ms 3284 KB Output is correct
85 Correct 4 ms 3412 KB Output is correct
86 Correct 4 ms 3412 KB Output is correct
87 Correct 4 ms 3284 KB Output is correct
88 Correct 3 ms 3284 KB Output is correct
89 Correct 4 ms 3284 KB Output is correct
90 Correct 4 ms 3212 KB Output is correct
91 Correct 4 ms 3284 KB Output is correct
92 Correct 3 ms 3216 KB Output is correct
93 Correct 3 ms 3284 KB Output is correct
94 Correct 3 ms 3284 KB Output is correct
95 Correct 3 ms 3284 KB Output is correct
96 Correct 3 ms 3284 KB Output is correct
97 Correct 3 ms 3284 KB Output is correct
98 Correct 3 ms 3284 KB Output is correct
99 Correct 3 ms 3284 KB Output is correct
100 Correct 4 ms 3220 KB Output is correct
101 Correct 4 ms 3412 KB Output is correct
102 Correct 5 ms 3412 KB Output is correct
103 Correct 4 ms 3412 KB Output is correct
104 Correct 4 ms 3476 KB Output is correct
105 Correct 3 ms 3484 KB Output is correct
106 Correct 4 ms 3492 KB Output is correct
107 Correct 3 ms 3412 KB Output is correct
108 Correct 3 ms 3472 KB Output is correct
109 Correct 3 ms 3412 KB Output is correct
110 Correct 3 ms 3284 KB Output is correct
111 Correct 96 ms 21396 KB Output is correct
112 Correct 119 ms 21536 KB Output is correct
113 Correct 97 ms 21500 KB Output is correct
114 Correct 95 ms 21452 KB Output is correct
115 Correct 89 ms 21380 KB Output is correct
116 Correct 88 ms 21404 KB Output is correct
117 Correct 90 ms 21380 KB Output is correct
118 Correct 130 ms 28240 KB Output is correct
119 Correct 126 ms 27708 KB Output is correct
120 Correct 100 ms 22856 KB Output is correct
121 Correct 66 ms 22056 KB Output is correct
122 Correct 118 ms 23572 KB Output is correct
123 Correct 122 ms 23192 KB Output is correct
124 Correct 99 ms 22864 KB Output is correct
125 Correct 65 ms 22128 KB Output is correct
126 Correct 85 ms 21836 KB Output is correct
127 Correct 92 ms 21884 KB Output is correct
128 Correct 100 ms 21860 KB Output is correct
129 Correct 64 ms 21772 KB Output is correct
130 Correct 78 ms 21868 KB Output is correct
131 Correct 79 ms 21872 KB Output is correct
132 Correct 76 ms 21804 KB Output is correct
133 Correct 68 ms 21744 KB Output is correct
134 Correct 82 ms 21744 KB Output is correct
135 Correct 79 ms 21792 KB Output is correct
136 Correct 74 ms 21772 KB Output is correct
137 Correct 70 ms 21860 KB Output is correct
138 Correct 77 ms 21736 KB Output is correct
139 Correct 82 ms 21796 KB Output is correct
140 Correct 77 ms 21748 KB Output is correct
141 Correct 77 ms 21792 KB Output is correct
142 Correct 104 ms 29096 KB Output is correct
143 Correct 106 ms 29116 KB Output is correct
144 Correct 111 ms 29156 KB Output is correct
145 Correct 98 ms 28992 KB Output is correct
146 Correct 100 ms 28844 KB Output is correct
147 Correct 96 ms 28820 KB Output is correct
148 Correct 97 ms 28716 KB Output is correct
149 Correct 94 ms 28488 KB Output is correct
150 Correct 95 ms 28452 KB Output is correct
151 Correct 88 ms 27872 KB Output is correct
152 Correct 70 ms 23248 KB Output is correct
153 Correct 105 ms 29124 KB Output is correct
154 Correct 98 ms 28928 KB Output is correct
155 Correct 94 ms 28868 KB Output is correct
156 Correct 96 ms 28780 KB Output is correct
157 Correct 106 ms 28660 KB Output is correct
158 Correct 94 ms 28572 KB Output is correct
159 Correct 91 ms 27924 KB Output is correct
160 Correct 62 ms 23288 KB Output is correct
161 Correct 105 ms 22320 KB Output is correct
162 Correct 111 ms 22384 KB Output is correct
163 Correct 106 ms 22252 KB Output is correct
164 Correct 96 ms 22224 KB Output is correct
165 Correct 93 ms 22196 KB Output is correct
166 Correct 67 ms 21716 KB Output is correct
167 Correct 75 ms 22408 KB Output is correct
168 Correct 82 ms 22260 KB Output is correct
169 Correct 76 ms 22180 KB Output is correct
170 Correct 73 ms 22200 KB Output is correct
171 Correct 75 ms 21680 KB Output is correct
172 Correct 84 ms 22476 KB Output is correct
173 Correct 108 ms 23892 KB Output is correct
174 Correct 107 ms 23992 KB Output is correct
175 Correct 135 ms 23916 KB Output is correct
176 Correct 100 ms 23740 KB Output is correct