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

Автор 127.0.0.1, история, 3 года назад, По-русски

Спасибо за участие!

Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Разбор задач Codeforces Round 907 (Div. 2)
  • Проголосовать: нравится
  • +116
  • Проголосовать: не нравится

»
3 года назад, скрыть # |
 
Проголосовать: нравится +34 Проголосовать: не нравится

Thanks for the fast editorial!

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

    I am having a little problem in D. Its working on nearly all the test cases and logic is to point. But I think there is some problem with modulus and its giving wrong answer on one test case-v 179 1000000000000000000 Can any body help I cant seem to figure it our. This is my code where maxi is modulus ll l,r; cin>>l>>r;

    ll te=l; ll ans=0; while(te<=r) { ll p=log2(te); ll up; // if(p==63) // up=r; // else up=min((ll)(pow(2,p+1)-1LL),r); //cout<<up<<endl; ll ct=0; ll x=1;

    while(x*p<=te) { x*=p; ++ct; } // cout<<te<<" "<<x<<endl; while(true) { ll nx; //cout<<x*p<<e ndl; x*=p;nx=min(x,up+1); ll nxm=nx%maxi; ll tem=te%maxi; ans=(ans+(ct*((nx-te)%maxi))%maxi)%maxi; if(nx>up) break; ct=(ct+1)%maxi; te=nx; } if(up==r) break; te=up+1;

    } cout<<ans<<endl;

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

Why the approach for F with euler tour+Lazy prop is giving tle on tc 21? here is the code-https://codeforces.me/contest/1891/submission/230589277

any help will be appreciated.

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

I came up with the author's solution F, but I didn't have enough time to debug((

»
3 года назад, скрыть # |
 
Проголосовать: нравится +61 Проголосовать: не нравится

Как автор задачи E, мне жаль, что E и F были не в том порядке.

У вас задачи не в том порядке разложены

»
3 года назад, скрыть # |
 
Проголосовать: нравится +16 Проголосовать: не нравится

F can be solved without reversing the queries. It is offline though.

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

What does the "transition" mean in D?

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

achha contest

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

Прощу прощения, можно ли найти где-то авторский код?

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

In C problem I did as proposed in editorial, but in one test case answers differ. Here is sequence of 14 hits from my implementation:

[1, 1, 2, 5, 6, 6]
=1h small stack=1 0/6
=2h small stack=1 1/6
=4h small stack=2 2/6
=6h big stack=5 4/6
crushing 6/6
=7h -> [3, 6] combo=0
[3, 6]
=10h small stack=3 0/6
crushing 3/6
=11h -> [3] combo=0
1 stack with 3 left. hit by 1
[3]=14h

Can someone provide a sequence to win with just 13 hits?

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

    If you want to stick to this approach, try using std::deque, erase() from the beginning of vector is expensive operation. Or take a look how beautifully contest leaders solved it.

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

Here is an alternative solution for F, using Fenwick Tree.

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

    Same, I think this is more direct.

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

    What's the logic?

    • »
      »
      »
      3 года назад, скрыть # ^ |
      ← Rev. 2  
      Проголосовать: нравится +12 Проголосовать: не нравится

      I believe that my solution 230576374 is the same as in this comment, so I'll describe it.
      Let's build our tree and for each vertex save its creation time and updates with current time and value.
      What is answer for some vertex? It's sum of all requests which were made on this vertex or any of parents LATER than creation time of current vertex. So let's create BIT for sum of requests by time and dfs our tree. We perform updates before getting ans and rollback them before dfs exit thus for each vertex only relevant updates remain:

      dfs(u, p):
          for (time, value) in updates[u]:
              bit.update(time, value)
          ans[u] = bit.get(createdAt[u], n)
          for (int v: g[u]): if v != p:
              dfs(v, u)
          for (time, value) in updates[u]:
              bit.update(time, -value)
      

      Each update is made exactly twice, so it's $$$O((n + q) \log(n))$$$

»
3 года назад, скрыть # |
 
Проголосовать: нравится +108 Проголосовать: не нравится

What was the reasoning for putting problem F at that position?

»
3 года назад, скрыть # |
 
Проголосовать: нравится +21 Проголосовать: не нравится

This is probably the easiest F I've ever seen :(

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

C can be implemented not using two pointers. But during the contest i forgot to check if n == 1 and a[i] == 1 :\

void solve() {
    scanf("%lld", &n);
    int s = 0;
    for (int i = 1; i <= n; i ++) {
        scanf("%lld", &a[i]);
        s += a[i];
    }
    if (n == 1 && a[1] == 1) {
        puts("1");
        return;
    }
    int sp = s / 2;
    sort(a + 1, a + 1 + n);
    int ss = 0, cnt = 0;
    for (int i = n; i >= 1; i --) {
        ss += a[i];
        cnt ++;
        if (ss >= sp){
            break;
        }
    }
    printf("%lld\n", cnt + s - s / 2);
}
»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I have a problem on C . In 230619057 the code id accepted , but in 230619275 , the code is wrong . The only difference between them is merely in "lower_bound(pres,prew+n+1)" or "lower_bound(pres+1,pres+n+1)" . But the pres is the prefix sum of a which indicates that the sum divided by 2 (floor,except for n = 1) must be positive . So "+1" should not make a difference to my solution . I am quite confused . Please help we .

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

Can someone please check out why my submission for Problem D is giving TLE?

Code

Approach: Lets say $$$y = \log_{\log_2(x)}(x)$$$ then the value will remain same till $$$tempR = \min(R, 2^{\log_2(x)+1}-1, \log_2(x)^{y+1}-1)$$$. So I will keep updating answer as $$$ answer += y \cdot (tempR - x + 1)$$$ $$$x = R + 1$$$.

»
3 года назад, скрыть # |
 
Проголосовать: нравится +36 Проголосовать: не нравится

I think swap E and F is a good idea

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

Can someone please tell me why is my submission for Problem D giving TLE?

Code
»
3 года назад, скрыть # |
 
Проголосовать: нравится +2 Проголосовать: не нравится

Mathforces

»
3 года назад, скрыть # |
 
Проголосовать: нравится +13 Проголосовать: не нравится

why is E is much difficult than F. Or why is F much easier than E.

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

Maybe the simplest implementation for C:

sort(a+1,a+1+n);
for(int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
int tmp=(sum[n]+1)/2;
int c=0;
for(int i=1;i<=n;i++) if(sum[i]>tmp) c++;
printf("%lld\n",tmp+c);

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

can anyone explain why the greedy solution works in C? also for the case when i==j and the last number is an odd number and x=0, then there is no way we can use the 2nd method on this horde

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

    It's possible to use 2nd method when there is only 1 horde left with odd size and x = 0.

    For example left horde size = 7 and x = 0 Use 3 attacks of first type. After that horde size = 4 and x = 3. Use second type (ultimate) attack. After that horde size = 1 and x = 0. Use 1 attack of first type. After that horde size = 0.

    So it takes 5 attacks to destroy horde size including second attack. Without second attack it would take 7 attacks.

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

I came up with using offline query in problem F. My idea is first save the query and build the completed tree which is presented in the end. Then, I just need to loop from q to 1 and update normally using Euler's tour when type 2 is meet otherwise if type 1 is the current query, output it's node value. But unfortunately, I got WA immediately at 2nd test case although this idea is kind of nature (or maybe it's wrong in some case), anyone suggests me why am i wrong here?

My submissions: 230648660

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

can anyone help in f...getting wa on 2..230657380

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

#

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

Can someone give a simple idea about F? Also may I know what are the prerequisites to learn to solve problem F?

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

Is there any online solution for F?

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

In problem D

and on each segment there are at most O(logn) transitions

shouldnt there be like at most 2 transitions per segment because if we make 3 transitions that would mean jump to next segment?

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

My logic is similar to one in editorial but I am having issues with MOD. What changes should be done in my code ?

https://codeforces.me/contest/1891/submission/230655160

Also what are some good sources for topics like modular arithmetic and other topics that will help me remain stable expert. Thanks

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

Out of curiosity following problem F , how will this problem be solved? Initially i have only one vertex which is numbered 1.There are 1e5 qeuries where in one type of query i can add a vertex to the tree with number sz+1 (sz is the no of nodes in the tree currently).Can i answer other type of query where i need to tell the size of subtree rooted at a given vertex in logn time or what will be the most optimized algorithm for this.

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

PROBLEM D

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

Here is the implementation of sqrt decomposition for F. It is giving TLE as warned by author. Any optimisation in provided code is welcomed.

»
3 года назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

is there a way to solve problem c with binary search

»
3 года назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Can F be solved online?

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

I think it is better with spoilers, and code.

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

Thank you, 127.0.0.1

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

127.0.0.1 I am having a little problem in D. Its working on nearly all the test cases and logic is to point. But I think there is some problem with modulus and its giving wrong answer on one test case-v 179 1000000000000000000 Can any body help I cant seem to figure it our. This is my code where maxi is modulus ll l,r; cin>>l>>r;

ll te=l;
 ll ans=0;
 while(te<=r)
 {
    ll p=log2(te);
    ll up;
    // if(p==63)
    // up=r;
    // else
    up=min((ll)(pow(2,p+1)-1LL),r);
    //cout<<up<<endl;
    ll ct=0;
    ll x=1;

   while(x*p<=te)
   {
      x*=p;
      ++ct;
   }
  // cout<<te<<" "<<x<<endl;
   while(true)
   {
    ll nx;
    //cout<<x*p<<e ndl;
    x*=p;nx=min(x,up+1);
    ll nxm=nx%maxi;
    ll  tem=te%maxi;
     ans=(ans+(ct*((nx-te)%maxi))%maxi)%maxi;
     if(nx>up)
     break;
     ct=(ct+1)%maxi;
      te=nx;
   }
   if(up==r)
   break;
   te=up+1;



 }
 cout<<ans<<endl;
»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

can someone help me,i am getting WA on test 2 of F https://codeforces.me/contest/1891/submission/232563023

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

I have a problem in D. I got a wrong anwer on test 8, and I have trouble finding where I went wrong. My submission is Your text to link here... . Can someone help me figure out what the problem is? Thanks a lot if you can help!

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

Can anyone please tell me if the error is in the steps of modular operations or in the map in the following solution. It would be a big help. My submission for Problem D

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

Solution to problem F- A Glowing Tree

Click here

If you like my solution please upvote me

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

2nd ques. can be done in less than O(30.N) if we maintain another array for counting the what should be added to the array element if it is divisible by some power of 2.

class Codechef {
public static void main(String[] args) throws IOException {
        Scanner ab = new Scanner(System.in);
        int t = ab.nextInt();
        while(t-- > 0) {
           int N = ab.nextInt();
            int Q = ab.nextInt();
            long[] a = new long[N];
            for(int i=0; i<N; i++) a[i] = ab.nextInt();

           boolean[] flag = new boolean[31];
           int mini = 31;
           for(int i=0; i<Q; i++) {
               int pow = ab.nextInt();
               if(pow < mini) {
                   mini = pow;
                   flag[pow] = true;
               }
           }

           long[] adder = new long[31];
           for(int i=1; i<=30; i++) {
               adder[i] = adder[i-1];
               if(flag[i]) adder[i] += (1<<(i-1));
           }
           for(int i=0; i<N; i++) {
               int pow = log(a[i]);
               a[i] += adder[pow];
           }
           for(int i=0; i<N; i++) System.out.print(a[i] + " ");
           System.out.println();
        }
    }
    static int log(long a) {
        int count = 0;
        while(a % 2 == 0) {
            ++count;
            a = a / 2;
        }
        return count;
    }
}

The time complexity comes out to be O(Q + NlogM), M = 30 at max.

»
20 месяцев назад, скрыть # |
 
Проголосовать: нравится -10 Проголосовать: не нравится

I had to put in more effort to fart than the people did to make this editorial. Its like they did it because its required. Barely explained anything.

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

C can be solved by multiset

Code