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

Автор chokudai, 6 лет назад, По-английски

We will hold AtCoder Beginner Contest 174.

The point values will be 100-200-300-400-500-600.

We are looking forward to your participation!

  • Проголосовать: нравится
  • +141
  • Проголосовать: не нравится

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

how many languages will be provided?

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

Question E is really hard to understand imo, couldn't understand it at all. :(

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

It seems like button to copy sample input has disappeared from Tasks for printing page. If I remember correctly, it used to exist before. Please add it back.

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

Whats the point in giving copy pasting problems -_-

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

I don't think this round is so well-prepared. Problem F has occured many times.

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

So, I asked if I can do process queries and print after processing or I have to process one query and answer immediately. And I get no comments. I don't know why and certainly don't know if I have done mistake or not. Anyway, solved the task where I needed clarifications.

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

how to solve problem F . please help???

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

After contest end then please give me some idea on C.

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

I can't find a difference between today's F and 1188 — Fast Queries . Really disappointed with today's contest :(

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

The problems seemed comparatively easy to me. I solved a SPOJ problem exactly like the problem F. I think the contest was not well prepared.

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

Same Question F from CSES can be found in GFG and other websites

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

Me during contest:

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

Can anyone give a little bit of hint on C Repsept. Is there any kind of tradition of Atcoder that problem C is more intresting and challenging than D.

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

F is almost similar to Spoj-DQUERY

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

Mini-editorial:

A: if print else print. Code.

B: loop through all points and count where x[i]*x[i] + y[i]*y[i] <= d*d. Code.

C: Notice that "X is a multiple of K" means that x % k == 0. We can use modular arithmetic (modulo K) to find possible remainders. Adding another 7 to the end of X is the same as x * 10 + 7.

I think if after K iterations you don't get a 0, that means there's no answer, because there's only K different remainders modulo K. However, during the contest I wrote a different solution that detected loops in the sequence of remainders. Code.

D: The resulting sequence looks like $$$RRR..RWWW..W$$$, i.e. 0 or more R and then 0 or more W. Note that flipping the color fixes at most 1 stone, whereas swapping two stones can fix two, so we can ignore the color flip operation.

Maintain two pointers: one pointing to the leftmost wrong element (=W) and the other pointing to the rightmost wrong element (=R). Swap the elements until the pointers meet. Code.

E: Use (integer) binary search on the answer. Suppose the answer is X ($$$0 \leq X \leq 10^9$$$). Then go through all logs $$$A_i$$$ and count how many splits $$$K_i$$$ you need to get the length of each of them under X, using the equation $$$A_i / (K_i + 1) = X$$$. There's some funky arithmetic with the rounding, which I'm unsure of, but it works. Code.

F: Mo's algorithm (a type of sqrt optimisation). Note that if you know the answer for a window $$$[L, R]$$$, it's easy to move either side of the window one position to the left or to the right: You can use a vector (don't use map or unordered_map, they are too slow) to store how many elements of each color you have, and keep a counter of unique colors (to get the answer in $$$O(1)$$$.

Then, using the idea of Mo's algorithm, you can sort the queries into $$$\sqrt{Q}$$$ buckets in such a way that the total run time will be $$$O(N\cdot \sqrt{N})$$$ instead of $$$O(N^2)$$$. The trick is to first sort the queries by the bucket of their left edge $$$L$$$, and then within each bucket, sort them by the position of the right edge $$$R$$$. This ensures that you will move the left end of your window $$$O(Q \cdot \sqrt{N})$$$ times, and the right end of the window $$$O(N \cdot \sqrt{Q})$$$ times (and given the constraints, we can assume $$$Q = O(N)$$$).

This can be implemented with a custom comparison function, no explicit buckets needed. Code.

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

Can someone share his/her approach of solving problem C. I tried it a lot , but was not able to solve it.

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

I've written an unofficial English editorial here: https://codeforces.me/blog/entry/80956

Hope it helps!

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

I think problem writers should read https://codeforces.me/blog/entry/75163 ...

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

    I think it's (partially) a difference in intended difficulty rather than problem-setting philosophy, Atcoder Beginner Contests feel as though A (and sometimes B) are designed to be solved by everybody, as long as they can write basic code. Whereas on a CF Div2/3, sometimes you don't even solve A or B since they have some tricky observation.

    In general, though, I agree (as I usually can solve Div2 A anyway), I also prefer when A and B have some interesting idea, and recent CF rounds have been really good about this! (And I think the blog post is valuable and worth reading.)

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

      I think it is not about difficulty levels. Difficulty levels assume some difficulty.

      What is the point of such problems as today's A?

      If you look at the standings there is literally not a single person who tried to solve it (at least made a submission) and failed

      What is the point of a problem that cannot be failed by any participant?

      Moreover, interestingly, there is not a single person who solved only A. They either solve both A and something else or none. Which pretty much means that weak participants also don't think about this problem as existing and just start with more difficult ones to check whether they can solve it and see no reason to solve only A. Also, probably people who persistently can solve only A just don't visit such sites.

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

Problem F just requires searching "Range Distinct Query". I know this is a Beginner contest so it's educational in nature, but maybe only E and F can be more carefully selected, since it's rated till a rather high bound.

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

Can someone help with E, I am getting wrong answer on 2 test cases.
Approach is binary search.My solution
UPD: Error found

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

I tried F using Mo's algo , but got TLE . This was similar to Dquery Spoj , But with higher constraints. Dquery

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

Easiest Contest ever......

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

please upload the editorial in English, because peoples are participating from all over the world...

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

Video solutions to all problems for people who are interested.

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

Please provide english editorials

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

In E why we can't cut longest log in len/2 and len-len/2 two parts greedly and put them in priority queue.

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

    That's actually what I implemented first -- luckily it got WA on the samples so I stopped and thought more.

    For a small counterexample, consider a single log of length 6 and $$$k=2$$$ cuts allowed. Our priority queue algorithm will cut into [3, 3] and then cut again into [3, 2, 1]. But it's possible to cut into [2, 2, 2].

    For a correct solution, see my English editorial.

    (But I encourage you to think about it more before looking, now that you know why the priority queue doesn't work.)

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

      Priority queue does work, see submission.

      The problem is that k can be 1e9 in which case it TLEs. Otherwise, it would run fine.

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

        Interesting. That looks more complicated than the simple greedy we discussed. Can you explain the algorithm?

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

          It is still greedy. Here, you store the number of cuts made too. Now when you make a new cut, you uniformly cut the whole log instead of the part you did.

          Implementation: Store total length, number of divisions and length of cut. Priority queue compares on basis of length of cut. When you get a new log, cut it into a unit more divisions.

          Taking your example, log is length 6, first cut cuts into [3,3] (storing as Log{total = 6, divisions = 1, length of cut = 3}) and second cut cuts into [2,2,2] (storing as Log{total = 6, divisions = 2, length of cut = 2}).

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

i use BigInteger class in problem C but didn't get the answer. Can any body tell where i was doing wrong...

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

Can someone help and explain me why this Solution gives TLE on problem F please? I'm using persistent segment tree

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

Guys can you suggest good resource for number theory for competitive. I found today's C very hard.

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

On Problem E, I got WA. After contest I check some test case in which I got WA. I got this one. 1 4784 450968417 and the answer is 94247. But If I cut the log with 94246.3 interval, I think it take exactly 4784 cut. So why 94246 is not the answer? Can anyone please help me? Sorry. I missed rounding 'Up' word.

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

Can someone provide editorial for this in English?

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

chokudai Many people have just copy pasted the solution of F from this: https://www.geeksforgeeks.org/queries-number-distinct-elements-subarray/ Please look into this matter!!!

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

I was reading problem F many times to be sure. Because it was too standard and I was thinking it can't be asked.

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

Apparently there's a solution to F for online queries and can even handle updates. It uses 2D range trees with fractional cascading:

https://stackoverflow.com/questions/39787455/is-it-possible-to-query-number-of-distinct-integers-in-a-range-in-olg-n

tl;dr; store 2d points of (currIndex, nextIndex) (default nextIndex is inf). Query the rectangle L <= currIndex <= R && R < nextIndex <= inf to count last occurrences in [L, R]

Can someone point me to a submission implementing it? (I'm mostly interested in the fractional cascading part to shave a log(n) factor)

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

deleted

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

Can anybody give a easy explanation in problem C as to why loop of i is only required till k and answer of number greater than k is not possible? But why

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

    Maybe this can help

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

      bro your explaination is good but i have some other doubt
      `void solve(){ int n;

      cin>>n;
      
      set<int> s;
      
      int x=7%n;
      int i=1;
      
      while(s.count(x)==0){
          if(x%n==0){
             cout<<i<<"\n";
             return;
          }
          s.insert(x);
          x=((x*10)+7)%n;
          i++;
      
      }
      cout<<-1<<"\n";
      

      }` this solution is acceptable but I saw one optimized approach using for(i=1;i<=n;i++) instead of while(s.count(x)==0) but i am not able to understand how is it acceptable.... please give some valid explaination after optimization code is —

      ``void solve(){

      int n;
      
      cin>>n;
      
      int x=7%n;
      
      
      
      for(int i=1;i<=n;i++)
      {
      
          if(x==0){
             cout<<i<<"\n";
             return;
          }
          x=((x*10)+7)%n;
      
      }
      cout<<-1<<"\n";
      

      } ``

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

        Simply If we mod x , n times there will be at least two same remainder (pigeonhole theorem) . Now in the first code we put remainder in the set and whenever we encounter a repeat in the set aka repeat in the remainder then its not possible (it has form a infinite loop and will never end in mod 0)

        In second code we just tried n times if there is not found mod 0 then it is sure that there will be repeatation of mod number so we break and print -1 (if we found mod 0 then we print number of step needed to get there)

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

          but why is the answer guaranteed in less than n steps where n is the number which is given as input.
          for(int i=1;i<=n;i++) how within this loops answer is confirmed ...can you please explain using example

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

            7 8 13 and we have N=3 if we mod 3 of them by N we get 1 2 1 It repeats , why? pigeonhole principle :there can be atmost N-1 mod numbers(boxes) but we have N mod number (pigeon) . So some mod number must be repeated .

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

If anyone need Detail explanation of C Here

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

Please, could anyone help me debugging this code? Thx!

#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2")
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
typedef long long ll;

int n, q, t[500005];
int c[500005];
int l, r;


int maxn(int s[],int m)
{
	int t;
	if (m==1)
	    return s[0];

	t=maxn(s,m-1);
    if (t>=s[m-1])
        return t;
    else
        return s[m-1];
}

int main()
{
	ios::sync_with_stdio(false);
        cin.tie(0);
	cout.tie(0);
	cin >> n >> q;
	t[0] = 0;
	c[0] = 0;
	for (int i = 1; i <= n; i++)
	{
		cin >> t[i];
		if (find(t, t + i, t[i]) == t + i) c[i] = c[i - 1] + 1;
		else c[i] = c[i - 1];
	}
	
//	for (int i = 1; i <= n; i++) cout << c[i] << ' ';
	for (int i = 1; i <= q; i++)
	{
		int no_use[500005];
		cin >> l >> r;
		if (l != r)
		{
			for (int j = l; j <= r; j++)
			no_use[j - l + 1] = c[j];
			cout << maxn(no_use, n) << endl; 	
		}
		else cout << 1 << endl;
	} 
	return 0;
}

PS.2AC, 4TLE, 1WA

another PS. I cannot speak English very well, and I can't speak Russian as well. So if some grammer errors exist, just omit it or tell me, thanks!

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

When will English editorial be published?

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

Can anyone help me with E-logs? Some people said its a simple binary search. I know binary search but even now I have no clue how it relates. It was my first contest. If anyone could link some articles or some similar problems, it will be very helpful. Thanks.