Advertisement
willy108

half of p1 code

Mar 26th, 2022
1,071
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. zero.reset();
  2.     one.reset();
  3.     //pst zero(m), one(m);
  4.     for(int i = 1; i<=n; i++){
  5.         zero.root[i] = zero.root[i-1];
  6.         one.root[i] = one.root[i-1];
  7.         for(const auto& e : swep[i]){
  8.             if(e.second == 0){
  9.                 zero.update(i, e.first);
  10.             }else{
  11.                 one.update(i, e.first);
  12.             }
  13.         }
  14.     }
  15.     sort(all(srt));
  16.     for(const auto& e : srt){
  17.         if(e.second > 0){
  18.             int i = e.second;
  19.             Union(i, i+1);
  20.         }else{
  21.             int t = find(-e.second);
  22.             int l = lp[t], r = rp[t];
  23.             int ans = 0;
  24.             ans += zero.query(l, e.first, r, 1e9+1);
  25.             ans += one.query(l, 1, r, e.first-1);
  26.             //for(const auto& c : cond){
  27.                 //if(c.first.first < l || c.first.first > r) continue;
  28.                 //if(c.second == 0){
  29.                     //if(c.first.second >= e.first) ans++;
  30.                 //}else{
  31.                     //if(c.first.second < e.first) ans++;
  32.                 //}
  33.             //}
  34.             //cout << l << "  " << r << " " << ans << "\n";
  35.             radj[r].pb(mp(l, ans));
  36.         }
  37.     }
  38.     //so i have intervals made by forcing an operation of type 1
  39.     //then i try to go from 0 -> n using disjoint intervals
  40.     //ideally this gives the right answer
  41.  
  42.  
  43.  
  44.     for(int i = 1; i<=n; i++){
  45.         dp[i] = max(dp[i], dp[i-1] + emp[i]);
  46.         for(const auto& e : radj[i]){
  47.             dp[i] = max(dp[i], dp[e.first-1] + e.second);
  48.         }
  49.     }
  50.     cout << dp[n] << "\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement