# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
632900 |
2022-08-21T06:14:23 Z |
MohammadAghil |
LIS (INOI20_lis) |
C++17 |
|
4000 ms |
195304 KB |
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
using namespace std;
typedef long long ll;
typedef pair<int, int> pp;
#define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
#define per(i,r,l) for(int i = (r); i >= (l); i--)
#define rep(i,l,r) for(int i = (l); i < (r); i++)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define ss second
#define ff first
void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
void IOS(){
cin.tie(0) -> sync_with_stdio(0);
// #ifndef ONLINE_JUDGE
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
// #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 1e9 + 7, maxn = 2e6 + 5, sq = 2000, lg = 20, inf = ll(1e18) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;}
int fen[maxn], n, pos[maxn], val[maxn], dp[maxn], tmp[maxn];
set<int> val_pos[maxn], place[maxn];
int ptr, stk[maxn], en;
int main(){ IOS();
cin >> n;
stk[0] = -1;
rep(i,1,n+1){
fen[i] = i&-i;
stk[i] = -1;
}
// map<int, int> cmp;
rep(i,0,n){
cin >> pos[i] >> tmp[i];
// cmp[tmp[i]] = 0;
}
// int id = 0;
// for(auto&c: cmp) c.ss = id++;
vector<bool> is(n + 1);
per(i,n-1,0) {
int ps = 0, cr = pos[i];
per(i,lg-1,0){
if((ps|(1<<i)) < n && fen[ps|(1<<i)] < cr){
ps |= 1<<i;
cr -= fen[ps];
}
}
ps++;
// assert(!is[ps]);
is[ps] = true;
// er(nw);
val[ps] = tmp[i];
pos[i] = ps;
for(; ps < n + 1; ps += ps&-ps) fen[ps]--;
}
// rep(i,0,n) er(pos[i], val[i]);
int ans = 1;
rep(i,0,n){
int p = pos[i], v = val[pos[i]];
dp[p] = 1;
rep(j,1,v){
auto it = lower_bound(all(val_pos[j]), p);
if(it != begin(val_pos[j])){
dp[p] = max(dp[p], dp[*prev(it)] + 1);
// er(i, j);
}
}
// er(i, dp[p]);
place[dp[p]].insert(p);
val_pos[v].insert(p);
// auto bg = place[dp[p]].upper_bound(p), en = bg;
// for(; en != end(place[dp[pos[i]]]) && val[*en] > v; en++) dp[*en]++, ans = max(ans, dp[p] + 1), er(i, *en, val[*en], v);
// place[dp[p] + 1].insert(bg, en);
// place[dp[p]].erase(bg, en);
// rep(i,1,5){
// cerr << i << ":" << endl;
// for(int c: place[i]) cerr << c << ' ';
// cerr << endl;
// }
// cerr << "_____" << endl;
// vector<int> stk{p};
stk[en++] = p;
// stk.reserve(100);
while(ptr < en){
int r = stk[ptr]; ptr++;
ans = max(ans, dp[r]);
auto it = place[dp[r]].lower_bound(r);
for(it++; it != end(place[dp[r]]) && val[*it] > val[r];){
dp[*it]++;
stk[en++] = *it;
place[dp[r] + 1].insert(*it);
it++;
place[dp[r]].erase(prev(it));
}
}
cout << ans << '\n';
}
return 0-0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
188136 KB |
Output is correct |
2 |
Correct |
80 ms |
188188 KB |
Output is correct |
3 |
Correct |
105 ms |
188380 KB |
Output is correct |
4 |
Correct |
95 ms |
188412 KB |
Output is correct |
5 |
Correct |
98 ms |
188740 KB |
Output is correct |
6 |
Correct |
102 ms |
188620 KB |
Output is correct |
7 |
Correct |
101 ms |
188512 KB |
Output is correct |
8 |
Correct |
100 ms |
188440 KB |
Output is correct |
9 |
Correct |
102 ms |
188496 KB |
Output is correct |
10 |
Correct |
102 ms |
188452 KB |
Output is correct |
11 |
Correct |
101 ms |
188456 KB |
Output is correct |
12 |
Correct |
101 ms |
188488 KB |
Output is correct |
13 |
Correct |
102 ms |
188492 KB |
Output is correct |
14 |
Correct |
102 ms |
188400 KB |
Output is correct |
15 |
Correct |
101 ms |
188480 KB |
Output is correct |
16 |
Correct |
102 ms |
188484 KB |
Output is correct |
17 |
Correct |
103 ms |
188524 KB |
Output is correct |
18 |
Correct |
102 ms |
188444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
188136 KB |
Output is correct |
2 |
Correct |
80 ms |
188188 KB |
Output is correct |
3 |
Correct |
105 ms |
188380 KB |
Output is correct |
4 |
Correct |
95 ms |
188412 KB |
Output is correct |
5 |
Correct |
98 ms |
188740 KB |
Output is correct |
6 |
Correct |
102 ms |
188620 KB |
Output is correct |
7 |
Correct |
101 ms |
188512 KB |
Output is correct |
8 |
Correct |
100 ms |
188440 KB |
Output is correct |
9 |
Correct |
102 ms |
188496 KB |
Output is correct |
10 |
Correct |
102 ms |
188452 KB |
Output is correct |
11 |
Correct |
101 ms |
188456 KB |
Output is correct |
12 |
Correct |
101 ms |
188488 KB |
Output is correct |
13 |
Correct |
102 ms |
188492 KB |
Output is correct |
14 |
Correct |
102 ms |
188400 KB |
Output is correct |
15 |
Correct |
101 ms |
188480 KB |
Output is correct |
16 |
Correct |
102 ms |
188484 KB |
Output is correct |
17 |
Correct |
103 ms |
188524 KB |
Output is correct |
18 |
Correct |
102 ms |
188444 KB |
Output is correct |
19 |
Execution timed out |
4106 ms |
195304 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |