Блог пользователя GlebsHP

Автор GlebsHP, история, 7 лет назад, По-английски
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Разбор задач Codeforces Round 401 (Div. 2)
  • Проголосовать: нравится
  • +70
  • Проголосовать: не нравится

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by GlebsHP (previous revision, new revision, compare).

»
7 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

In the problem C I used a map to store previous queries to pass on the 100th test case. It worked, lol

  • »
    »
    7 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    and main program?Are you using the is_sorted() function in stl?

    upd:sorry I'm bit naive

    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      No, actually I precomputed the answer as said in the problem explanation.But my algorithm runs on O(k*m), Because it checks every column, it's pretty easy to repeat queries just to slow it down. Só I used a map to store previous queries. Here is a link: 24986527.

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Seems distinct queries are very needed

»
7 лет назад, # |
Rev. 3   Проголосовать: нравится +3 Проголосовать: не нравится

There may be a mistake in prob E's solution.

ans[i] += opt[i].height; should be ans[i] += r[i].height;

opt.back() should be opt.top()

Is it right?

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

for problem E can't we use modified longest increasing sub-sequence in O(nlgn) ?

  • »
    »
    7 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    i did something similar to LIS, but in the end it's not so far from the solution proposed above

    #include <cstdio>
    #include <algorithm>
    #include <set>
    using namespace std;
    int II(){int n;scanf("%d",&n);return n;}
    void II(int n){printf("%d\n",n);}
    typedef long long ll;
    void LL(ll n){printf("%lld\n",n);}
    typedef pair<int,ll> il;
    
    struct ring_t {
      int inner,outer,height;
      bool operator<(ring_t b)
      {
        if(b.outer==outer)return inner>b.inner;
        return outer>b.outer;
      }
    };
    
    #define MAXN 100000
    
    ring_t V[MAXN]; ring_t *vend=V;
    
    int main()
    {
      int N=II();
      set<il> dp;
      while(N--)*vend++={II(),II(),II()};
      ll H=0;
      sort(V,vend);
      for(ring_t *x=V;x<vend;x++)
      {
        //printf("adding %d,%d,%d",x->inner,x->outer,x->height);
        ll myH=0;
        {
          auto it=dp.lower_bound({x->outer,-1});
          if(it!=dp.begin())
          {
            it--;
            myH=it->second;
          }
        }
        myH+=x->height;
        H=max(H,myH);
        {
          auto r=dp.insert({x->inner,myH});
          if(r.second)
          {
            auto it=r.first;
            auto prv=it;prv++;
            while(prv!=dp.end()&&it->second>=prv->second)
            {
              dp.erase(prv);
              prv=it;prv++;
            }
          }
        }
        //for(auto y:dp)printf("[%d|%d] ",y.first,y.second);putchar(10);
      }
      LL(H);
    }
    
    
»
7 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

In problem C, should be a[i, j] <= a[i + 1, j] instead of a[i, j] < a[i + 1, j].

»
7 лет назад, # |
  Проголосовать: нравится +19 Проголосовать: не нравится

When CF round #403 begins?

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I see that there is a binary search tag for problem C. Did anyone solve this problem using binary search? Please enlighten me on how to use binary search for this problem.

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    If you just store the indexes which are greater than the next number in an adjacency list for each column. Then for each query you could apply binary search within that range and see if no such element exists even for one column, then Yes. But there seems to be some kind of optimization that I have missed. Plus, the approach is way slower than that in the editorial. This might help

    Please let me know if I'm wrong.

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Here are two submissions for problem D.

26348627

26348633

These two submissions contain exactly the same code. Yet, I didn't use the same compiler. The first one got TLE, and the second one got Accepted. I would be thankful if anybody could explain me why.

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

can someone provide me dp solution for B

»
5 лет назад, # |
  Проголосовать: нравится -7 Проголосовать: не нравится

DDangr coongj sanr vieetj nam muoon nawm >u<

»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Editorial for problem C should be:
* $$$up(i,j) = up(i+1,j)$$$ if $$$a[i][j] \leq a[i+1][j]$$$
* $$$up(i,j) = i$$$, otherwise.
I think it is more suitable with your explanation.

»
4 года назад, # |
Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

I think I got E in O(n log n) time.

  1. Sort rings by outer radius first, then inner radius. Sorting should take O(n log n).

  2. From the end of the array (biggest outer radius), do the below for each ring:

  • If the ring would fall through the ring that is on top of the current stack, get rid of ring on the top of the stack, repeat until fall is no longer detected. Then add the ring to the stack, since you can do so without the ring falling.
  • Keep track of the sum of height of rings in the stack: when adding a ring, add to the sum, when removing from the stack, subtract from the sum.
  • When adding a ring, update the "maxHeight" variable with the current sum of height, that is, maxHeight = max(maxHeight, currentSum), this variable will be the answer by the end.

Knowing that each individual ring can only be added and removed to the stack one time each, this part of the program takes O(n) time.

The whole algorithm thus takes O(n log n + n) = O(n log n) time.

Code: https://codeforces.com/problemset/submission/777/71466945

Feel free to try and prove me wrong.

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Problem E can be solved using Fenwick tree and coordinate compression! First compress the values of a and b. Sort the rings first based on b,then on base of a in decreasing order. Fenwick tree will store the max height account so far till the value 'a'. We start iterating from 0 to n-1, and the for the max value in the fenwick tree till b[i]-1 call it qmax, and update fenwick tree at index a[i] by h[i]+qmax, and max height so far by h[i]+qmax!

»
4 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

I think that the editorial proof of D is unnecessarily involved. We can just prove by induction that at the $$$mth$$$ step, the length of string $$$s_t$$$, $$$t=n-m+1$$$ is maximum as produced by our algorithm. Can anyone prove me wrong?

»
9 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

nice thx