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

Автор BledDest, история, 7 лет назад, По-русски

Приносим свои извинения за серьёзные неполадки с тестирующей системой в самом начале контеста. Мы надеемся, такого не повторится.

Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Разбор задач Educational Codeforces Round 23
  • Проголосовать: нравится
  • +93
  • Проголосовать: не нравится

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

По поводу задачи B... Можно решить проще: и по памяти, и немного по времени (вроде бы). Можно одним проходом по массиву найти 3 наименьших элемента и их количество, а потом 3-4 условия на то, что выводить (случаи, если наименьшего больше трех раз встретилось, и парочку, если наоборот).

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

    Можно, конечно. По времени то же должно получаться. Решение из разбора разве что объяснять проще.

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

Thanks for fast editorial! :D An easy trick for D: Once you have calculated the sum of minimum in all subarrays, you can just make all the numbers negative ( multiply each of them by -1) and then again calculate the sum of minimum in all subarrays. The sum of maximum will just be the negative of that.

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

C problem also solvable with DP (27810451) works in 183 * 92 * 2.
D problem also solvable with D&C approach(27810683) which works in N * log(N).

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

Альтернативное решение C:

Заметим, что все числа, меньшие s — не действительно большие. Рассмотрим число x >= s. Очевидно, x — сумма_цифр(x) >= x — максимальная_сумма_цифр = x — 9*18 = x — 162. Тогда, если x >= s + 162: x — сумма_цифр(x) >= s + 162 — 162 = s, то есть число действительно большое.

Значит, количество НЕ действительно больших чисел от 1 до n равно:

X = кол(<s) + кол(>=s) = min(s-1, n) + (кол-во не действительно больших чисел на отрезке [s, min(s+161, n)]).

Ответ на задачу равен n — X.

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

There is also another solution for problem C.

Since we know that the maximum value for n is 1018, then the maximum sum of digits we can get is for n = 999999999999999999, which is 162. Using this observation, and the proof mentioned in the editorial, we can be sure that all integers in the interval [s + 162, n] are really big numbers. So, what is left now is to check the interval [s, s + 161] with a simple for-loop.

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

    #include <bits/stdc++.h>

    define ll long long int

    using namespace std;

    int main() {

    ll n,s;
    cin>>n>>s;
    float y=log10(s);
    
    int k=ceil(y);
    if(s==1)
    {
        k=1;
    }
    //cout<<k<<endl;
    if(n<=s)
    {
        cout<<0;
        return 0;
    }
    ll ans=n-s-(9*k);
    ll l=0;
    ans=max(ans,l);
    ll p=(9*k)+s;
    for(ll i=s;i<=p;i++)
    {
        if(i>n)
        {
            break;
        }
        else
        {
            ll h=i;
            ll sum=0;
            while(h!=0)
            {
                sum+=h%10;
                h=h/10;
            }
    
            if((i-sum)>=s)
            {
                ans++;
            }
        }
    }
    cout<<ans;
    return 0;
    

    }

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

    Amazing observation :D

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

Can i know the difficulty difference between an educational round and a normal round.How does difficulty of each problem in Normal round map to educational round?

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

    It's usually like a standard div2 round + one task slightly harder than div2e.

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

      E and D are good so that people can learn something new from the contest. Though they were standard trie and stack questions . I felt they were educational.Hope u introduce more advance concepts and data structures through educational rounds.

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

I did not understand the editorial to problem B. please explain. thanks :)

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

    A very simple approach to problem B: Sort the array containing the numbers. Pick the first three. Now, we can prove that the minimum product will always contain only these three elements and nothing else. Thus, we next count occurrences of these first three letters in the whole sequence. Let the first, second and third numbers be a, b and c. And their repetition in the whole sequence be countA, countB, countC, and let they all be different. Then, ans is countA*countB*countC. But, if b repeats, then b is equal to c (sorted order). Then ans is countA* (ways of choosing 2 elements from countB elements). Similarily if a is repeated two times. Ans is countB only(any other repetition of a will cause it to be equal to c). If all three are same. Then ans is (no. of ways of choosing 3 elements out of countA elements). Here, the no. of ways of choosing 3 elements out of n elements = n*(n-1)*(n-2)/6 Here, the no. of ways of choosing 2 elements out of n elements = n*(n-1)/2

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

      I did the same thing for B, but I keep TLE-ing on test 43. I'm convinced there's some kind of error in the judger or the data, because every other test takes less than 200 ms, including the 100000-length ones. I even bit the bullet and used BufferedReader instead of Scanner...no difference.

      Take a look at my submission. Can you see some weird degenerate case that would cause my solution to not be O(NlongN + N)? I'm going crazy over here!

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

      Can you please explain why the number of ways to choose 3 elements out of n is n*(n-1)*(n-2)/6 ?

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

I am not getting problem A ,I mean why does not (x2-x1)%x==0 and (y2-y1)%y==0 work?Please explain.

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

    it works but you also have to check if it's possible to reach the point doing movements in L. like a horse on chess. It will be reachable if the number of moves performed in the x axis + the number of moves performed in the y axis is even. This happens because when you move, you always do a move in both axis.

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

      but also number of moves in x and y-axis can't be given by (x2 — x1) / x, (y2 — y1) / y because in 0 0 0 6 and x=2,y=3,no of moves in x axis is not(0-0)/2

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

        So what? Yes, it isn't 0, but we only care of the parity of this number and (0 + 0)/2 + (0 + 6)/3 is even, so the answer exists.

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

How to approach a problem like 'B'? I mean how does the right technique strike? Are there any pointers(in the limits or similarity to a classic problem) to the right way? Any help would be appreciated.

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

    Hmm. I don't really know :) I used the approach from the editorial in couple of other problems, though I can't remember any in particular. I guess that if this one doesn't seem intuitive then you can always try the other one. Where you just check some cases on the amount of the elements less than the third minimum of the array. Most people implemented this solution.

    UPD: the author of this task told me that the similar approach is used here

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

      Thanks a lot, awoo.

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

      i would request the author to provide the implementation described in the editorial Thanks for the help awoo Also i have seen many people doing sorting will that not affect the ordering (i<j<k) as described in the question???

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

        ordering will not be affected because if there is 3 indices in sorted array then there will be 3 indices in previous array. Isn't it .

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

        Here it is.

        Reorders will not affect answer. Why should they? You will just take the same triplets but indices in each will be in other order.

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

    I solved it differently. First sort array a. Then take three smallest values, let them be a,b,c in this order. Also, while doing input of array, keep array cnt[x], which tells how many times x appeared in input.

    1. case a!=b!=c Then number of ways is cnt[a] * cnt[b] * cnt[c] (simple combinatorics)
    2. case a == b but b!= c (if b!=c then a!=c as well, because a,b,c are sorted) then there are cnt[a] * (cnt[b] — 1) /2 ways to choose pair (a,a) and cnt[c] to choose c, so to get total multiply these two.
    3. case a != b, b == c Similar to 2. case 4.case a == b == c then answer is cnt[a] * (cnt[b] — 1) * ( cnt[c] — 2) / 6 (again simple combinatorics)

    That covers all cases.

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

      Can you explain how did you get these formulas?

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

        marginal You may see these formulae as "n choose r". If we denote this value with the function c(n,r), c(n,r) = n!/(r!(n-r)!). So here, in case 1: It is simple product-rule of combinatorics case 2: It is c(cnt[a],2) that we need; because that gives us the number of ways to choose a(and hence, b). case 3: Like case 2. case 4: It is c(cnt[a],3). Hope this helps.

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

      True. The condition i<j<k made me think that sorting would be of no help . This is may be because I assumed that a[i]<a[j]<a[k] which is not so. Need to practice more. Thanks

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

Hello, In problem D I don't know why did I get a Wrong answer on test 12. Can you please help me?

27814997

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

How to solve the problem D when imbalance is defined as (max-min)^2 or (max-min)^k with k>=2 in better than O(N^2)?

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

WHat is the movement of

source: 2 -5 destination: -8 8

move: 2 1

. in Problem A ? How this is YES ?

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

Why my MEX queries does not work? Here's my code:

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

aren't NlogN solutions supposed to pass for D ?? Mine got TLE because it uses insert and lower_bound in a set n times ! and I know their complexity is logN http://codeforces.me/contest/817/submission/27808174

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

    I also have the same problem...

    Here is my code.

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

    NlogN solutions were supposed to pass but in your solution the constant factor is large (around 5).

    In your code the complexity is :

    1. Sort — NlogN
    2. First loop — 2*NlogN
    3. Second loop — 2*NlogN

    Overall Complexity — 5*NlogN (Worst Case) = 5*(10^6)*(20) = 10^8.

    And only those O(10^8) solutions pass in 2 sec which are highly optimised. In your case the hidden constant factor of set insertion also affects your code complexity.

    Other NlogN solution which passed : 27810683 by Kerim.K

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

I solved Problem C by searching for the first 'Really Big Number' greater than 's' and less than or equal to n by running a loop.I considered the fact that if a number suppose i=25 doesn't satisfy the 'Really Big Number' condition then no number from 20-29 will satisfy the condition and thus I can jump from i=25 to i=30.By following this, if i found the first valid number less than or equal to n then our answer will be 'n-i+1' otherwise '0'. My question is whether my approach is correct or not because i got accepted but i couldn't proved why my approach is correct. Here is my accepted code.

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

    Your approach is absolutely correct since you have used binary_search.

    As you can observe from the value of num-sumD(num), it is always increasing.

    • For num = 1 to 9 : num-sumd(num) = 0
    • For num = 10 to 19 : num-sumD(num) = 9
    • For num = 20 to 29 : num-sumD(num) = 18
    • .
    • .
    • .
    • For num = 999999999999999990 to 999999999999999999(18 times) : num-sumd(num) = 999999999999999872

    And since the value of num — sumD(num) is strictly non-decreasing, take the lower limit to be 1, higher to be n + 1 and search for the appropriate num such that for values less than num (num — sumd(num)) is less than s and for values greater than or equal to num (num — sumd(num)) is greater than or equal to s.

    So your approach is alright. For more clarification you can see my code : 27802867

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
#include<iostream>
using namespace std;
int main()
{
	long long a,s,q;
	cin>>a>>s;
	if(s%9!=0)
	q=s/9+1;
	else
	q=s/9;
	if (a-10*q>=0)
	cout<<a-10*q+1;
	else
	cout<<"0";
}

I don't know where I went wrong in problem C please help I don't know much about dp and stuff I used the fact that difference of any number and its sum of digits is equal to nearest multiple of 9 of that number.

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

    This is for itachi_2016's approach.

    Try the following test case and you will realize your mistake. 109 91

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

Can anyone help me with sqrt decomposition solution for 817F - MEX Queries (According to editorial its possible).

I can't figure how this approach can be used to solve Problem F.

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

    It's not much different from the segment tree one. Numbers are also compressed and the queries are the same.

    You process assigning on a segment and xor of the segment by dividing original array into sqrt blocks, for each block you maintain its sum. Lazy propagation is used too. Just every query works in instead of .

    We decided not to force participants to use solutions.

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

Similar problem as D are :

http://practice.geeksforgeeks.org/problems/maximum-of-minimum-for-every-window-size/0

http://agc005.contest.atcoder.jp/tasks/agc005_b

Same approach can be use in these problem , next smaller , next greater using stack .

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

Can someone please tell why my code is getting WA ??? Link .Thanks in advance !!!

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

    your code is giving wrong answer because suppose you are standing on a node where xbit=1 and ybit=0 then there xor is 1 and you are adding all the numbers that have that bit zero. but this is wrong because this does not gaurantee all the number in this group to be smaller then your leadership(l).this group till now are only equal, not became less. so you can't add them. if xbit=0 and ybit=1 then your case is correct. there may be case some of these number can latter become equal to or greater than leadership(l). link this is my code you can see . this might help you visualising what i am saying.

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

Problem B In the tutorial "Let's also store set of three elements which give minimal product of the array". In c++ how do you calculate the product if all the numbers are greater than 10^9?

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

Скажите, а что делать, если в задаче Е нет числа p[i] ^ l[i]?

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

Problem B In the tutorial "Let's also store set of three elements which give minimal product of the array". In c++ how do you calculate the product if all the numbers are greater than 10^9?

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

    hi

    we don't calculate product of three numbers

    and question is "how many ways are there to choosing three minimal numbers"

    because minimal numbers give us minimal product

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

There is also one more solution of problem C.

All numbers bigger than s+9*18 and not more than n are really big. So we can check numbers from s to s+9*18 and add max(0, n — s-9*18) to answer. Sorry for my English

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

Problem F in such constraints can also be solved with coordinates compression and bitmasks in obvious way.

BTW, it's fastest solution at this moment. (171 ms without fastIO). 27832302

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

    can you explain your approach . it is diificult to understand from code

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

      Global idea as it is in the editorial:

      The first two types of queries are translated to "assign value 1 or 0 on a segment" (set the number on some position is either present or not). The third is "for each i in segment [l, r] assign xi to xi^1" (this will inverse the segment as described in statement).

      Let's store this array of zeros and ones as bitset, it means that each byte of array will represent 8 values in 8 bit. Then you can perform first two queries on 32 values at once as simple assignment of int variable a[i] = 0 or a[i] = -1, and third query as a[i] = ~a[i]. To find the answer after each query you should find first value in array not equal -1 and find first zero bit index in it.

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

Can anyone explain me D&C solution for D? Because solution with stacks looks awful. I was thinking D&C on contest but couldnt solve it. Edit: got it. this solution helped me http://codeforces.me/contest/817/submission/27832753

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

Detailed approach for D???

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

    Considering finding the sum of minimum values for all subsegments, the solution tries to know for each index i how many times a[i] will be the answer. If x is the number of subsegments that contain index i and a[i] is the minimum value, then ans[i] = x·a[i]. The final answer will be .

    For the correctness of the algorithm, if a subsegment have more than one cell with the same value, we will consider the answer to be the leftmost cell.

    For index i, Let:

    • L[i] be the rightmost index j < i and a[j] ≤ a[i]
    • R[i] be the leftmost index j > i and a[j] < a[i]

    Clearly, All cells in the range [L[i] + 1, i - 1] have values greater than a[i] and all cells in the range [i, R[i] - 1] have values greater than or equal to a[i]. Now, we can say that index i can be the answer to any subsegment whose startpoint is in the range [L[i] + 1, i] and endpoint is in the range [i, R[i] - 1]. So, ans[i] = (i - L[i])·(R[i] - i)

    How to compute the array L? Keep a stack with you and go from left to right. The stack is initially empty and will contain indices. Now, we are at index i:

    • If the stack is empty, L[i] =  - 1.
    • If top of the stack is j and a[j] ≤ a[i], then L[i] = j
    • If top of the stack is j and a[j] > a[i], then pop this element and do the same check for the new stack top.

    If j is popped from the stack, then for k > i, can L[k] = j? The answer is no, because a[j] > a[i] and i is closer to k from j, so if a[i] ≤ a[k], then L[k] = i. Otherwise, a[j] > a[i] > a[k]. That's why we remove j from the stack because it will never be used again.

    After finding L[i], push i onto the stack.

    You can compute the array R in a similar way from right to left.

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

      Shouldn't the L array be calculated on right of i'th element instead of j < i and similarly for R array , If I'm wrong correct me , you are trying to calculate for each i'th element the no of elements which are lesser than a[i] to its left and right (to whatever position we can extend the left and right boundaries )

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

        The objective is to find, for each index i, the closest element to its left side that is not greater than ai, and similarly to the right side.

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

