Submission #883016

#TimeUsernameProblemLanguageResultExecution timeMemory
883016vjudge1Exhibition (JOI19_ho_t2)C++17
0 / 100
1 ms6492 KiB
/* Author : Mychecksdead */ #include<bits/stdc++.h> using namespace std; #define ll long long int #define MOD (1000000000+7) #define MOD1 (998244353) #define pb push_back #define all(x) x.begin(), x.end() #define en cout << '\n' const int N = 1e6+100, M = 1e5+10, K = 52, MX = 30; int n; pair<int, int> T[N]; ll S[N]; array<ll, 2> a[N]; array<ll, 3> b[N]; void build(int x, int m){ for(int i = 0; i <= 4*x; ++i) T[i] = {0, m+1}; } pair<int, int> get(int l, int r, int p, int k){ if(l == r) return T[k]; int m = l+r>>1; if(p <= m) return max(get(l, m, p, k<<1), T[k]); return max(get(m+1, r, p, k<<1|1) , T[k]); } void update(int l, int r, int ql, int qr, int k, pair<int, int> val){ if(ql > r || l > qr) return; if(ql <= l && r <= qr){ T[k] = max(T[k], val); return; } int m = l+r>>1; update(l, m, ql, qr, k<<1, val); update(m+1, r, ql, qr, k<<1|1, val); } int m; void solve(){ cin >> n >> m; for(int i = 1; i <= n; ++i) cin >> a[i][0] >> a[i][1]; for(int i = 1; i <= n; ++i) b[i][0] = a[i][1], b[i][1] = a[i][0], b[i][2] = i; for(int i = 1; i <= m; ++i) cin >> S[i]; sort(S+1, S+1+m); sort(a+1, a+1+n); sort(b+1, b+1+n); vector<int> val; // for(int i = 1; i <= n; ++i) val.pb(a[i][1]); // sort(all(val)); for(int i = 1; i <= n; ++i) a[b[i][2]][1] = i; build(n, m); for(int i = n; i >= 1; --i){ int pos = lower_bound(S+1,S+1+m,a[i][0]) - S; pair<int, int> dp = get(1, n, a[i][1], 1); if(dp.second - 1 < pos) continue; if(dp.second > 1 && pos >= 1 && a[i][0] <= S[m] && a[i][0] <= S[max(dp.second - 1, pos)]){ // cout << dp.first << '\n'; update(1, n, 1, a[i][1], 1, {dp.first + 1, max(pos, dp.second - 1)}); } } int ans = 0; for(int i = 1; i <= n; ++i) ans = max(ans, get(1, n, i, 1).first); cout << ans; } int main(){ cin.tie(0); ios::sync_with_stdio(0); int tt = 1, aa; // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); while(tt--){ solve(); en; } cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n"; return 0; }

Compilation message (stderr)

joi2019_ho_t2.cpp: In function 'std::pair<int, int> get(int, int, int, int)':
joi2019_ho_t2.cpp:23:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   23 |   int m = l+r>>1;
      |           ~^~
joi2019_ho_t2.cpp: In function 'void update(int, int, int, int, int, std::pair<int, int>)':
joi2019_ho_t2.cpp:33:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   33 |   int m = l+r>>1;
      |           ~^~
joi2019_ho_t2.cpp: In function 'int main()':
joi2019_ho_t2.cpp:70:15: warning: unused variable 'aa' [-Wunused-variable]
   70 |   int tt = 1, aa;
      |               ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...