답안 #417382

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
417382 2021-06-03T15:54:07 Z kai824 Event Hopping 2 (JOI21_event2) C++17
100 / 100
213 ms 43152 KB
//persistent segtree with lazy propagation?!?!?!
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mp make_pair
#define eb emplace_back
#define pii pair<int,int>
#define f first
#define s second

int n;
pii vals[100005];
int lef[200005];

int par[200005][18];
void init_sts(int s,int a){//1, a
  int cur=-1;//running max on lef[i]...
  for(int i=1;i<=a;i++){
    cur=max(cur,lef[i]);
    par[i][0]=cur;
  }
  for(int i=1;i<18;i++){
    for(int j=1;j<=a;j++){
      if(par[j][i-1]==-1)par[j][i]=-1;
      else par[j][i]=par[par[j][i-1]][i-1];
    }
  }
}

int qq(int l,int r){
  int ans=0;
  for(int i=17;i>=0;i--){
    if(par[r][i]>=l){
      r=par[r][i];
      ans+=(1<<i);
    }
  }
  return ans;
}

int32_t main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int k,a,b;
  cin>>n>>k;

  vector<pii>disc;//discretisation: raw value, index...
  for(int i=0;i<n;i++){
    cin>>a>>b;
    disc.eb(a,i*2);
    disc.eb(b,i*2+1);
  }
  sort(disc.begin(),disc.end());
  a=1;
  for(int i=0;i<2*n;i++){
    if(i>0 && disc[i].f>disc[i-1].f)a++;
    if(disc[i].s&1)vals[disc[i].s/2].s=a;
    else vals[disc[i].s/2].f=a;
  }
  for(int i=0;i<n;i++){
    //cout<<vals[i].f<<' '<<vals[i].s<<'\n';
    lef[vals[i].s]=max(lef[vals[i].s],vals[i].f);//both should be discretised...
  }
  init_sts(1,a);//initialise segtrees...

  int cur=qq(1,a),tmp;
  if(cur<k){
    cout<<-1;
    return 0;
  }//else cout<<cur<<'\n';
  set<pii> ss;ss.insert(mp(1,1));ss.insert(mp(a,a));
  set<pii>::iterator it,it2;
  bool mk[n];memset(mk,0,sizeof(mk));
  for(int i=0;i<n;i++){
    it=ss.lower_bound(vals[i]);
    it2=it--;
    if(it2==ss.end())continue;
    if(it->s<=vals[i].f && vals[i].s<=it2->f){
      tmp=cur;
      tmp+=1+(qq(it->s,vals[i].f)+qq(vals[i].s,it2->f) ) - qq(it->s,it2->f);
      if(tmp>=k){
        mk[i]=true;
        cur=tmp;
        ss.insert(vals[i]);
      }
    }
  }
  int cnt=0;
  for(int i=0;i<n && cnt<k;i++){
    if(mk[i]){
      cout<<i+1<<'\n';
      cnt++;
    }
  }
  return 0;
}
/*
5 4
1 3
2 5
8 9
6 8
10 15
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 163 ms 41184 KB Output is correct
5 Correct 163 ms 43052 KB Output is correct
6 Correct 166 ms 43052 KB Output is correct
7 Correct 167 ms 42960 KB Output is correct
8 Correct 169 ms 43092 KB Output is correct
9 Correct 161 ms 43132 KB Output is correct
10 Correct 163 ms 43012 KB Output is correct
11 Correct 161 ms 43152 KB Output is correct
12 Correct 137 ms 40640 KB Output is correct
13 Correct 141 ms 40580 KB Output is correct
14 Correct 140 ms 40724 KB Output is correct
15 Correct 138 ms 40568 KB Output is correct
16 Correct 111 ms 37588 KB Output is correct
17 Correct 104 ms 37576 KB Output is correct
18 Correct 107 ms 37552 KB Output is correct
19 Correct 96 ms 36912 KB Output is correct
20 Correct 97 ms 36848 KB Output is correct
21 Correct 99 ms 36800 KB Output is correct
22 Correct 96 ms 36912 KB Output is correct
23 Correct 100 ms 36820 KB Output is correct
24 Correct 94 ms 36840 KB Output is correct
25 Correct 97 ms 36784 KB Output is correct
26 Correct 99 ms 36784 KB Output is correct
27 Correct 98 ms 36804 KB Output is correct
28 Correct 101 ms 36928 KB Output is correct
29 Correct 90 ms 36808 KB Output is correct
30 Correct 90 ms 36784 KB Output is correct
31 Correct 92 ms 36788 KB Output is correct
32 Correct 96 ms 36788 KB Output is correct
33 Correct 98 ms 36780 KB Output is correct
34 Correct 138 ms 40492 KB Output is correct
35 Correct 138 ms 40404 KB Output is correct
36 Correct 136 ms 40308 KB Output is correct
37 Correct 130 ms 40116 KB Output is correct
38 Correct 132 ms 40172 KB Output is correct
39 Correct 130 ms 40128 KB Output is correct
40 Correct 130 ms 40156 KB Output is correct
41 Correct 131 ms 40120 KB Output is correct
42 Correct 100 ms 36784 KB Output is correct
43 Correct 143 ms 40120 KB Output is correct
44 Correct 142 ms 39860 KB Output is correct
45 Correct 138 ms 39796 KB Output is correct
46 Correct 139 ms 39552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 268 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 0 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 0 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 268 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 0 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 0 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 3 ms 1484 KB Output is correct
29 Correct 3 ms 1484 KB Output is correct
30 Correct 3 ms 1484 KB Output is correct
31 Correct 3 ms 1484 KB Output is correct
32 Correct 3 ms 1484 KB Output is correct
33 Correct 2 ms 1484 KB Output is correct
34 Correct 2 ms 1484 KB Output is correct
35 Correct 4 ms 1504 KB Output is correct
36 Correct 4 ms 1484 KB Output is correct
37 Correct 4 ms 1500 KB Output is correct
38 Correct 2 ms 1484 KB Output is correct
39 Correct 4 ms 1484 KB Output is correct
40 Correct 5 ms 1484 KB Output is correct
41 Correct 4 ms 1484 KB Output is correct
42 Correct 2 ms 1484 KB Output is correct
43 Correct 3 ms 1484 KB Output is correct
44 Correct 3 ms 1484 KB Output is correct
45 Correct 3 ms 1484 KB Output is correct
46 Correct 2 ms 1484 KB Output is correct
47 Correct 3 ms 1484 KB Output is correct
48 Correct 3 ms 1484 KB Output is correct
49 Correct 3 ms 1484 KB Output is correct
50 Correct 3 ms 1484 KB Output is correct
51 Correct 3 ms 1484 KB Output is correct
52 Correct 3 ms 1484 KB Output is correct
53 Correct 3 ms 1484 KB Output is correct
54 Correct 2 ms 1484 KB Output is correct
55 Correct 4 ms 1100 KB Output is correct
56 Correct 3 ms 1080 KB Output is correct
57 Correct 3 ms 1100 KB Output is correct
58 Correct 3 ms 1100 KB Output is correct
59 Correct 4 ms 1100 KB Output is correct
60 Correct 3 ms 1100 KB Output is correct
61 Correct 3 ms 1100 KB Output is correct
62 Correct 3 ms 1100 KB Output is correct
63 Correct 3 ms 1100 KB Output is correct
64 Correct 2 ms 972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 163 ms 41184 KB Output is correct
5 Correct 163 ms 43052 KB Output is correct
6 Correct 166 ms 43052 KB Output is correct
7 Correct 167 ms 42960 KB Output is correct
8 Correct 169 ms 43092 KB Output is correct
9 Correct 161 ms 43132 KB Output is correct
10 Correct 163 ms 43012 KB Output is correct
11 Correct 161 ms 43152 KB Output is correct
12 Correct 137 ms 40640 KB Output is correct
13 Correct 141 ms 40580 KB Output is correct
14 Correct 140 ms 40724 KB Output is correct
15 Correct 138 ms 40568 KB Output is correct
16 Correct 111 ms 37588 KB Output is correct
17 Correct 104 ms 37576 KB Output is correct
18 Correct 107 ms 37552 KB Output is correct
19 Correct 96 ms 36912 KB Output is correct
20 Correct 97 ms 36848 KB Output is correct
21 Correct 99 ms 36800 KB Output is correct
22 Correct 96 ms 36912 KB Output is correct
23 Correct 100 ms 36820 KB Output is correct
24 Correct 94 ms 36840 KB Output is correct
25 Correct 97 ms 36784 KB Output is correct
26 Correct 99 ms 36784 KB Output is correct
27 Correct 98 ms 36804 KB Output is correct
28 Correct 101 ms 36928 KB Output is correct
29 Correct 90 ms 36808 KB Output is correct
30 Correct 90 ms 36784 KB Output is correct
31 Correct 92 ms 36788 KB Output is correct
32 Correct 96 ms 36788 KB Output is correct
33 Correct 98 ms 36780 KB Output is correct
34 Correct 138 ms 40492 KB Output is correct
35 Correct 138 ms 40404 KB Output is correct
36 Correct 136 ms 40308 KB Output is correct
37 Correct 130 ms 40116 KB Output is correct
38 Correct 132 ms 40172 KB Output is correct
39 Correct 130 ms 40128 KB Output is correct
40 Correct 130 ms 40156 KB Output is correct
41 Correct 131 ms 40120 KB Output is correct
42 Correct 100 ms 36784 KB Output is correct
43 Correct 143 ms 40120 KB Output is correct
44 Correct 142 ms 39860 KB Output is correct
45 Correct 138 ms 39796 KB Output is correct
46 Correct 139 ms 39552 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 1 ms 332 KB Output is correct
50 Correct 0 ms 332 KB Output is correct
51 Correct 0 ms 332 KB Output is correct
52 Correct 1 ms 332 KB Output is correct
53 Correct 0 ms 332 KB Output is correct
54 Correct 1 ms 332 KB Output is correct
55 Correct 1 ms 268 KB Output is correct
56 Correct 0 ms 332 KB Output is correct
57 Correct 0 ms 332 KB Output is correct
58 Correct 0 ms 332 KB Output is correct
59 Correct 0 ms 332 KB Output is correct
60 Correct 0 ms 332 KB Output is correct
61 Correct 0 ms 332 KB Output is correct
62 Correct 0 ms 332 KB Output is correct
63 Correct 1 ms 332 KB Output is correct
64 Correct 1 ms 332 KB Output is correct
65 Correct 0 ms 332 KB Output is correct
66 Correct 0 ms 332 KB Output is correct
67 Correct 0 ms 332 KB Output is correct
68 Correct 1 ms 332 KB Output is correct
69 Correct 0 ms 332 KB Output is correct
70 Correct 1 ms 332 KB Output is correct
71 Correct 0 ms 332 KB Output is correct
72 Correct 0 ms 332 KB Output is correct
73 Correct 1 ms 332 KB Output is correct
74 Correct 3 ms 1484 KB Output is correct
75 Correct 3 ms 1484 KB Output is correct
76 Correct 3 ms 1484 KB Output is correct
77 Correct 3 ms 1484 KB Output is correct
78 Correct 3 ms 1484 KB Output is correct
79 Correct 2 ms 1484 KB Output is correct
80 Correct 2 ms 1484 KB Output is correct
81 Correct 4 ms 1504 KB Output is correct
82 Correct 4 ms 1484 KB Output is correct
83 Correct 4 ms 1500 KB Output is correct
84 Correct 2 ms 1484 KB Output is correct
85 Correct 4 ms 1484 KB Output is correct
86 Correct 5 ms 1484 KB Output is correct
87 Correct 4 ms 1484 KB Output is correct
88 Correct 2 ms 1484 KB Output is correct
89 Correct 3 ms 1484 KB Output is correct
90 Correct 3 ms 1484 KB Output is correct
91 Correct 3 ms 1484 KB Output is correct
92 Correct 2 ms 1484 KB Output is correct
93 Correct 3 ms 1484 KB Output is correct
94 Correct 3 ms 1484 KB Output is correct
95 Correct 3 ms 1484 KB Output is correct
96 Correct 3 ms 1484 KB Output is correct
97 Correct 3 ms 1484 KB Output is correct
98 Correct 3 ms 1484 KB Output is correct
99 Correct 3 ms 1484 KB Output is correct
100 Correct 2 ms 1484 KB Output is correct
101 Correct 4 ms 1100 KB Output is correct
102 Correct 3 ms 1080 KB Output is correct
103 Correct 3 ms 1100 KB Output is correct
104 Correct 3 ms 1100 KB Output is correct
105 Correct 4 ms 1100 KB Output is correct
106 Correct 3 ms 1100 KB Output is correct
107 Correct 3 ms 1100 KB Output is correct
108 Correct 3 ms 1100 KB Output is correct
109 Correct 3 ms 1100 KB Output is correct
110 Correct 2 ms 972 KB Output is correct
111 Correct 111 ms 36884 KB Output is correct
112 Correct 118 ms 37008 KB Output is correct
113 Correct 107 ms 36816 KB Output is correct
114 Correct 108 ms 36884 KB Output is correct
115 Correct 115 ms 36848 KB Output is correct
116 Correct 114 ms 36816 KB Output is correct
117 Correct 113 ms 36720 KB Output is correct
118 Correct 213 ms 43136 KB Output is correct
119 Correct 207 ms 43064 KB Output is correct
120 Correct 166 ms 40584 KB Output is correct
121 Correct 98 ms 36744 KB Output is correct
122 Correct 177 ms 40712 KB Output is correct
123 Correct 170 ms 40484 KB Output is correct
124 Correct 180 ms 40488 KB Output is correct
125 Correct 102 ms 36784 KB Output is correct
126 Correct 131 ms 37588 KB Output is correct
127 Correct 128 ms 37508 KB Output is correct
128 Correct 122 ms 37424 KB Output is correct
129 Correct 103 ms 36716 KB Output is correct
130 Correct 116 ms 37040 KB Output is correct
131 Correct 114 ms 36908 KB Output is correct
132 Correct 118 ms 36808 KB Output is correct
133 Correct 115 ms 36824 KB Output is correct
134 Correct 113 ms 36908 KB Output is correct
135 Correct 113 ms 36884 KB Output is correct
136 Correct 115 ms 36876 KB Output is correct
137 Correct 116 ms 36752 KB Output is correct
138 Correct 114 ms 36840 KB Output is correct
139 Correct 111 ms 36776 KB Output is correct
140 Correct 109 ms 36784 KB Output is correct
141 Correct 102 ms 36656 KB Output is correct
142 Correct 155 ms 28692 KB Output is correct
143 Correct 149 ms 28724 KB Output is correct
144 Correct 149 ms 28664 KB Output is correct
145 Correct 124 ms 28848 KB Output is correct
146 Correct 122 ms 28824 KB Output is correct
147 Correct 121 ms 28720 KB Output is correct
148 Correct 124 ms 28732 KB Output is correct
149 Correct 118 ms 28748 KB Output is correct
150 Correct 120 ms 28732 KB Output is correct
151 Correct 120 ms 28720 KB Output is correct
152 Correct 63 ms 22036 KB Output is correct
153 Correct 124 ms 28852 KB Output is correct
154 Correct 124 ms 28712 KB Output is correct
155 Correct 124 ms 28848 KB Output is correct
156 Correct 119 ms 28688 KB Output is correct
157 Correct 126 ms 28748 KB Output is correct
158 Correct 127 ms 28648 KB Output is correct
159 Correct 125 ms 28640 KB Output is correct
160 Correct 72 ms 21948 KB Output is correct
161 Correct 167 ms 32728 KB Output is correct
162 Correct 174 ms 32764 KB Output is correct
163 Correct 162 ms 32720 KB Output is correct
164 Correct 173 ms 32720 KB Output is correct
165 Correct 165 ms 32704 KB Output is correct
166 Correct 92 ms 36788 KB Output is correct
167 Correct 140 ms 40032 KB Output is correct
168 Correct 147 ms 39832 KB Output is correct
169 Correct 132 ms 39740 KB Output is correct
170 Correct 130 ms 39608 KB Output is correct
171 Correct 126 ms 39576 KB Output is correct
172 Correct 155 ms 40232 KB Output is correct
173 Correct 148 ms 25292 KB Output is correct
174 Correct 169 ms 25292 KB Output is correct
175 Correct 150 ms 25164 KB Output is correct
176 Correct 132 ms 24880 KB Output is correct