Can any one tell me why we are doing mod 2 in problem A.

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

    hi

    it is difficult to explain but

    if there modes in 2 aren't equal then we can't arrive from x1 to x2 and y1 to y2 in the same time

    and if there modes in 2 are equal then imagine that:

    x2 > x1 and y2 > y1 and (abs(x2 — x1)/a) > (abs(y2 — y1)/b)

    then you can simply do x1 + a, y1 + b and x1 — a, y1 + b k times and you will have

    (abs(x2 — x1)/a) and (abs(y2 — y1) + b*2k)/b

    and you can chose correct k to get (abs(x2 — x1)/a == abs(y2 — y1)/b + 2*k) because their modes in 2 are equals.

    for another cases you can do like this.

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

    if mod 2 is 1, then we can reach target with odd number of moves. Otherwise, we can reach target with even number of moves. So, the parity (odd/even) must be the same for both horizontal and vertical moves.

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

Can anyone explain Problem D?? I read the solution many times but not getting it.

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

Is there an online solution for F ?

I thought of having a sorted set of ranges . Insertion and deletion can be done in O(qlog(q)) amortised time . But I'm not sure how to implement flipping efficiently .

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

    You can use Dynamic Segment Tree.

    I've tried to do it, but got Memory Limit Exceeded. I think my implementation is still not good enough. If you want some idea on how to code, this is my code: 27989735

    I think that I would receive Accepted if memory limit was higher.

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

      Can you please briefly explain your approach.

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

        Imagine that you will solve this problem with a standard segment tree with range update (10^18 nodes and lazy propagation).

        The only thing that change in the dynamic segment tree is that you do not declare an static array with size 4 * 10^18, you just create those nodes that you really need to, because there will not exist 10^18 queries.

        Here is an example, if you do not have any query in range [10^5, 10^10], simply don't create those nodes.

        And if you want to flip some interval [l, r], just do this:

        new_value = (r - l + 1) - previous_value;
        
»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

How is the complexity for B (as per the solution given in editorial) is O(n)? How will you find the 3 smallest no.s in O(n), i.e without sorting( which would take O(nlogn) )?

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

    hi

    you can save 3 smallest numbers in 3 Variable and save their count

    even it isn't necessary to store all numbers.

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

Can someone please tell why my code is getting WA at test 12? Link Thanks in Advance!

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

Anyone there who can help me with my previous post. Please help me. Don't know what is the problem with my code. Why my code gives tle in 43th test case.

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

    I'm not sure but this can probably be Java anti-sort test. Arrays.sort over an array of primitive types uses quicksort and may work in O(n2). Try replacing it either with Collections.sort or with array if Integer values.

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

Что измениться в задаче Е если будет ограничение pi^pj <= l а не pi^pj < l ???

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

I am getting WA on test case 7. Can anyone tell me which case I am missing??? The method I used to solve this problem is almost identical to the editorial... I just put the values L and R+1 in a set and then constructed segment tree from there... Any help is appreciated. :)

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

Chtholly Tree used to solve F: 88862104

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

You can solve the 817B using one traversal instead of two. Simply store the numbers inside a std::map, whose keys are by default sorted ascending. Then there are only a few cases:

Assuming the frequency of the smallest 3 elements are respectively a, b, c:

if a>=3, the answer is comb(a, 3)

if a==2, the answer is b

if a==1 && b==1, the answer is c

if a==1 && b>=2, the answer is comb(b, 2)

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

Don't understand editorial for E, can someone explain it more detailedly?

Thanks a lot in advance.