Submission #883028

#TimeUsernameProblemLanguageResultExecution timeMemory
883028vjudge1Exhibition (JOI19_ho_t2)C++17
100 / 100
92 ms19088 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){ for(int i = 0; i <= 4*x; ++i) T[i] = {x+1, 0}; } pair<int, int> mx(pair<int, int> x, pair<int, int> y){ swap(x.first, x.second); swap(y.first, y.second); if(max(x, y) == x) return {x.second, x.first}; return {y.second, y.first}; } pair<int, int> get(int l, int r, int ql, int qr, int k){ if(ql > r || l > qr) return {0, 0}; if(ql <= l && r <= qr) return T[k]; int m = l+r>>1; return mx(get(l, m, ql, qr, k<<1), get(m+1, r, ql, qr, k<<1|1)); } void update(int l, int r, int p, int k, pair<int, int> val){ if(l == r){ T[k] = mx(val, T[k]); return; } int m = l+r>>1; if(p <= m) update(l, m ,p, k<<1, val); else update(m+1, r, p, k<<1|1, val); T[k] = mx(T[k<<1], T[k<<1|1]); } int m; void solve(){ cin >> n >> m; for(int i = 1; i <= n; ++i) cin >> a[i][1] >> a[i][0]; 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(m); for(int i = n; i >= 1; --i){ // cout << a[i][0] << ' ' << a[i][1] << '\n'; int pos = lower_bound(S+1, S+1+m, a[i][1]) - S; if(pos>m) continue; pair<int, int> dp = get(1, m, pos, m, 1); // cout << pos << ' ' << dp.first << ' ' << dp.second << '\n'; if(dp.first >= pos + 1){ // cout << "uwu" << '\n'; update(1, m, dp.first - 1, 1, {dp.first - 1, dp.second + 1}); } } int ans = T[1].second; 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, int)':
joi2019_ho_t2.cpp:30:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   30 |   int m = l+r>>1;
      |           ~^~
joi2019_ho_t2.cpp: In function 'void update(int, int, int, int, std::pair<int, int>)':
joi2019_ho_t2.cpp:38:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   38 |   int m = l+r>>1;
      |           ~^~
joi2019_ho_t2.cpp: In function 'int main()':
joi2019_ho_t2.cpp:77:15: warning: unused variable 'aa' [-Wunused-variable]
   77 |   int tt = 1, aa;
      |               ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...