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

Автор GlowCheese, 4 дня назад, По-английски

1993A - Question Marks

Hint
Solution
Code (python)

1993B - Parity and Sum

Hint 1
Hint 2
Solution
Code (python)

1993C - Light Switches

Hint 1
Hint 2
Solution
Code (C++)

1993D - Med-imize

Hint 1
Hint 2
Solution
Code (C++)

1993E - Xor-Grid Problem

Hint 1
Hint 2
Solution
Code (C++)

1993F1 - Dyn-scripted Robot (Easy Version)

Hint 1
Hint 2
General idea (for both F1 and F2)
Solution
Code (C++)

1993F2 - Dyn-scripted Robot (Hard Version)

Solution
Разбор задач Codeforces Round 963 (Div. 2)
  • Проголосовать: нравится
  • +117
  • Проголосовать: не нравится

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

Wow really fast editorial thank you

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

D is cool

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

thanks for fast editorial

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

can someone explain C

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

    Realize that all the chips are activated after the max(a_i). Let's call the interval corresponding to this max time as interval I, and the chip corresponding to it as chip i. So, since the entire pattern of the intervals being on/off is periodic, we know that there is nothing special (i.e. different) that happens later (after interval I). So, we know that, if the intervals all overlap at some point, it will happen in this first occurrence of chip i being on, over interval I. So, we can just maintain the intersection of the ON intervals (within I) across all the chips, using a high and low. If we end the intersection with a valid interval, the answer is the earliest time in that interval, otherwise the answer is no.

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

It's so refreshing to see all the participants solving the contest I'd tested.

Thank you GlowCheese for inviting me to become a tester.

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

Thanks for the Editorial The problems are really fun :D

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

can we use binary search for problem C ? :)

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

    No, it's not a linear function :D

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

    Yes, I used it in my solution

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

      what did you use for the decision making in your binary search approach?

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

        I just found that if the answer exist, all the lights will be turned on somewhere in the range [mx ; mx + k — 1], where mx is the biggest element in the array. So I used binary search to find for each element in the array the nearest minute (z) where at the minute z the current element will be turned on and the range [z ; z + k — 1] is intersect with the range [mx ; mx + k — 1]. and if the intersect exist for all elements then the answer exist and it is the first point of the range resulting from the intersections. I hope this is helpful.

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

          Hey Sandman10,

          How are you ensuring that you are only checking for even numbers, Like ai, ai + 2*k , ai + 4*k, because light will be ON only on even points.

          For doing so we need to do

          for (ll i = 0; i <= 1e9; i += 2) { arr.pb(i); }

          and this will result in MLE.

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

            Exactamento!

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

            u dont need to, since every segments of length k, with the leftmost point congruent to a[i] modulo 2*k, which means u only need to care about the remainder of every a[i], divided by 2*k (and of course, the largest value in the array)

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

          Honestly i feel like its not required. Implementing BS in that is like giving the TC extra logn factor to deal with instead we can just divide the distance from max(a) to a[i] by k and get the range for intersect based in the parity easily. I mean like ur solution is correct and u avoided the mathematical calculations successfully by integrating BS in ur solution but the TC increases by some multiple.

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

Problem C was really funny.. thx :)

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

Really great problems with nice observations, why is the editorial getting downvotes ? Is it because you guys are mad not able to solve the problems ?

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

I enjoyed solving D and E very much :) which is quite rare for a div2 round

Thanks a lot

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

    I think you should have lowered constraints in E though since my and probably many others n^4 2^n did not pass, and the optimization is just boring

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

      $$$O(n^4 2^n)$$$ still passes though as I set the time limit pretty high (5 times how intended solution should run), but you may find some luck to get it AC

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

        Take a look at submissions, you will find a lot of TLEs.

        5x from n^3 2^n doesnt mean it will pass since going purely theoretically, its 15x

        My n^4 * 2^n took 13s on cf custom invo. I removed the factor of n to get it to 1.6s

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

    I'm glad that you liked it :D

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

Wow fast Editorial

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

wish i solved D, but really fun contest nonetheless!

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

algorithm contest -> ❌ math contest -> ✅

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

    It was never supposed to be an algorithm contest, this is a thinking and problem solving contest. Also which problem exactly needed math?

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

      "it was never supposed to be an algorithmic contest"

      what a stupid thing to say

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

      The number of using the word "mod" in the solution was more than the total number of questions.

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

        That is because it can be modeled in mathematical terms and that way the solution is easier to understand, it doesn't mean the solution is math based.

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

          how can you say C is not math?

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

            It's not, in the editorial it is modeled mathematically to be precise. This was my thinking process: If there is a possible time, it will be in the first turned on interval of the maximum $$$a[i]$$$. So i will bring every $$$a[i]$$$ so that it intersects with the maximum $$$a[i]$$$ and update the left and right bound of the answer.

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

        and still some of those can be solved without mod at all. C has mod in editorial but can be solved with a different approach that doesn't require mod

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

          Yes, I use some trick with the brain to solve it without mod 274409368, but still you need some good insight for the problem just to solve it :3

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

            I also had the same approach. Honestly, I couldn't still understand how people could think of a solution involving modulus during the contest itself. Great thinking

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

              Actually, people choose to use modulus is it's better to understanding the problem in that way, and you can prove it's correct while my approach may get hack if there is an edge case :3

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

Thanks for fast editorial!

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

Ah, I should've been able to do B. Don't know where my code went wrong. Anyway, Thanks for the editorial.

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

    in your code, whenever the "if(store < a)" is true, you can just print out the amount of even numbers+1. the solution will always be either 0, the amount of even numbers, or the amount of even numbers+1.

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

      Yes, I understood my mistake. I should've thought of this. Thanks for replying, buddy!

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

Nice Solutions.

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

The solution for F1 (and F2) is really elegant and tricky! I enjoyed (attempting to) solve the problem very much. Hope to see more of such problems.

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

Editorial is high quality. Nice problems too, been a while since I've seen a moving interval one (C).

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

274419542 why i didnt get TL for C task? Its O(n*k)

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

I don’t understand why binary searching works on D They aren’t even checking whether the bs element is present in array or not?

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

Can someone please explain in problem D if I am doing binary search on median and getting that number "mid" should be in middle, how am I even able to check by dp if I can remove segments accordingly, please explain the check function in simpler terms. Thanks in advance!

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

    mid should not be in middle, it should be less than or equal to median. Means we are binary searching on the predicate: f(mid) -> is mid lying to the left of median? and we can do that by counting elements greater than mid, if they are greater than half the size of array, then it will return true.

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

in C, I did linear search in the range max(array)to max(array)+k and got the answer. the check function i used for every numbers in the range is- ~~~~~ function<bool(int)>check=[&](int t){ for(int i=0;i<n;i++){ if((t-v[i])<0||((t-v[i])/k)%2!=0) return false; } return true; }; ~~~~~ can someone explain how these range working, also i think the complexity is O(N*k)??

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

    very weak tests i think, i saw some O(n*k) solution got hacked, so i think that its just really weak tests.

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

E is really a good problem

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

Why, in problem C, the solution with time complexity O(nk) not giving TLE?

I first submitted O(nk) solution (274384802).

Then later, submitted O(n) solution (274394074).

After the system testing, I again submitted my O(nk) solution just to check if it is passing or not, and it got passed. I think the test cases were quite weak for Problem C

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

B- Parity and Sum

can someone please help me understand why my solution was WA on test case 2

C++ solution:

#include<bits/stdc++.h>
using namespace std;
#define ll long long

// Code By VibhuGodson
int main ()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t=1;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        vector<ll>evn;
        ll mxod=-1;
        ll x;
        for(ll i=0;i<n;i++){
            cin>>x;
            if(x%2) mxod=max(mxod,x);
            else evn.push_back(x);
        }
        sort(evn.begin(),evn.end());
        ll ans=0;
        if(evn.size()==0 or evn.size()==n){
            cout<<ans<<endl;
            continue;
        }
        for(auto&i:evn){
            if(i>mxod){
                mxod=2*i+mxod;
                ans+=2;
            }else{
                mxod = i+mxod;
                ans++;
            }
        }
        // cout<<"---------------";
        cout<<ans<<endl;
    }
    return 0;
}

I think the intution is correct, I'm doing the same same thing as per the solution

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

    It's was my first try too. The problem that some times choose the biggest even number from evn, it's better than a smaller one. Because if you take $$$a > b$$$, which is at the end of evn, then you increase mxod and now mxod = mxod + max_elemen(evn), so now mxod is in 100% of cases is greater than any evn and ans += 2 isn't case

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

What is the dp state in the editorial of problem D?

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

As usual, thanks to the authors for this round ! Here is my advice about the problems:

A
B
C
D
E
»
4 часа назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

In Problem D they did not specify that sum of k is less than 5e5, so after I got pretests accepted with O((n + k) * log(1e9)) per testcase solution, I assumed that it whould fail the system test because of the Time Limit. I fixed and resubmited the solution with O(n * log(1e9)) time complexity and it passed the system tests, but it seems like there was not any test case in the system tests that results in a TLE. So if anybody wants to get free hacks for problem D, they can easily construct a testcase where t = 1e4 and n = 1, k = 5e5 for each test case.

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

For D. My solution https://codeforces.com/contest/1993/submission/274431244 is giving RTE on the following test case:

1
1 500000
3169420

But when I am running it locally it is working just fine. Can anyone please help me?

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

I solved C, in a slightly different way

1) If the answer exists it's always going to be from (max(a), max(a)+k-1). (Observation from provided test cases).

2) so we add (2*k*r(some integer) to each element a[i] in place, such that a[i]+2k is just greater than max(a).(2k because in every 2k intervals the light will be on)

3) we need to find two things if(max(a)-min(a)>=k) the answer will be -1, else the answer is max(a).

Solution here: https://codeforces.com/contest/1993/submission/274401978

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

Correct me, if I'm wrong, but shouldn't we choose both n+1th row and m+1th column at the same time to correctly calculate R and C?

I mean, e.g. when calculating C, we need at the same time remove one row (to look for the best solution on n remaining rows) and remove one column (because otherwise distance between rows cannot be calculated correctly). Hence complexity should be somewhat $$$O((n+1)(m+1) \cdot ((m+1)^22^{m+1} + (n+1)^22^{n+1}))$$$ or $$$O(n^42^n)$$$

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

I think the editorial for problem B is for another version of the problem where we can make operations on numbers having the same parity ? You could fix it by just removing the part talking about that x)

Btw it's quite cool that the editorial was writen that much in advance!

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

Guys i have a doubt

https://codeforces.com/contest/1993/submission/274430880

Im getting wrong answer on the above submission

but my other solution (https://codeforces.com/contest/1993/submission/274433114) is getting accepted why? i understand the logic of the 2nd one but whats wrong with my first submission?

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

    Consider test case with n = 3, a = [1, 2, 6]. Your algorithm would first set maxodd to be 1, then it would use 2 operations to turn 1 -> 3 and 2 -> 5, then 2 more operations to turn 5 -> 11 and 6 -> 17. But in an optimal answer you never need to use 2 operations on an even number more than once, so the actual answer is 3 and not 4.

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

    If maxodd is less than v[i], you should add the largest even number to maxodd, instead of v[i]. Adding v[i] may lead to extra operations.

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

There's typo in editorial of D, it should be: $$$b[i]=1$$$ if $$$a[i]≥x$$$ right?

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

Funny thing is: there is a recent video with 3blue1brown which mentioned general idea from F (they called it quite popular but i'm not really into geometry so idk)

With that video in mind it was much easier to think up the solution

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

In problem B you must take numbers such that have distinct parities. So you can remove even + even & odd + odd options from editorial. EDIT: I'm a bit late to tell it first.

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

~~~~~~~~~~~~~~~~~~~ import java.util.*; public class Main{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt();

int []a=new int[n];
      for(int i=0;i<n;i++)
      {
        a[i]=sc.nextInt();
      }
      int count1=0;
      int count2=0;
       int count=0;
      int olarge=0;
      int esmall=Integer.MAX_VALUE;
      Arrays.sort(a);
      int m=0;
      int j=0;
      int max=0;
      for(int i=0;i<n;i++){
    if(a[i]%2==0){
      count1++;
              if (a[i] < esmall) {
        esmall = a[i];
        m = i;
    }
    }
    else{
      count2++;
      olarge=a[i];
         if(max<olarge){
          max=olarge;
          j=i;
    }
    }
      }
      if(count2>0){
          olarge=max;
      }
    if(count1==n || count2==n)
    {
      System.out.println("0");
    }
    else{
      if(olarge>esmall)
      {
        a[m]=max+esmall;
          max=a[m];
          count=count+1;
      }
      else
      {
        a[j]=max+esmall;
        max=a[j];
        a[m]=max+esmall;
        count=count+2;
      }
      for(int k=0;k<n;k++)
      {
        if(a[k]%2==0 && a[k]<a[m])
        {
           a[k]=a[k]+a[m];
           a[m]=a[k];
           count=count+1;
        }
        else if(a[k]%2==0 && a[k]>a[m])
        {
          a[m]=a[k]+a[m];
          a[k]=a[m]+a[k];
          a[m]=a[k];
          count=count+2;
        }
      }
      System.out.println(count);
      }
    }
    }

~~~~~~~~~~~~~~~ can someone please tell me what is wrong in this only the last test case of test case 1 is showing wrong answer

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

GlowCheese

1) why the fuck is not k <= n in problem D, it makes no sense

2) why do tests not have k = max, and 1e4 tests???? How do you miss that in the tests. My solution uses an array of k size and passeed the initial tests https://codeforces.com/contest/1993/submission/274400595

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

Problem D might be my favourite problem ever.

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

    its very common algorithm in Vietnam.If you can do it, your level is equivalent to a fairly good high school student in Vietnam

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

      What's the algorithm called?

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

        its calling binary search on result, that you find the minimal result can be, and the maximum result can be, and binary search on it with a bool check(), remember that the answer must be linear, that is, if one position is satisfied, then the whole in front or behind it must also be satisfied. it is effective for problems that require finding something that is largest or smallest, or the answer involves something that is linear.

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

          I guess binary searching on the result wasn't the tricky part for me, it was more translating the given array into 'b' where 'b[i]' is if the element is greater than the desired median or not.

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

Can anyone help me figure out what the time complexity is for my solution to D?

I used recursion with memoization to solve for the answer. Let the initial size of the array be N. I start with the full array, and using recursion I get the answer for every possible array of size N-K, and so on. I store the maximum answer. I keep doing that until the size of the array is smaller than or equal to K. Then I find the median of the array. I have an map which stores the indices that I have removed.

I'm thinking the time complexity is O(N^2log(n)). My reasoning is that there are ~ N^2 subbarays of different sizes, and the sort takes log(N) time. Is that correct.

This is my code: https://codeforces.com/contest/1993/submission/274435465

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

B Video Editorial : https://youtu.be/xTb58OEZnJM

C Video Editorial : https://youtu.be/6xtmLO43mD4

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

Can anyone please tell me where I am going wrong in this code I am always taking the maximum odd number and updating it whenever required and storing the value in ans variable. 274393002

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

Problem D was cool.

Approached the problems in a million ways. But didn't think in this way.

Was thinking about BS + some sort of greedy

Also thought about some DP

But nice technique of reducing this problem only to a simple dp sum problem.

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

in D it should be x<=a[i],right?

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

Was C that easy? I am unable to find any clue to solve even after seeing the comments and editorial

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

    it wasnt that hard, but also alot of O(n*k) solutions passed for some reason, because of really weak tests.

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

Hello

Can someone help me with my solution for C? I'm getting wrong answer on test 2 on the 2003rd test, so there's an off by one error somewhere. Here's the link to my submission: https://codeforces.com/contest/1993/submission/274445861

I take the time of the light being installed as lowerbound and that time + k as the upperbound, and I set the lowerbound in an array to be +1 and the upperbound as -1 However if the lowerbound to upperbound contains 2k in the middle, then it loops around after the mod, so i set the lowerbound to +1 and the 0th index to +1 and the new upperbound to -1 to account for this loop around Then I add in the array as I go until I find the first index that has the value n (meaning all lights are on at this moment) and at the end I check if index 0 was an answer, then I shift the answer to put it after max(a)

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

why is this code for problem C not giving correct output on codeforces compiler? Link to Submission

while same code gives correct output on my local vscode and also on codechef online c++ compiler

for the 1st test case it is giving correct output as given in the problem

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

I solved C in an another way. As the answer should be at least the maximum number of the array a and every 2k minutes the condition of the light in the apartment is repeated, I decided to build a segment tree, where in each segment of time I save one of three numbers:

0 — means during this segment of time there's no light in the apartment

1 — means during this segment of time all of the lights are on

2 — means during this segment of time some lights are on and some are off

The information in the segment tree is updated by running through the array and performing some mathematical operations. Including that the total time which we are looking through is 2k, the time complexity of the algorithm is O((n + k) * logk).

Code: 274409062