By adedalic, history, 19 months ago, ,

First, I apologize for problems with round and serious problem with Div1A/Div2C. It was very important round for me and, as always, something goes wrong. KAN have already wrote about this.

Anyway, there are problems, so editorial must exists. Due some circumstances, Editorial will be upload in parts. Also, most of tutorials will contain main ideas how to solve task, not ready algorithm.

code
code
code
code
code
code
code

•
• +200
•

 » 19 months ago, # |   +12 Auto comment: topic has been updated by adedalic (previous revision, new revision, compare).
 » 19 months ago, # |   +8 But in both cases we must add 3 arithmetic progression to the segment of array d. Its well known task, which can be done by adding/subtracting values in start and end of segment offline.Can you please elaborate a bit(or point to some reference) on this well known task?
•  » » 19 months ago, # ^ | ← Rev. 2 →   0 I a general case when you need to add progressions and answer querys you can use a Lazy Fenwick tree, see this tutorial. Maybe someone knows how yo solve it whitout this structure, I don't.But in this specific case, you made updates but you have to answer the query just after all modifications are made. So you can made the updates using just 2 arrays
•  » » 19 months ago, # ^ |   +5 Yes, i will elaborate this with next update
•  » » 19 months ago, # ^ |   +1 Reference for offline addition(407C)
 » 19 months ago, # | ← Rev. 4 →   +6 A"if...else if''solution for div2 C... 28115691
•  » » 19 months ago, # ^ |   +6 can you please explain your code??
•  » » » 19 months ago, # ^ |   0 sorry that I failed to prove it when b < a,seems complex...I just think it will be a loop; and when b >= a or the length is short,the answer is sure.there are some mistakes before,now corrected and some comments added
•  » » 19 months ago, # ^ |   +1 A loop come brute force solution must work I guess. Basically logic I tried out is checking all strings where the repeating character introduced by B is any of the last max(1, a-b) characters. http://codeforces.com/contest/820/submission/28126243
 » 19 months ago, # |   +5 An alternative to handle the even case of 1E is to split the graph into 2 equal disjoint sets A and B. Label the elements a_1 to a_m, b_1 to b_m.Use induction to construct for A and B separately. What remains is the complete bipartite graph, which can be done using cycles of length 4, all of form a_i — b_(i+j) — a_(i+1) — b_(i+j+1), where i and j run from 1 to m, and indices are taken modulo m.
 » 19 months ago, # | ← Rev. 2 →   0 Can someone please help me understand how Div2 Problem B can be solved in O(1) ?
•  » » 19 months ago, # ^ |   0 Here's my submission Well, if you want to find closest angle to a, you just need to find an arc with angle most close to 2*a which its vertices are vertices of polygon. For doing this, you make your ideal arc (with angle 2*a) and find the vertex in polygon which is closest to end of arc.
 » 19 months ago, # |   +4 can anyone explain div2d div1 b more thoroughly . i am not getting it
 » 19 months ago, # |   +3 The solution for Div 2 B is really nice. My solution was to construct the polygon then use dot products and a binary search to find the best end point with two other points fixed. It was really tedious and time consuming to code and had a worse complexity of .
 » 19 months ago, # |   0 Can someone elaborate more accurately on Div2 D?
 » 19 months ago, # |   +18 For Div2D / Div1B, one could also keep the amount of elements which holds a[i] >= i to update the difference in O(1) time.Code with comments : http://codeforces.com/contest/819/submission/28113390
•  » » 19 months ago, # ^ |   0 Can you explain your solution a bit more?
•  » » » 19 months ago, # ^ |   +7 To calculate the weighted sum of the (i+1)-th shift from the i-th shift, the elements which holds i >= a[i] (named as gt in the code) contributes +1 to the sum and i < ai contributes -1. That being said, we could solve the problem by simply maintaining the amount of elements which holds true on the above cases.For non-tail elements, we could easily tell the moment of i < a[i] becomes i >= a[i] is a[i] — i, meaning that we need to account for this moments later.For the tail element at the moment, we shall recalculate its contribution and placing a new update for it. Note that as a[i] <= n, it is guaranteed that n > a[tail] holds true, so we shall remove one from gt before the update. Same for updating lt for the tail.
•  » » 19 months ago, # ^ |   0 Can you please tell me what does upd[i] hold? Actually I don't undersatand what this operation "upd[a[i]+i]++" is doing.
•  » » » 19 months ago, # ^ |   +1 As upd[time] stores the pended update for moment "time", upd[time]++ means that there will be one extra element will switch from contributing -1 to +1. As we are placing a[tail] back to the front, after a[tail] iterations it will hit a[index] == index, therefore we shall place an update on time = a[tail] + current_time = a[tail] + i.
•  » » 19 months ago, # ^ |   0 I did it more stupid using segment tree, but calculating indexes carefully is a bit difficult, and each update in log time :Phttp://codeforces.com/contest/820/submission/28132944
•  » » 19 months ago, # ^ |   0 Awesome solution! Thanks. I understood it and coded myslef but it's giving TLE! I dont understand how a O(n) solution gets TLE?! Code Can you please check it once why its happening
•  » » » 19 months ago, # ^ |   +1 Editted versionI interchanged line 10 & 11 of the original code and it passed all cases, the TLE is most likely caused by initializing the array with size n+2 before n is properly initialized.For the sake of competitve programming, I would recommend you to use array that has fixed size instead of referring their sizes to variables -- This increases memory usage in practical cases but we only care about the worse case scenario here.
•  » » » » 19 months ago, # ^ |   0 Yea. I figured it out just after submitting the solution in java. In c++ uninitialized variables contain garbage values and no compilation error, however in java you need initialise it. BTW thanks for giving this nice concept to solve the problem
 » 19 months ago, # | ← Rev. 2 →   +11 I think my solution of div2D/div1B is a bit easier. We can see that after a cyclic shift our array is always divided into two parts: shifted part and not shifted part. So i just simulated the process. All wee need is two maintain two values for each of two parts: number of such elements that |p[i] — i| will increase after shifting, and number of elements for which this value will decrease. Complexity is O(n). My explanation isn't very good, but code may help you 28121452
•  » » 19 months ago, # ^ |   0 I did something similar: http://codeforces.com/contest/820/submission/28127444
 » 19 months ago, # |   0 Auto comment: topic has been updated by adedalic (previous revision, new revision, compare).
 » 19 months ago, # | ← Rev. 2 →   +48 Abstract.Another (and probably more simple) approach to Div1E.Here I will suggest a way of constructing a solution for n, given any solution for n - 2. No properties are requested and required to be preserved by such induction.You still need to solve cases for n = 3 and n = 4 to get the full solution.The method:Let's take two nodes, let them be s = n - 1 and t = n for simplicity of numbering.Consider following paths: ... (this one is special from above). Taking any two of such pathes you form a valid cycle of length 3 or 4. Match listed paths into cycles the following way: first with second, second with third, ..., pre-last with last, and last with first (in other words, match by neighbourhood).Add such cycles to the answer. Note, that each listed path was used twice by construction above, this way all edges connected to s or t were used twice too.Continue with n = n - 2 here.
•  » » 19 months ago, # ^ |   0 This solution is absolutely brilliant! Thanks for sharing it with us. It's unexpectedly elegant and easy to understand. I've looked for an induction approach but failed to think about it for long because it was hard for me to imagine that I might be able to keep the old construction in its exact form, without some strange alterations.
 » 19 months ago, # |   0 why editorial link is not there on contest page . I know there is issue with div2-c question but rest of the question are good , i learned and solved div2-d and e(almost done) . good work in editorial and contest adedalic . thumbs up for good work.
 » 19 months ago, # | ← Rev. 2 →   0 There is my solution to 819A - Mister B and Boring Game First of all, I guess the color for each segment a is ascending or descending. And for each segment b its color is the minimum or maximum value of the previous paragraph a. We can easily make the interval between l and r no more then 5*(a+b). Thus, you can enumerate the status of each segment and calculate the current answer. Maybe I can't describe it clearly.This is my submission:28097355
•  » » 19 months ago, # ^ |   0 The description said: "From multiple variants of t lexicographically minimal is chosen." Why each segment a is descending?
•  » » 19 months ago, # ^ |   0 Your solution inspire me.This is my solution.For each segment a is increasing then as you said: "for each segment b its color is the minimum or maximum value of the previous paragraph a.", so I separate it to two situation: If a<=b then get the minimum/maximum value in section[lst+1,lst+a] else get it in section[lst+b+1,lst+a].
 » 18 months ago, # | ← Rev. 2 →   0 Here is my O(1) solution of 820B : 28500099
»
10 months ago, # |
Rev. 6   -23

Could someone please tell me why my test's 6 output differs from my output in my consola ? I have correct output (that is 2 1 558 ) even though in my consola i see this ---> 2 1 584

That's the code

# include

using namespace std;

float n, a;

float kw, ks;

int main() {

ios_base::sync_with_stdio(false);

cin >> n >> a;

kw = ((n &mdash; 2) * 180) / n;

ks = kw / (n &mdash; 2);

int l = 0;

float mini = 180;

float p = 0;

int i = 0;

while (kw >= ks)
{
p = kw- a;

if (p < 0)p = -p;
if (mini > p)
{
mini = p;
l = i;
}
i++;
kw -= ks;
}
if (l == 0)
{
cout << "1" << " " << "2" << " " << "3";
return 0;
}
if (p == mini)
{
cout << "2" << " " << "1" << " " << "3";
return 0;
}
else
{
cout << "2" << " " << "1" << " " << n-l;
return 0;
}
return 0;


}

It was my first time posting and i did not know that after pasting the code will get deformed. Sorry.