ACGN's blog

By ACGN, history, 106 minutes ago, In English
A little backstory about the round (ACGN)

2031A - Penchick and Modern Monument

Idea: pwned
Preparation: HappyPacMan

Hint 1
Hint 2
Solution
Feedback

2031B - Penchick and Satay Sticks

Idea: ACGN
Preparation: HappyPacMan

Hint 1
Hint 2
Solution
Feedback

2031C - Penchick and BBQ Buns

Idea & preparation: ACGN

Hint 1
Hint 2
Solution
Feedback

2031D - Penchick and Desert Rabbit

Idea: AverageDiv1Enjoyer
Preparation: HappyPacMan

Hint 1
Hint 2
Solution
Feedback

2031E - Penchick and Chloe's Trees

Idea & preparation: ACGN

Hint 1
Hint 2
Solution
About Problem E
Feedback

2031F - Penchick and Even Medians

Idea: trunkty
Solution & preparation: maomao90

Hint 1
Hint 2
Solution 1
Solution 2
Solution 3
Challenge
Feedback

Round statistics

Fastest submission among all participants, and among rated participants:
A: tourist at 00:00:43, priyanshu.p at 00:00:56
B: tourist at 00:01:57, arnabmanna at 00:02:10
C: arvindf232 at 00:06:22, boboquack at 00:11:42
D: _Duck_Dot_Dot_Happy at 00:10:50
E: fzx at 00:11:27, Jack.YT at 00:20:38
F: peti1234 at 00:34:01, waiting_for_the_sunset at 00:54:34

More round statistics to be updated!

That's it for this round, and we hope you had fun with all the problems!

A few serious words from ACGN - about problemsetting, MathForces, and more
and from my own heart...

  • Vote: I like it
  • +80
  • Vote: I do not like it

»
103 minutes ago, # |
  Vote: I like it +11 Vote: I do not like it

wow,the tutorial comes so fast!

  • »
    »
    101 minute(s) ago, # ^ |
      Vote: I like it +2 Vote: I do not like it

    like a wind :)

»
103 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

hint 1 for D is missing

»
102 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

great contest c is quite interesting

»
102 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

Why the hints of D starts from Hint 2? By the way, good C&D.

  • »
    »
    101 minute(s) ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    numbering issue, sorry and has been fixed

»
101 minute(s) ago, # |
  Vote: I like it 0 Vote: I do not like it

why my code for C got wrong answer?

  • »
    »
    100 minutes ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    the $$$1$$$s at indices $$$1$$$ and $$$9$$$ are separated by a distance of $$$8$$$, which isn't a square.

  • »
    »
    100 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    dist b/w first 1 and last 1 is not a perfect square

»
101 minute(s) ago, # |
  Vote: I like it +1 Vote: I do not like it

superfast editorial

»
100 minutes ago, # |
  Vote: I like it +6 Vote: I do not like it

C was great. The Pythagorean triples idea is so elegant.

  • »
    »
    99 minutes ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    thanks, it was my favorite problem!

»
100 minutes ago, # |
Rev. 2   Vote: I like it +7 Vote: I do not like it

Nice trick on C. Instead of creating this array

1 3 3 4 4 5 5 6 6 1 2 7 7 8 8 9 9 10 10 11 11 12 12 13 13 1 2

I create this

1 2 2 3 3 4 4 5 5 1 6 6 7 7 8 8 9 9 10 10 11 11 12 13 13 1 12

  • »
    »
    93 minutes ago, # ^ |
      Vote: I like it +2 Vote: I do not like it

    That's the construction some of the testers used; there are many ways to construct a suitable array.

  • »
    »
    82 minutes ago, # ^ |
    Rev. 2   Vote: I like it +1 Vote: I do not like it

    Same as mine, but to figure out that odd number still exists a way, that literally took me a while.

  • »
    »
    14 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    another way $$$x=1e6$$$

    x 1 2 3 4 5 6 7 8 x 12 11 11 13 13 14 14 1 2 3 4 5 6 7 8 x 12

»
98 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

1,12,13,13,11,12,10,9,11,8,10,7,9,8,6,7,1,5,6,4,3,5,2,4,3,1,2 can this be a sequence for first 27 element in question c?

»
97 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

the fastest tutorial ever!

»
96 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

[1, 2, 3, 3, 1, 2, 4, 4, 1] is sollution for 9 which is less then 25 for problem C

distance is 1 for 3, 4 and 4 for 1, 2

  • »
    »
    94 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    this is wrong, the first and last 1 have a distance of 8.

  • »
    »
    94 minutes ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    distance between 1s at indices 1 and 9 is 8 which is not perfect square

  • »
    »
    93 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    No , 9 — 1 is 8 which is not a perfect square

»
96 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

A caught me off guard wtf

»
95 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

I find I always make problem more complex, like this div.2 D. I spent 30mins to solve ABC, but can't wock out D. What should I do to avoid??

  • »
    »
    92 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    What algorithm you think it should be applied in D?

    • »
      »
      »
      86 minutes ago, # ^ |
        Vote: I like it +1 Vote: I do not like it

      I preprocessed out the position of the largest number and sorted it by numerical size and position. Then use a monotonic stack to maintain a suffixed minimum value from back to front. When I want to compute the answer, find the position of this minimum and find the answer before it. The time complexity is $$$O(n\log{n})$$$ because I need to make a binary search inside the stack to find this rearmost minimum.

      • »
        »
        »
        »
        78 minutes ago, # ^ |
        Rev. 3   Vote: I like it +3 Vote: I do not like it

        At first, I thought the same thing however I notice that I can create mountains (*mountain is an decreasing array), so a mountain will have a peak (the largest value) and a down (the smallest value).

        For example: 2 4 1 6 3 8 5 7 -> (2), (4, 1), (6, 3), (8, 5), (7)

        And then I save the largest and smallest of each mountain

        (2), (4, 1), (6, 3), (8, 5), (7) -> (2, 2), (4, 1), (6, 3), (8, 5), (7, 7)

        Here's another example 2 5 3 1 6 2 10 9 8 -> (2), (5, 3, 1), (6, 2), (10, 9, 8)

        Then (2), (5, 3, 1), (6, 2), (10, 9, 8) -> (2, 2), (5, 1), (6, 2), (10, 8)

        And I notice that if there exist 2 mountains i and j so that i.peak > j.down then the rabbit can jump from mountain i to mountain j. I sort these mountains with the peak decreasing and I find out that the problem now looks like a graph (more like DSU).

        Here's my solution 291628412

      • »
        »
        »
        »
        43 minutes ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        I use this algorithm too!

»
94 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

Can D be solved with dsu?

  • »
    »
    55 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Yep. For each point, merge it with the point to the left of this point and with the highest height, and also merge it with the point to the right that is farthest away from it and with a height smaller than it. It can be shown that this merging is optimal.

    • »
      »
      »
      a moment ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      How do you keep track of highest height to the left and the points which are farthest away with a height smaller than it?

»
93 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

so why my code for D is wrong?

#include <bits/stdc++.h>
#define for1(i,a,b) for( int (i)=(a); (i)<=(b); ++(i))
#define for2(i,a,b) for( int (i)=(a); (i)>=(b); --(i))
#define madd(a,b) (a)=((a)+(b)+mod)%mod
#define fi first
#define se second
#define p_f push_front
#define p_b push_back
#define o_f pop_front
#define o_b pop_back
#define int long long
using namespace std;
typedef pair<int,int> P;
typedef long long LL;
typedef unsigned long long ULL;
const int mod = 10007;
const int N = 105;
const int M = 105;
const int IINF = 0x3f3f3f3f;
const LL LINF = 1e18;
int T;
int n;
int a[500005];
int b[500005];
int Log[500005];
int f[500005][30];
int ans[500005];
int fm(int l,int r){
	int d=r-l+1;
	int x=Log[d];
	return max(f[l][x],f[r-(1<<x)+1][x]);
}
signed main(){
	time_t start=clock();
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	Log[1]=0;
	for(int i=2;i<=500000;i++)
		Log[i]=Log[(i>>1)]+1;
	cin>>T;
	while(T--){
		cin>>n;
		for1(i,1,n) ans[i]=b[i]=0;
		for1(i,1,n){
			cin>>a[i];
			ans[i]=a[i];
			b[a[i]+1]=i;
			f[i][0]=a[i];
		}
		for1(i,1,n) b[i]=max(b[i],b[i-1]);
		for(int len=1;len<=Log[n];len++)
			for(int i=1;i<=n;i++){
				int j=i+(1<<len)-1;
				if(j>n) break;
				f[i][len]=max(f[i][len-1],f[i+(1<<len-1)][len-1]);
			}
		ans[n]=max(ans[n],fm(1,n));
		for2(i,n-1,1)
			ans[i]=max(ans[i],max(ans[max(fm(1,i),fm(1,b[a[i]]))],max(fm(1,i),fm(1,b[a[i]]))));
		for1(i,1,n) cout<<max(a[i],ans[i])<<" ";
		cout<<"\n";
	}
	time_t duration=clock()-start;
	cerr<<"\ntime="<<duration;
    return 0;
}
»
91 minute(s) ago, # |
  Vote: I like it +28 Vote: I do not like it

Lmaooooo I already knew that tons would vote "Bad Problem" in the feedback for C. This community can be so predictable at times.

C is an EXCELLENT problem, yall are just haters

  • »
    »
    90 minutes ago, # ^ |
      Vote: I like it +2 Vote: I do not like it

    Yes, many of them don't think about the odd amount of elements can have a solution

  • »
    »
    89 minutes ago, # ^ |
      Vote: I like it +2 Vote: I do not like it

    So true bestie

  • »
    »
    83 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    What is the purpose of samples in such problems? They always must have funny non generalizable construction.

    • »
      »
      »
      77 minutes ago, # ^ |
        Vote: I like it +6 Vote: I do not like it

      Well of course it has to be non-generalizable, otherwise it would spoil the problem haha

      Regardless, it does still serve the following purposes:

      • Showcases the output format
      • Allows you to verify ("sanity check") that your understanding of the problem is correct, since you can verify the given definition on a concrete example.

      For example in this problem, what does |i — j| = a perfect square mean? Should it be the 1st and 9th buns that match, or the 1st and 10th? We know it should be 1 and 10, but it's a reasonable misunderstanding to make, especially in the heat of a contest.

      But the answer is easily, totally unambiguous because you can very easily just check the sample output to see which interpretation is correct.

»
90 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

Typo: In Problem F Solution 1 Part 1 line 2: and the other is strictly larger than $$$\frac n2$$$ -> larger than $$$\frac n2 +1$$$.

»
87 minutes ago, # |
  Vote: I like it +3 Vote: I do not like it

if you know Pythagoras theorem,you can solve C easily

»
86 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

Penguins! A very nice contest :D

»
86 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

Though I stuck on C for nearly an hour(because of my poor math), I still think C is a beautiful problem conbined maths and constructive algorithms excellently. This is the best problem in this type I've ever met.

»
86 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

Can someone point out the mistake —

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin>>n;
        int count=0;
        vector<int>arr(n);
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        for(int i=0;i<n-1;i++){
            if(arr[i]>arr[i+1]) count++;
        }
        cout<<count<<endl;
    }
    return 0;
}
»
82 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

I couldn't solve A and B. My penchick is getting skinny

»
82 minutes ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

For C, isn't [1, 2, 2, 4, 4, 5, 5, 3, 6, 1, 7, 7, 6, 1, 9, 9, 3] for 17?

  • »
    »
    81 minute(s) ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    No, the first 1 and the last 1's distance is not a perfect square (13).

  • »
    »
    80 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    the $$$1$$$s at indices $$$1$$$ and $$$14$$$ differ by $$$13$$$, which is not a square.

  • »
    »
    80 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    dist between first 1 and last 1 is 13

»
75 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

Thanks for the fast editorial. Elegant problemsetting for C, now I learn.

»
74 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

What's wrong with this case for n=27 in Problem C? 13 1 2 2 3 3 4 4 5 5 1 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 1

  • »
    »
    65 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    distance between your 2 first 1s is 8

    you werw so close though that is the idea. but it's the even length you need to pad

    • »
      »
      »
      60 minutes ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      No, I think its 9 only, 1s are on 1st and 10th index in the case you're mentioning.

      So actually, I have put 1's on index 1, 10, 26 13s on index 0 and 25 Rest I just generated.

      • »
        »
        »
        »
        39 minutes ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Oh yeah mb. Checked your last submit you're printing "13 1 \n" in the end arent you ? Maybe thats the issue ?

        • »
          »
          »
          »
          »
          36 minutes ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Got this: wrong answer Color 1 used only once (test case 1), but don't know which test case it could be on.

          • »
            »
            »
            »
            »
            »
            33 minutes ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            ans for n=1 is -1. no filings can be used a single time so n=1 has no valid answer.

            • »
              »
              »
              »
              »
              »
              »
              31 minute(s) ago, # ^ |
                Vote: I like it 0 Vote: I do not like it

              Ohh man...crying myself to sleep. :((....Thanks dude!!

              • »
                »
                »
                »
                »
                »
                »
                »
                12 minutes ago, # ^ |
                  Vote: I like it 0 Vote: I do not like it

                Dont ! Double checking minor mistakes is the easy part. Finding this idea for C i bet you get cyan in less than 5 contests !

»
72 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

ACGN pwned how to join the server?

»
72 minutes ago, # |
Rev. 4   Vote: I like it 0 Vote: I do not like it

Unfair time constraints for B, my correct solution [O(N) in PyPy] is giving tle on test 3, kindly accept this in system testing. (https://codeforces.me/contest/2031/submission/291630383) Wasted the whole contest in figuring out a logn or constant time solution for this, I didn't even try using C++ cause never do I expect a simple O(N) problem to give tle just because its python, also got like extra -200 because of trying shorter solutions for B out of frustration, so sad

  • »
    »
    47 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Python's input() is slow (at least on the judge server); always use sys.stdin.readline().rstrip() instead of input().

  • »
    »
    5 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Calling input() in Python flushes stdout. Even in C++ you easily get the same kind of TLE if you forget cin.tie(0). Repeatedly flushing stdout is very slow.

    For the future, put this into your template. Then you won't ever get this kind of TLE again.

    import sys
    input = lambda: sys.stdin.readline().rstrip()
    
    
»
71 minute(s) ago, # |
  Vote: I like it 0 Vote: I do not like it

In Problem D first example

4

2 3 1 4

o/p --> 3 3 3 4

how can rabbit jump from 2 to 3 because question clearly states that forward jump can be made iff the next guy is smaller.

  • »
    »
    70 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    2 -> 1 -> 3

  • »
    »
    67 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    The rabbit jump from 2 to 1 (because 1 < 2 and 1 stand after 2)

    Then the rabbit jump from 1 to 3 (because 3 < 1 and 3 stand before 1)

»
68 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

Great problem C, good choice of samples as well, any more samples might've given away the solution.

»
63 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

E can be solved in $$$O(N)$$$

  • »
    »
    62 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    how so? I'm interested

    • »
      »
      »
      27 minutes ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Please have a look at 291664548

      Basically, we just count the leaves needed for each subtree. The # can be large so we use a binary array.

      Since the count added from each children is a power of two, by potential method the amortized time to do addition of all children is $$$O(#children)$$$.

      Then we can just choose smallest $$$k$$$ such that $$$2^k$$$ leaves is enough.

      • »
        »
        »
        »
        16 minutes ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        I'm sorry, I really can't understand the code; can you explain it in more detail and pseudocode? thankss

        • »
          »
          »
          »
          »
          10 minutes ago, # ^ |
          Rev. 3   Vote: I like it 0 Vote: I do not like it

          Sure, dfs(u) returns depth of perfect binary tree needed to build subtree of u in original tree.

          Let's call this value dp[u].

          To calculate dp[u], first we calculate dp[v] for every child v. The intuition is if v requires perfect binary search tree of depth dp[v], it will "consume" 2^{dp[v] - 1} leaves.

          We add the amount of leaves needed for each child node of u to get the total amount of leaves needed for u's subtree.

          But the amount can be very large, so we use something similar to bigint in base 2.

          dfs(u) {
          	d <- 0
                  vec <- {}
          
          	for all child v {
                          x <- dfs(v)
                          vec.push_back(x)
          		d = max(d, x)
          	}
           
                  let xx be bigint
                  for w in vec {
                         add 2^w to bigint
                         d = max(d, w)
                  }
          
          	if (xx[d] == u)
          		for (int i = 0; i < d; ++i)
          			if (xx[i] == u) { ++d; break; }
          		
          	return d + 1;
          }
          
          

          (There might be some off-by-one error in this comment)

          • »
            »
            »
            »
            »
            »
            4 minutes ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            The complexity of bigint operations:

            The bigint is stored as array where each element can be 0 or 1

            Since the value we add to it is always power of 2.

            We can let potential of the array be count of digits with 1 in it.

            Each value we add will increase the potential by at most 1

            Hence, amortized over all children of node u, the complexity is O(count of children of u)

»
61 minute(s) ago, # |
  Vote: I like it 0 Vote: I do not like it

ACGN i can't view the implementation of problems,can you make them public?

  • »
    »
    58 minutes ago, # ^ |
      Vote: I like it +4 Vote: I do not like it

    I think the implementation are only viewable after system testing has concluded; sorry for the inconvenience.

»
61 minute(s) ago, # |
  Vote: I like it +6 Vote: I do not like it

if this round didnt have samples, nothing would have changed

»
58 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

I finished ABCD for the second time!

»
56 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

I can not access the implementation of problem D !!!

»
55 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

Why are there so many pretests in Problem E?

»
53 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

Thanks for creating this round!All of the problems are awesome!

»
53 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

In the solution for D Shouldn't it be:

ansi=max(a1,a2,…ai)=pi

instead of

ansi=max(a1,a2,…an)=pi

»
52 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

Damn. C was just Fire. Though couldn't finished in time

»
51 minute(s) ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
50 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

In D ansi=max(a1,a2,…an)=pi. should be ansi=max(a1,a2,…ai)=pi.

»
46 minutes ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

C was a great question. I was very close to figuring it out, but couldn't solve it in the end :(

»
20 minutes ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

in A if i assume if n == 1, the answer will always be 0, but due to this i got the wrong answer, why is that? my answer got accepted after i removed this condition

  • »
    »
    17 minutes ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    Because you are not reading the input that comes after, so you are getting wrong input for the next testcase.

»
14 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

Can someone assist me in determining the first minimum element from the back of an array for each element in the array?

Thank you!

»
14 minutes ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

What an incredible journey! The blend of creativity, dedication, and unique themes makes this round truly special. Kudos to the team for bringing it to life!

»
5 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

Can someone help me figure out why 291650692 failed with RTE, while 291666454 passed? The only difference is that the priority_queue is declared local in the former and global in the latter. Is this because $$$10^6$$$ ints is too much for a stack allocated std::priority_queue?