Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- zero.reset();
- one.reset();
- //pst zero(m), one(m);
- for(int i = 1; i<=n; i++){
- zero.root[i] = zero.root[i-1];
- one.root[i] = one.root[i-1];
- for(const auto& e : swep[i]){
- if(e.second == 0){
- zero.update(i, e.first);
- }else{
- one.update(i, e.first);
- }
- }
- }
- sort(all(srt));
- for(const auto& e : srt){
- if(e.second > 0){
- int i = e.second;
- Union(i, i+1);
- }else{
- int t = find(-e.second);
- int l = lp[t], r = rp[t];
- int ans = 0;
- ans += zero.query(l, e.first, r, 1e9+1);
- ans += one.query(l, 1, r, e.first-1);
- //for(const auto& c : cond){
- //if(c.first.first < l || c.first.first > r) continue;
- //if(c.second == 0){
- //if(c.first.second >= e.first) ans++;
- //}else{
- //if(c.first.second < e.first) ans++;
- //}
- //}
- //cout << l << " " << r << " " << ans << "\n";
- radj[r].pb(mp(l, ans));
- }
- }
- //so i have intervals made by forcing an operation of type 1
- //then i try to go from 0 -> n using disjoint intervals
- //ideally this gives the right answer
- for(int i = 1; i<=n; i++){
- dp[i] = max(dp[i], dp[i-1] + emp[i]);
- for(const auto& e : radj[i]){
- dp[i] = max(dp[i], dp[e.first-1] + e.second);
- }
- }
- cout << dp[n] << "\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement