# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
469244 |
2021-08-31T08:39:50 Z |
AmirrezaM |
LIS (INOI20_lis) |
C++17 |
|
4000 ms |
77324 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define vc vector
#define pb push_back
#define fr first
#define sc second
#define Heh ios::sync_with_stdio(false) , cin.tie(0)
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
const int MAXN = 1e6 + 16 , s = 1 << 20 , sq = 1.5e3 + 15.3;
int n , b[MAXN] , a[MAXN] , it[MAXN] , lis[MAXN] , ans;
set<int> lit[sq];
set<int>::iterator iter;
int segTree[s<<1] , lazy[s<<1];
inline void shift(int v){
segTree[v<<1] += lazy[v];
segTree[(v<<1)^1] += lazy[v];
lazy[v<<1] += lazy[v];
lazy[(v<<1)^1] += lazy[v];
lazy[v] = 0;
}
int get(int v , int tl , int tr){
if(tl == tr) return tl;
shift(v);
int mid = (tl + tr) >> 1;
if(segTree[(v<<1)^1] == 0) return get((v<<1)^1 , mid+1 , tr);
return get((v<<1) , tl , mid);
}
void upd(int v , int tl , int tr , int l , int r , int x){
if(l > tr or r < tl) return;
if(l <= tl and r >= tr){
segTree[v] += x;
lazy[v] += x;
return;
}
shift(v);
int mid = (tl + tr) >> 1;
upd(v<<1 , tl , mid , l , r , x);
upd((v<<1)^1 , mid+1 , tr , l , r , x);
segTree[v] = min(segTree[v<<1] , segTree[(v<<1)^1]);
}
void upd(int id){
set<int>::iterator iter = lit[lis[id]].lower_bound(id);
while(1){
if(iter != lit[lis[id]].end() and a[*iter] > a[id]){
int jd = *iter;
iter++;
lit[lis[id]].erase(jd);
lis[jd]++;
upd(jd);
}
else break;
}
lit[lis[id]].insert(id);
ans = max(ans , lis[id]);
}
int main(){
Heh;
for(int i = 0 ; i < (s<<1) ; i++) segTree[i] = MAXN;
cin >> n;
for(int i = 0 ; i < n ; i++){
int id;
cin >> id >> b[i];
id--;
segTree[s+i] = i-id;
}
for(int i = s-1 ; i >= 1 ; i--){
segTree[i] = min(segTree[i<<1] , segTree[(i<<1)^1]);
}
for(int i = 0 ; i < n ; i++){
int id = get(1 , 0 , s-1);
a[n-i-1] = b[id];
it[id] = n-i-1;
upd(1 , 0 , s-1 , id , n-1 , -1);
upd(1 , 0 , s-1 , id , id , MAXN);
}
for(int i = 0 ; i < n ; i++){
int id = it[i];
lis[id] = 1;
while(1){
iter = lit[lis[id]].lower_bound(id);
if(iter != lit[lis[id]].begin() and a[*(--iter)] < a[id]) lis[id]++;
else break;
}
upd(id);
cout << ans << endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8652 KB |
Output is correct |
2 |
Correct |
6 ms |
8652 KB |
Output is correct |
3 |
Correct |
13 ms |
8780 KB |
Output is correct |
4 |
Correct |
13 ms |
8780 KB |
Output is correct |
5 |
Correct |
24 ms |
8832 KB |
Output is correct |
6 |
Correct |
18 ms |
8744 KB |
Output is correct |
7 |
Correct |
16 ms |
8780 KB |
Output is correct |
8 |
Correct |
15 ms |
8780 KB |
Output is correct |
9 |
Correct |
16 ms |
8780 KB |
Output is correct |
10 |
Correct |
15 ms |
8780 KB |
Output is correct |
11 |
Correct |
17 ms |
8780 KB |
Output is correct |
12 |
Correct |
15 ms |
8816 KB |
Output is correct |
13 |
Correct |
17 ms |
8732 KB |
Output is correct |
14 |
Correct |
17 ms |
8780 KB |
Output is correct |
15 |
Correct |
15 ms |
8784 KB |
Output is correct |
16 |
Correct |
16 ms |
8720 KB |
Output is correct |
17 |
Correct |
17 ms |
8760 KB |
Output is correct |
18 |
Correct |
16 ms |
8780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8652 KB |
Output is correct |
2 |
Correct |
6 ms |
8652 KB |
Output is correct |
3 |
Correct |
13 ms |
8780 KB |
Output is correct |
4 |
Correct |
13 ms |
8780 KB |
Output is correct |
5 |
Correct |
24 ms |
8832 KB |
Output is correct |
6 |
Correct |
18 ms |
8744 KB |
Output is correct |
7 |
Correct |
16 ms |
8780 KB |
Output is correct |
8 |
Correct |
15 ms |
8780 KB |
Output is correct |
9 |
Correct |
16 ms |
8780 KB |
Output is correct |
10 |
Correct |
15 ms |
8780 KB |
Output is correct |
11 |
Correct |
17 ms |
8780 KB |
Output is correct |
12 |
Correct |
15 ms |
8816 KB |
Output is correct |
13 |
Correct |
17 ms |
8732 KB |
Output is correct |
14 |
Correct |
17 ms |
8780 KB |
Output is correct |
15 |
Correct |
15 ms |
8784 KB |
Output is correct |
16 |
Correct |
16 ms |
8720 KB |
Output is correct |
17 |
Correct |
17 ms |
8760 KB |
Output is correct |
18 |
Correct |
16 ms |
8780 KB |
Output is correct |
19 |
Correct |
738 ms |
21848 KB |
Output is correct |
20 |
Correct |
689 ms |
21956 KB |
Output is correct |
21 |
Correct |
775 ms |
21888 KB |
Output is correct |
22 |
Correct |
854 ms |
22016 KB |
Output is correct |
23 |
Correct |
753 ms |
22016 KB |
Output is correct |
24 |
Correct |
751 ms |
22088 KB |
Output is correct |
25 |
Correct |
733 ms |
22020 KB |
Output is correct |
26 |
Correct |
748 ms |
21956 KB |
Output is correct |
27 |
Correct |
745 ms |
21888 KB |
Output is correct |
28 |
Correct |
748 ms |
21996 KB |
Output is correct |
29 |
Correct |
761 ms |
22036 KB |
Output is correct |
30 |
Correct |
742 ms |
21912 KB |
Output is correct |
31 |
Correct |
960 ms |
21932 KB |
Output is correct |
32 |
Correct |
932 ms |
21948 KB |
Output is correct |
33 |
Correct |
903 ms |
21948 KB |
Output is correct |
34 |
Correct |
904 ms |
22016 KB |
Output is correct |
35 |
Correct |
903 ms |
22068 KB |
Output is correct |
36 |
Correct |
910 ms |
21988 KB |
Output is correct |
37 |
Correct |
908 ms |
21924 KB |
Output is correct |
38 |
Correct |
920 ms |
22084 KB |
Output is correct |
39 |
Correct |
917 ms |
21960 KB |
Output is correct |
40 |
Correct |
910 ms |
22020 KB |
Output is correct |
41 |
Correct |
567 ms |
19104 KB |
Output is correct |
42 |
Correct |
103 ms |
10692 KB |
Output is correct |
43 |
Correct |
600 ms |
18964 KB |
Output is correct |
44 |
Correct |
445 ms |
15704 KB |
Output is correct |
45 |
Correct |
60 ms |
9768 KB |
Output is correct |
46 |
Correct |
16 ms |
8780 KB |
Output is correct |
47 |
Correct |
250 ms |
13580 KB |
Output is correct |
48 |
Correct |
182 ms |
12028 KB |
Output is correct |
49 |
Correct |
45 ms |
9384 KB |
Output is correct |
50 |
Correct |
17 ms |
8892 KB |
Output is correct |
51 |
Correct |
158 ms |
11744 KB |
Output is correct |
52 |
Correct |
463 ms |
17352 KB |
Output is correct |
53 |
Correct |
399 ms |
15996 KB |
Output is correct |
54 |
Correct |
338 ms |
15024 KB |
Output is correct |
55 |
Correct |
94 ms |
10172 KB |
Output is correct |
56 |
Correct |
324 ms |
13924 KB |
Output is correct |
57 |
Correct |
139 ms |
11004 KB |
Output is correct |
58 |
Correct |
122 ms |
10824 KB |
Output is correct |
59 |
Correct |
36 ms |
9212 KB |
Output is correct |
60 |
Correct |
485 ms |
16404 KB |
Output is correct |
61 |
Correct |
13 ms |
8780 KB |
Output is correct |
62 |
Correct |
223 ms |
12352 KB |
Output is correct |
63 |
Correct |
117 ms |
10692 KB |
Output is correct |
64 |
Correct |
346 ms |
14404 KB |
Output is correct |
65 |
Correct |
293 ms |
13504 KB |
Output is correct |
66 |
Correct |
80 ms |
10032 KB |
Output is correct |
67 |
Correct |
235 ms |
12596 KB |
Output is correct |
68 |
Correct |
158 ms |
11432 KB |
Output is correct |
69 |
Correct |
299 ms |
13448 KB |
Output is correct |
70 |
Correct |
69 ms |
9732 KB |
Output is correct |
71 |
Execution timed out |
4090 ms |
77324 KB |
Time limit exceeded |
72 |
Halted |
0 ms |
0 KB |
- |