Comments

Let me make the idea a bit more clear for everyone, since even reds are getting me wrong.

Suppose 4 users ABCD are participating in the contest, and CD are new accounts. For A and B rating will be calculated as if only A and B are in the standings, for C it will be calculated as if ABC are in the standings, and for D as if ABD are in the standings.

So everyone gets rating, and it's more or less the same amount of rating as with the current system (because new accounts are a much smaller portion of all accounts), but two problems are gone:

  1. This is what usually troubles people about fake accounts: if some red user registered fake account and stole the first place, the actual div2 first place still gets rating as if he is the winner.

  2. The starting rating is 1500. If 1500 is not the true middle, it will either cause inflation or deflation of ratings. For example if someone participates, fails, gets -200 and drops his account, he gives away 200 points of inflated rating into the system. If you exclude new users from calculations in the proposed way, new accounts will get to their true rating (more or less), and only then will start influencing the system.

As farmersrice mentioned, it's usually called provisional rating, and it is successfully used in many rating systems.

As I heard, one of the causes of rating inflation is from lower rated people registering new accounts after failing their first rounds. I don't have statistics on that though.

Actually, I didn't mean that at all, but maybe I was a bit unclear.

For new accounts the rating change should be calculated as if only their new account was in the standings along with all the older accounts (if they weren't getting rating at all it wouldn't be much of a solution).

Why less attractive though? It doesn't even change much, considering that new users are a small part of standings (in usual rounds). I would expect it to affect rating change by maybe 3-10 points for everyone. But in a long run this helps against inflation.

And yes, they can do that, but on the one hand it will be way more obvious what these people are doing, and on the other hand I believe for most of these guys it will be too long-term and not worth it, so the problem will be 95% solved.

Well, if you exclude new accounts (for example with less than 3 rated rounds) from rating calculation (so everyone gets rating as if new accounts are not in the final standings, and each of the new accounts gets rating as if only their new account was in the standings), this problem will easily be solved. This is equivalent to placement matches for ladder in multiplayer games.

On csacademyRound #68 (Div. 2), 8 years ago
+35

Allow me to disagree.

There are not nearly as many platforms so that the contests are held every single day of the week. There's always a free day for each platform.

CSAcademy already surrenders the best days (Saturday and Sunday) to other platforms, I don't see why it's necessary to also surrender the best time slot (this slot was decided to be the most convenient to most participants by public polls on CSA).

Also, as a side note, I understand that 14:00 may be better for you and some other people. But there's a nice example we have, topcoder, that tries to hold contests in different time slots. While commendable, it just doesn't seem to work (take a look especially at contests held at 1am UTC, it's just a waste of problems at this point, literally 0 people participate).

"he or she likes it if and only if he can climb into this car and 2a ≥ b."

Pay attention to "if and only if" here. This means that when 2a >= b and a <= b, then she has to like it. And since it is written that she liked only the smallest one, it follows that the rest do not satisfy these constraints.

If it's any consolation to you, the Russian statement uses exactly the same wording.

Don't know the situation with problem B, but I have no idea what is it that everyone dislikes about A. To me it seems like the problem is not English, but the fact that it requires a bit more thinking than the usual div2 A. In fact, English in this problem is absolutely fine.

Let's take a look at your complaint.

Here's your wording: "Masha needs to be able to ride all three cars but she has to dislike the first 2 cars and like the smallest car."

Here's problem statement: "She could climb into all cars, but she liked only the smallest car."

What new information does your wording provide? Why is it better?

Amazing, good job finding this article! When applying Divide & Conquer optimization for minimization tasks, we always prove something along the lines of (d[a] + f(a, c) ≥ d[b] + f(b, c)) => (d[a] + f(a, d) ≥ d[b] + f(b, d)), but for this optimization there never seemed to be any easy way to prove applicability. Now there is.

Wouldn't expect any less from Swistakk :P

This is correct. I'm sorry, I was overseeing this editorial and for some reason it seemed completely fine to me, even though I am aware of the fact that the stronger statement is necessary.

While it seems intuitively correct, I fear that formal proof may be beyond my ability. I don't know if I_Love_Tina has it or not.

On PetrAn unsportsmanlike week, 9 years ago
+60

Can't say for Petr, but don't you think it's just that Gennady is on everyone's mind when there is an international competition nowadays?

Can't completely disregard your point though, yes, other guys deserve acknowledgement too. Really hope to see LHiC and overtroll as ACM-ICPC World Champions representing Russia one day.

And no, I don't suppose you have more than one account, I honestly think you shouldn't have posted this at all :) Free speech though.

On PetrAn unsportsmanlike week, 9 years ago
+85

This is stupid. It's called competition. Competing is fun. Trying to be "more the best" than the best is fun, especially if you have the means for it.

Why shouldn't Petr compare himself with tourist? Right now tourist provides him with a challenge, and Petr is up for that challenge.

I'd also argue that Petr seems more like a guy who'd stop participating sooner if there was nobody in the same league with him rather then if there are more great people to compete against :)

Regarding the link you provided in a later post where you say that messages like this are your "style": this is not about style. You've written some great and informative messages in the past. Not this time. In fact, a comment like this should have never been sent from your account, as it's more MAXIMAN tier garbage.

One of those contests where you think you want to ask for a clarification but don't even know where to start.

On BarichekCodeforces Round #407, 9 years ago
+5

If there exists a[i] == n, answer is 1.

Else if we don't have both a[i] < n and a[i] > n, answer is -1.

Else we have some a[i] == n — x and a[j] == n + y. Then we can take y bottles of type i and x bottles of type j. x + y <= 1000.

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

Yeah, don't worry, we will rejudge it soon!

This is already the whole editorial :)

I feel that people usually come to the editorial with specific task in mind, and not to read the whole editorial at once. This way they can just unroll the task they need, and not spoil themselves by accident glancing over the editorial of a different task :D

Also, seeing the whole solution may be less beneficial than taking a hint and trying to still solve the problem by yourself.

Like they were usually held, there will be 6 tasks for 2 hours. I'll update the blog with this :)

On MikeMirzayanovTesting Round #13, 10 years ago
+35

I think that what you should also be doing, is not just choosing one possible candidate, but the one that minimizes the number of remaining candidates in the worst outcome.

On LewinCodeforces Round #385, 10 years ago
+24

You are reading capitals after the edges, but they are given before them.

On riadwawTCO Round 3A, 10 years ago
+20

It's interesting that the same idea (except depending on the oddity of n one needed to pick the best position out of the last 1 or 2, then another out of the last 3 or 4 and so on) was used in TCO just last year, and also in Round 3 :) Round 3B medium (and back then it wasn't the first time I saw it either).

I thought that the task was a breeze after applying this idea, and was surprised to be one of the first to submit. It actually took me very little time to see and prove the greedy, but apparently it didn't go this smooth for most people (for example Errichto, who set previous 3B, as well as great amount of people who solved the medium back then, couldn't solve this task).

On PetrTopCoder SRM 693, 10 years ago
+10

It's very likely a parsing issue. You have a contest with the same name "SRM" later on July 9, and it may be overriding the current SRM on clist.by.

On PetrTopCoder SRM 693, 10 years ago
+3

Hard to learn about upcoming SRM's recently. No blog posts by chrome, no entry on clist.by or in Coder Calendar plugin :(

+16

For each center binary search the maximal radius such that you don't pick up any zeroes. Count the number of 2's and 3's in a cross with this radius. Use partial sums to quickly get number of 0's, 2's and 3's in a cross.

+46

Correct me if I'm wrong.

Task E: nothing prohibits non-positive d (it says three integers, not positive integers). With non-positive d set of items under given constraints is empty. So, technically, answer for all zeroes must be one and not zero?

My solution that prints 0 passed, and I think some solutions that printed 1 failed, seems not fair if I'm right =)

+10

My 2^k * k implementation passes =)

http://puu.sh/paG0G/b57485addc.png

On dagaCodeChef SnackDown 2016, 10 years ago
+72

Any strong reason for limiting teams to participants from the same institution/organization?

I mean, I would maybe understand if it was some sort of high school competition (uni vs uni spirit and all that), but this seems to be an open to every age and occupation type of event. Seems to me the only thing the limitation accomplishes is extra work for organizers (having to request a proof of being in the same organization and all) and, of course, my favorite part — leaving me with no team yet again for no reason at all. Thanks, I guess.

On murattCodeforces Round #352, 10 years ago
+24

Did pretests for Div1 D really not have a test for n == 1?

I had a solution that printed -1 in such case instead of 0, but, luckily, fixed it.

Damn, I got my hopes up a bit too much for this post. Thought maybe they finally implemented practice rooms and either plugins support or at least code generation for web arena. I mean these practice rooms are coming "soon" for more than half a year already -_-

It is a quite standard sweep line problem.

Sweep with a vertical line from left to right. There are 2 types of events: a circle began, a circle ended.

Maintain a set of circles that the line currently intersects (began, but not ended). In this set, maintain them sorted by Y coordinate of their center. Then each time you add a circle, you only need to check at most 2 of it's neighbors (for having a common point with it). The same when you delete a circle, there could be at most one new pair of neighbors formed that you need to check.

What you have to be careful with:

  1. counting the same pair twice (happens when you delete circles from the set).
  2. not counting circles sharing a common point that have the same Y. To count them, you should process adding events before the removal events when tie-breaking equal X coordinates.

Thank you so much, that's it!

I'm looking at my code for Preorder Test (Div1 edition task E) for like an hour already and can't understand why it gets TLE#8.

Can any of you guys help me find the bug? I don't think 8 million dfs calls can cause TLE in C++ when TL is 7 seconds.

http://ideone.com/d46vuQ

The reason is that you are not trying to maximize the expected value, but to win the game, so you can take advantage of the additional information (current score, remaining darts) to achieve better chance of victory.

For the sake of an example, let's say they throw darts at a line 8880099 and the chance is to hit one of the three consecutive boxes. Say they have two darts each and in the first round they both throw at 888, in the second round the first player throws at 888 again. Now, 099 nets less expected score, but as you can see, for the second player, it gives 2/3 chance of winning as opposed to 1/2 if he throws at 888 again.

On ShafaetHackerRank World Codesprint, 10 years ago
+14

Last time I won an Amazon Gift Card from Hackerearth they mailed me a Claim Code. Could use it on any Amazon Account.

On LewinWunder Fund Round 2016, 10 years ago
0

Well I know from practice that sin and cos are waaay too slow. Maybe you should have saved them in arrays sin[360], cos[360]? Try it.

On ShafaetHackerRank World Codesprint, 10 years ago
+4

Winners from US and India will receive Amazon Gift Cards. Winners from other countries will receive equivalent USD amount in bitcoins.

Just mentioning this for the others because it's in the rules but not in the announcement. For me personally an Amazon Gift Card would be better, but I guess tough luck =)

You don't need all 400 states. Since the field is symmetrical, instead of saying we are i cells from the right border, we can say we are m — 1 — i cells from the left border (0-based).

So you can do i' = min(i, m — 1 — i), j' = min(j, m — 1 — j), which brings the size of the matrix down to 100. You can also swap i' and j' if i' < j'. The size will be <= 55 then.

+12

About reusing it later: don't know about the others, but I already saw the statement while it was up for a short while, including the tricky restrictions, and even wrote a solution for it.

+10

So is the sixth problem still going to be added or this is all of them now?

Any possibility the contest could be moved to avoid collision with COCI#3? COCI has been scheduled for that time slot for a long time now.

H: Show that the largest circle always touches the boundary of the garden. Binary search the radius. Now for a fixed radius r we know that the answer lies on the circumference of the circle with center (0, 0) and radius R - r, where R is the radius of the garden.

So we are only interested in the polar angle of the answer. Notice that if this angle is atan2(y1, x1) + PI, we get the most distant point from (x1, y1) we can get. Find such delta that angles from atan2(y1, x1) + PI - delta to atan2(y1, x1) + PI + delta are distant enough from (x1, y1), and the rest of the angles are not. You can do it with another binary search or with acos, but don't forget that sometimes the whole circle is good and delta = PI, and sometimes even atan2(y1, x1) + PI is not good enough.

Now we have two ranges of angles. Those that are good for (x1, y1) and those that are good for (x2, y2). If the ranges have at least one common angle, this radius is good, else it isn't.

A: For each guy, calculate how much he owes minus how much he is owed. For some guys the number will be positive, for some guys negative. The sum is, of course, zero. Greedily connect the positive guys with the negative ones.

Thanks! It feels like cheating a bit though >.<

No, it should work without any space optimizations even with 64MB ML. That is, if you are using map<char, int> nx[2000000] and not int nx[2000000][26].

For some reason though, I got run-time errors on pretests with 2 million maps, even though on my machine the solution consumed around 35MB. So I wrote the above and it passed, thankfully.

+5

You are right, my solution is wrong >.<

I got lucky to not receive any WA. Spent too much time making other tasks work (especially fitting D in ML), which strangely ended up being beneficial as I didn't think this solution through, else I wouldn't have coded it!

I stored transitions in map<int, int> nx[1024];

When I wanted to find a transition, I did:

int ind = ((s[i] - 'A') << 21) | pos;
auto it = nx[ind & 1023].find(ind >> 10);

Memory limit was stupid though.

+7

One observation is that we never need more than K closest neighbours of the city (is it even correct? I only had 30 minutes to solve this task, so I didn't have much time to prove things). What I did is I took K closest cities by X, K closest cities by Y, and then merged the two lists and took K closest cities overall.

Then you can do binary search for the squared distance, finding the connected components using only edges found above, and trying to find solution for the problem for each connected component separately.

This works in N * K * log(MAX_DIST^2). Could still be too slow for 1 second, not sure.

Edit: looks like this solution is not fast enough, or my implementation is slow. 96 points

+19

Without hashes:

Use trie. Let's put strings one by one in it, solving the problem for the given string at the same time. Once we added the string and calculated the answer for it, we will remember this answer in the node of the trie that corresponds to the end of this string.

Processing a string: mark all positions i such that the first i characters are equal to the last i characters of the string. You can do it with z-function (or KMP if you prefer so). While moving through the trie, take a maximum of all previously remembered answers that lie on nodes which correspond to the marked positions. The answer for the current string is this maximum value plus one.

0

Didn't see your edit when I replied. We came up with the same thing :D

By the way, differences of 65535 are even better than 100000, they lead to more matrix multiplications. Almost all accepted solutions fail such testcases.

+15

It seems that on all of their big testcases time makes big jumps and then increases very little for a while. So the logarithm part is almost always 1.

I wrote a solution which passed their tests in 870ms, but worked on my custom testcase with t[0] = 100000, t[1] = 200000, t[2] = 300000 etc. for 18 seconds.

I still managed to pass that testcase in a bit under 3.5 seconds using the fact that we can take modulo once or maximum twice during 20 multiplications in the third loop of the exponentiation. But the constraints are definitely too big for the solution and the testcases are weak =)

On ZloboberGP of Ekaterinburg, 11 years ago
0

With set: 1.2s

V^2: 0.49s

On ZloboberGP of Ekaterinburg, 11 years ago
+3

Were they actually trying to separate them though? I passed with Dijkstra on Set in my Min Cost Flow. So it was even O(N^3logN).

Collides with Opencup, Grand Prix of Siberia.

You can store the xor of last two. 2 is interchangeable with 0.

On Facebook you knew it would be public from the start :)

You can ask what happens when you move from x to x+1. If you receive 0, ans <= x. Else, ans > x.

On enot110Who is the most popular?, 11 years ago
+44

I added you because I like to compare my progress with different reds and yellows who participate regularly (in a contest, I mostly look at the friends leaderboard). The spamming is exactly the reason you are one of them ;)

On GuralTOOCOCI, 11 years ago
0

Yes, it is possible to avoid division:

http://ideone.com/nd4dDL

On GuralTOOCOCI, 11 years ago
0

I have full score with almost the same complexity, except I build the segment tree in O(c^2 * n).

And another thing is that in each update I do MOD operation only c times, not c^2.

On GuralTOOCOCI, 11 years ago
+3

F: notice that for each guy we can calculate his possible left and right bounds independently. Take a vertex x, sort it's children by V[i].

Suppose that we want to find all the left bounds for x. In the beginning, the only left bound is V[x]. Iterate through the children from right to left, starting from the first child i that has V[i] < V[x]. If a child has one of it's right bounds in the position of one of x's left bounds minus 1, we can add all of this child's left bounds to x's left bounds.

Hope this isn't too unclear >_<

On lukasPNCPC 2015 online contest, 11 years ago
0

Problem B. In the picture, there is a transition from 1 2 4 3 6 5 back to 1 2 3 4 5 6. Do we have to be able to go to the initial position like this? The statement doesn't have any information about that.

On BeraNonsense about doubles, 11 years ago
+23

You'd think that even though there are precision errors, doing the same thing should lead to the same results, but there's also top answer here: link

On BeraNonsense about doubles, 11 years ago
+40

Well, comparing doubles like this leads to unpredictable results. Use integers whenever possible, and when not, use epsilon when comparing two doubles (or comparing double with integer).

http://codeforces.com/contest/568/submission/12457494

On zxqflSRM 663, 11 years ago
+16

Funny, this is actually my challenge case for O(n^3) solution.

It was most likely added to the system tests in the end as a successful challenge, that's why the truncation bug on it was not caught before the round.

On wanboHackerRank 101Hack 27th Edition, 11 years ago
+15

Should be half an hour later, right now it intersects with the challenge phase of SRM 663.

0

My solution prior to isolating the K = 10 case has 97.84 points, and the one after has 99.06. For a hundred though it was definitely too slow and the score went down.

+14

Glad to say I am impressed with the problem set.

My favourite task was C as it jogged my memory on the Divide & Conquer dynamic programming optimization, which I rarely come across in programming contests.

+19

I used HLD where each path of decomposition is a treap. You can cut the chunks of paths from u to v out of HLD, merge them into one treap, reverse and veeeery carefully put it back.

Probably possible with splay trees too as mentioned above, but I have no experience with them.

+22

My approach for the challenge problem:

K = 1 — let's pick the value with the most bits set from A. Now let's pick the value from B such that A[i] | B[j] is maximized. Most of the time this should give you all bits set.

K = 10 — let's pick such values A[i..i+9] that their sum is maximized. Now when picking values from B let's calculate the total result with brute force (10x10 iterations) and compare it to the best result so far.

K > 10 — let's pick both A[i..i+k-1] and B[i..i+k-1] such that their sum is maximized.

Also you can stop searching for better values in the current array and have more time for another one if you come against two zeroes in a row (possible since the values b0 b1 d0 d1 are generated randomly), but this doesn't change the score too much (0.1-0.2 final points).

+3

Still remember this problem. I only glanced at your code, so I can be wrong, but here is something that I really don't think should be in there:

if(n%2==0){
        for(int i=2;i<=n;i+=2){

The oddity of the number of the objects does not matter, also you I don't think you want to jump 2 objects at a time. It looks like you are trying to make as many groups as possible, when in fact some objects are better left alone. (Precisely, pairing up any 2 objects which make an obtuse angle with the purse will only increase the distance, given how it's calculated in this task).

Consider a bitmask dp where you either pick the leftmost zero alone or in a group with any other zero.

+9

The DP in Bits Transformation is basically d[i][j][k] — the lowest cost of passing i characters in string a and filling first j zeros and first k ones in string b with them. Since k = i — j, we drop it and it becomes an O(n^2) d[i][j] dp.

At each step we look at how much it would cost to transform symbol a[i] into zero and into one, and how far the next zero and one are in string b. Then we assign d[i + 1][j + 1] = min(d[i + 1][j + 1], d[i][j] + cost0 + <distance from i to j+1's zero in b> / 2) and the same for d[i + 1][j] <k + 1>. We divide the distance by 2, because for each element not in it's place we can swap it with another element not in place, which has to go in the other direction.

Reference solution: http://pastebin.com/qJ1xhawP (a bit messy :P and I multiplied everything accept for distance coefficient by 2 to avoid fractions).

+9

Let's assume connected components are black stones (N - M in total) and spaces between them are white stones (M in total). Let's use C black and C - 1 white stones to form the minimal possible chain of C connected components: bwbwbwbwb.

Now we have to spread N - M - C black stones across C positions, then spread M - (C - 1) white stones across C + 1 positions ( + 1 because there are two extra positions for white stones to the left and to the right). So it's going to look like this: solve(N - M - C, C) * solve(M - C + 1, C + 1)

Now what is this solve(int count, int positions) function? It's a choise of k elements out of n with repetitions allowed. solve() should return zero if count < 0, and C(count + positions - 1, positions - 1) otherwise.

+13

Here's the solution from the editorial plus extra D(N,B) recurrence to account for disconnectedness:

T(N) = 2N * (N - 1) / 2 — the number of graphs with N vertices.

— the number of connected graphs with N vertices. We subtract the number of disconnected graphs from the total number of graphs assuming that the first vertex lies in the component of size k. Later we will be using the same technique (assuming that the first vertex lies in one of the subgraphs).

— the number of 2-edge-connected graphs of size N. From the total number of connected components we subtract the number of connected components which have at least one bridge.

— auxiliary function to calculate F(N, 0). Here we have a 2-edge-connected component of size K and N free vertices which we have to split into connected components. Each one of the connected components will have exactly one edge going to our 2-edge-connected component of size K, which leads to the multiplication by K * l.

— the number of connected graphs with exactly B bridges.

— auxiliary function to calculate F(N, B). Here we have a 2-edge-connected component of size K, N free vertices and B has the following meaning: the number of connected components + the total number of bridges in these components. On each step we assume that the first vertex lies in the component of size l with j bridges.

— the number of graphs with N vertices and B bridges allowing disconnected components this time.

In all these recurrences we assume that a single vertex is a 2-edge-connected component.

+8

Div. 1 Hard was also given at NEERC's Western Subregional 2014. https://contest.yandex.ru/QF2014/contest/794/problems/G/ (requires Yandex login).

It's not 100% the same as it requires to calculate only the number of connected graphs, but it is easy to account for disconnected graphs afterwards.

There is a video editorial (unfortunately, only in Russian), which helped me understand the approach for this kind of problems a lot. (problem G starts at 48:48)

+6

Looks like you do not assign the "comp" variable, which is local. Should be: int ip = 0, comp = 0, ini;

Use custom invocation in situations where your code does not pass test 1. Your code prints "NO" on CF servers.

They don't run your code locally so there is no such verdict as TLE. You have to produce and upload the output in 6 minutes, this is the only limit.

+4

There was an announcement about maintenance before it went down.

On sappleki280 (Div2), 12 years ago
+4

The problem is probably in printf("%.10f¥n",ans), which outputs ¥n instead of newline. Generally, if you get wrong answer on pretest 1, good idea is to use Codeforces' Custom Invocation to check how your code runs on the Codeforces servers.

There is indeed a bug in the implementation. It is pointed out in the comments section in the first comment. What it says is basically

replace int k = (i>r ? 0 : min (d1[l+r-i], r-i)) + 1;

with int k = (i>r ? 1 : min (d1[l+r-i], r-i));

Question is, what it K? Since each edge has different cost. And the solution above is wrong anyway, sorry!

I'm an idiot :<

Edit: wrong, of course

Something like O( K). Not sure if I understand your question. You do the same thing on each iteration, just as you would in Min-Cost Flow with Bellman-Ford or with Dijkstra + potentials.

In the end, each part of the initially divided edge will be filled with the same amount of flow, so it will be easy to get back to the original graph.

Split each edge into Ki edges with cost 1 and run bfs.

On I_love_tigersugarTopCoder SRM 636, 12 years ago
+11

For each vertex you can sort other vertices by priority (first distance, then y coordinate, then x).

Then for each pair of vertices you want rabbits to NOT be in the cells that have higher priority compared to the picked vertices in at least one of the list.

If there are n places for rabbits, r rabbits and e cells must be empty, the chance for that is C(n - e - 2, r - 2) / C(n, r) (two picked cells are already occupied by rabbits, which leads to minus 2). Add this chance to ans for each pair.

That's O(n^6), not sure if it's quick enough, as I didn't implement it during the contest :c

There is a coach mode when you are red (or yellow and participated in 30+ rated events). With coach mode enabled you can transfer to practice all solutions made by somebody in a gym contest.

Somebody might have abused this feature. I think your best course of action is to try contact Mike.

Any ideas on G?

"aaaa" is a prefix of "aaaa" so on step 4 you will get "aaaa" again and not "aaaaaaaa".

Ha, yeah. Guess there's little place in competitive programming for slowpokes like me. Takes too long to come up with the idea for a hard problem and in short competitions I almost always end up solving one extra problem just 5-10 minutes after the end of the contest.

In my opinion, 1:40 is a little bit short for the final round. My reasoning is that people that can solve 5 problems in, say, 2:30, are better and should be rated higher than those who can solve 4 in 1:40 and run out of ideas.

That aside, the problems were great, thanks for the contest!

On damn_metle in multq3, 12 years ago
+3

Faster input maybe, but not output. Don't use endl, use '\n' instead. Even better if you replace the whole thing with printf("%d\n", query(1,0,n-1,x,y));

Also you could try replacing every 2 * node with node << 1 and every 2 * node + 1 with (node << 1) | 1, maybe it will help.

Oh, right, in build_st() instead of if (L == R) return new Vertex(a[L]); it should be if (L == R) return new Vertex(L < n ? a[L] : 0); so it doesn't try to access elements in A that do not exist. My bad.

We do not need lazy propagation, since nodes of the tree do not actually store any information about the segment (like minimum or sum), they just store x that we have to add when passing through the node, and y that we have to add for each element we skip after passing through the node.

Here is my implementation of this. Of course it's slower than the solution ValenKof suggested below and works for O(N * logN * logM), but it was still fun to implement this :P

http://pastebin.com/HLhNJzeQ

His code is correct, your problem statement isn't. According to this test case, values A[L]..A[R] are increased by x..x + (R - L) * y and not by x + y..x + (R - L + 1) * y.

+3

On each update every interval we iterate through we unite in one big interval. Then in the worst case we split the leftmost and the rightmost intervals, which leads to 2 extra intervals per one query. With the total of m queries and n intervals in the beginning this leads to no more than n + 2m iterations in total.

+38

I don't really see the easy way to prove the fact that the best answer for i + 1 has the best answer for i as it's subset.

Edit: counterexample: graph with successively connected vertices 5-6-1-3-6-4, numbers are weights of vertices. Weights of edges are all 1. The best answer for 2 vertices is 5-6, the best answer for 3 vertices is 3-6-4.

So your algo only works because the answer is always in dp[2] :P

On SmartCoderTCO'14 Algorithm Round 2C, 12 years ago
+3

So, basically, on each BFS step we process the current vertex v and:

  1. Pick all the cliques in which v lies.
  2. For each clique that we haven't processed yet, update distances to vertices in them that we haven't visited yet to dist[v] + 1, put these vertices to the queue.
  3. Mark all cliques we processed on this step as processed.
On SmartCoderTCO'14 Algorithm Round 2C, 12 years ago
+3

No chance for T-shirt, sorry! There are 350 T-shirts, first 50 places were different in all 3 contests, so that leaves 200 T-shirts for places 51 and lower. Saying that 23X's place gets a T-shirt is like saying that 18X out of these 200 people were placed in top 23X in all 3 contests. Or something like that.

My guess is you have to be in the top 140-190 to get a T-shirt. Really depends on the diversity of the results.

On SmartCoderTCO'14 Algorithm Round 2C, 12 years ago
0

Well, they notified that there were problems with system testing. Most likely they shut down the arena to investigate.

On SmartCoderTCO'14 Algorithm Round 2C, 12 years ago
+1

This one is only for those who advanced from Round 1. If you want to take part in topcoder contests, check out Single Round Matches (SRM).