### mesanu's blog

By mesanu, history, 12 days ago,

Thank you for participating!

1971A - My First Sorting Problem

Idea: flamestorm

Tutorial
Solution

1971B - Different String

Idea: flamestorm

Tutorial
Solution

1971C - Clock and Strings

Idea: flamestorm

Tutorial
Solution

1971D - Binary Cut

Idea: flamestorm

Tutorial
Solution

1971E - Find the Car

Idea: mesanu

Tutorial
Solution

1971F - Circle Perimeter

Idea: mesanu

Tutorial
Solution

1971G - XOUR

Idea: mesanu

Tutorial
Solution

1971H - ±1

Idea: flamestorm

Tutorial
Solution
• +64

 » 12 days ago, # |   +36 🌹
 » 12 days ago, # |   +15
•  » » 12 days ago, # ^ |   +8 What if you changed thte black backlight to a light white one
 » 12 days ago, # |   +25 My joke solution to problem C:https://codeforces.com/contest/1971/submission/260436859
•  » » 11 days ago, # ^ |   0 Bro can you explain your solution?
•  » » » 11 days ago, # ^ |   +6 He converts given integers to points on plane to find the answer with geometry
•  » » » » 11 days ago, # ^ |   0 I was gonna ask you to atleast give me a keyword to google. But i asked chat gpt. Only thing i understood is it's not worth it at my level. lolAnyway, Thank you for your time.
•  » » » » » 11 days ago, # ^ | ← Rev. 2 →   0 e^(i*omega) produces a point in the unit circle in the complex plane. Here I use it to produce the position of 1-12 o’clock. Then, there is a triangle area formula that produce positive value if 3 points are given in counterclockwise order, negative value clockwise. So I use it to calculate the area of Δabc and Δabd. It’s obvious that c and d are on opposite of line ab iff one is positive and the other is negative.
•  » » » » » 10 days ago, # ^ |   0 he just , gave the hands of click different coordinates on a plane , then plotted the time(points) on the given graph , then check if there is any point of intersection between the given two lines , an interesting way XD.
 » 12 days ago, # |   0 Dude, you included the wrong tutorial for problem B.
 » 12 days ago, # | ← Rev. 2 →   0 problem b editorial for now is an editorial of an old div4b problem, fix plsupd1: fixed now
 » 12 days ago, # |   0 Too Fast!
 » 12 days ago, # | ← Rev. 5 →   0 https://codeforces.com/contest/1971/submission/260448426-> this is giving out of bound https://codeforces.com/contest/1971/submission/260447515-> this is not giving out of bondBoth code are same,, just the writing style is different..Why is this happening?? Thanks in advance..flamestorm(could you plz help sir)
•  » » 12 days ago, # ^ | ← Rev. 3 →   0 The difference lies in how division is performed: the first snippet directly divides by a variable (speed) that could be close to zero, risking a division by zero or resulting in large values leading to out-of-bounds errors when accessing the 't' vector, while the second snippet avoids this issue by rearranging the calculation to use multiplication and division together.
•  » » » 12 days ago, # ^ |   0 the second code that passed should get out of bound he is using upper bound take for example this case 10 1 1 10 10 10it should give RE but it's not because I tried to hack so why ??
•  » » » » 12 days ago, # ^ |   0 The second code is avoiding the expected out-of-bounds error because it decrements the index i after upper_bound, making it within bounds. However, this behavior is unreliable and could lead to issues with different inputs or compiler optimizations.
•  » » » » » 12 days ago, # ^ |   0 he decrements the index i but he is using (i+1)
•  » » » » » » 12 days ago, # ^ |   0 In the second code, even though the index 'i' is decremented after upper_bound, it's still used to access t[i], which could lead to accessing an out-of-bounds element since i is decremented but used as 'i+1'. This behavior is indeed a vulnerability in the code, which could lead to unpredictable results or runtime errors, depending on the input.
•  » » » 12 days ago, # ^ |   0 https://codeforces.com/contest/1971/submission/260423806 This friend of mine did the same thing using another vector but his code didn't show any kind of this behaviour
•  » » » » 12 days ago, # ^ |   0 This code ensures that mid always points to the correct segment in the array 'a', preventing out-of-bounds issues when accessing elements from 'a' and 'b'. Therefore, the code doesn't exhibit the same behavior as the previous codes.
•  » » » » » 12 days ago, # ^ |   0 The first code also decrement i to prevent out of bound.. And, I said the division by smaller number logic is invalid since he did the same thing...
•  » » » » » » 12 days ago, # ^ |   0 You're correct. I apologize for that. Both the first and second snippets decrement the index i to mitigate the risk of accessing out-of-bounds elements. Additionally, you rightly pointed out that the division by a smaller number logic doesn't apply since both codes essentially use the same approach.In that case, it seems that the difference in behavior between the two codes might be due to other factors, such as input data or compiler optimizations
•  » » » » » » » 12 days ago, # ^ |   0 Input data is same brother
•  » » 12 days ago, # ^ |   0 weird
 » 12 days ago, # |   0 took 30 min to solve F+G, still have no idea how I got WA from E 260451462too bad actually
•  » » 12 days ago, # ^ |   +4 Solutions that use floating points will eventually get hacked.
 » 12 days ago, # | ← Rev. 5 →   +1 please tell me why this is not getting accepted but (PROBLEM E) long long ans = brr[it] + ((drr[i]-arr[it]) / ((arr[it+1]-arr[it])/(brr[it+1]-brr[it]))); this is accepted? how? long long ans = brr[it] + (drr[i]-arr[it]) * (brr[it+1]-brr[it])/(arr[it+1]-arr[it]);
•  » » 12 days ago, # ^ |   0 please, put your code in spoiler next time, or at least on different lines.from what i can see, in the first one you should have used floating point arithmetic, but it would be a bad idea, cuz solutions with floating point are getting hacked now.the second one just makes your original formula compatible with integer arithmetics in c++, so it works just right
•  » » » 12 days ago, # ^ |   0 I am sorry, for the bad structure of the comment, will do the needful next time.. "the second one just makes your original formula compatible with integer arithmetics in c++, so it works just right" how you know that, like how can I think like that during the contest.
•  » » » » 12 days ago, # ^ |   0 try to just simplify formula as mush as you can (and also try to use less division), that's what i usually do
•  » » » » » 12 days ago, # ^ |   0 thankyou very much :)) wishing you loads of +ve delta
•  » » » » » » 12 days ago, # ^ |   0 thank you!
•  » » » » » » » 5 days ago, # ^ | ← Rev. 10 →   0 hey, I am not getting why i am getting TLE for the same problem 261422309. I even implemented the same binary search as the official solution
•  » » » » » » » » 4 days ago, # ^ | ← Rev. 3 →   +3 in the binary search function, every time that you use it, you create a new copy of a vector. what you should do instead is pass it by reference, just changing the vector v to vector &v should workhere is your solution when vector is passed by reference 261565356
•  » » » » » » » » » 4 days ago, # ^ |   0 .ComplaintFrame { display: inline-block; position: absolute; top: 0; right: -1.4em; } .ComplaintFrame a { text-decoration: none; color: #ff8c00; opacity: 0.5; } .ComplaintFrame a:hover { opacity: 1; } ._ComplaintFrame_popup p, ._ComplaintFrame_popup button { margin-top: 1rem; } ._ComplaintFrame_popup input[type=submit] { padding: 0.25rem 2rem; } ._ComplaintFrame_popup ul { margin-top: 1em !important; margin-bottom: 1em !important; } Never knew making copies would take up so much time. Thank a lot mate.
•  » » 11 days ago, # ^ |   0 Same problem and really learned a lot! Thanks!
•  » » 10 days ago, # ^ |   0 yeah similar problem same testcase failed.
 » 12 days ago, # |   0 Detailed Video Editorials (BCDEFG)https://www.youtube.com/playlist?list=PLbAEGNVuy98kfnqOz26QPV4cSpj9j-3tY
•  » » 12 days ago, # ^ |   +3 Language — Hindi
 » 12 days ago, # |   0 nice editorial but why does always with c++ why dont in python or other languages
•  » » 11 days ago, # ^ |   0 +1
•  » » 10 days ago, # ^ |   0 its better for the purpose ig
 » 12 days ago, # | ← Rev. 2 →   0 Can anyone explain me please(with reference to problem E) — as the answer needs to be rounded off to nearest integer value...so let say total comes out to be like 1.6 then the rounded off answer wouldn't be 2 instead of 1. And without using round() 1 will be the ans, then how it's correct without using round function? Am i misunderstood the word rounded *down(instead off) which means to always round off to floor value? But i sumbitted with using round() also..and why ac for that?
•  » » 12 days ago, # ^ | ← Rev. 2 →   0 i think that's just a typo, because russian statement says it should be rounded down
•  » » » 12 days ago, # ^ |   0 Then why it got also ac with using round() In case like 1.6 it gives 2 but the ans would be 1 yeah?
•  » » » » 12 days ago, # ^ |   0 Now i got the clarity. I used int and before rounding off it already converted into int .so there is no effect of round() in this situation..lol blunder by me
•  » » » » » 11 days ago, # ^ |   0 XD
 » 12 days ago, # |   0 I wrote this code for problem F During the contest.. But now I really have no idea way it works !!!!!! void calculate() { int r; cin >> r; int ans = 2; for(int x = -1*r; x <= r; x++) { ans += ((int)sqrt((r+1)*(r+1)-x*x-1)-(int)sqrt(r*r-x*x-1))*2; } cout << ans << endl; } There is a case when r*r-x*x-1 becomes negative and then sqrt(negative) !!I didn't notice that during the contest but I am really surprised to see it works!the second thing is why the answer is 2 ? when I wrote this weird solution I noticed that it get the write answer — 2 so I added two to the answerVery weired
•  » » 12 days ago, # ^ |   0 1 . Yes, $r^2 - x^2 - 1$ becomes $-1$ when $x = r$, then it will become -2147483648 (saw from code), but then you multiply it by 2, so it becomes 0 (because of the overflow).You can add this in your loop to check it out for yourself.cout << x << " " << (int)sqrt(r*r-x*x-1) << " " << (int)sqrt(r*r-x*x-1)*2 << endl;2 . It comes from first (why you need to add 2). When $x = ±r$, you have $\sqrt{2r} - 0$ instead of $\sqrt{2r} - (-1)$, so you loose 1 point for both $x = r$, and $x = -r$.
•  » » » 11 days ago, # ^ |   0 Very helpful. Thanks alot
 » 12 days ago, # |   0 In the Editorial Implementation for the problem F, when we say the overall answer is the answer per quadrant multiplied by 4, aren't we over-counting at the edges of the semi-disc (like x=0 or x=r) ?. Could anyone help figure out what I might be missing. Thanks.
•  » » 12 days ago, # ^ | ← Rev. 2 →   +1 We have counted at x = 0, but not at h = 0 (in second while statement there is h > 0 which ensures that we are not crossing x-axis).
•  » » » 11 days ago, # ^ |   0 Didn't see that. That's slick! Thanks!
 » 12 days ago, # |   0 Shouldn't this editorial be published after the end of hacking phase? [In Educational Rounds and Div3s, I usually don't see Editorials to be published before the end of Hacking Phase]
 » 12 days ago, # | ← Rev. 2 →   0 This is my solution for G if using maps, if you don't know priority_queue . Spoilervoid solve(){ read(n); vi v(n); read(v); map> mp; fori(i,n){ mp[v[i]>>2].ff.pb(v[i]); mp[v[i]>>2].ss.pb(i); } vi ans(n); for(auto e: mp){ sort(all(e.ss.ff)); fori(i, e.ss.ff.size()){ ans[e.ss.ss[i]] = e.ss.ff[i]; } } ps(ans); } 
 » 11 days ago, # |   0 I learnt programming a month ago. I gave my first contest(944 div.4) yesterday n I solved only 3 problems. I read that div.4 is rated for unrated players. But my account is still unrated. can anyone explain why? Why I didnt get any rating?
•  » » 11 days ago, # ^ |   0 raiting change will came after open hacks whic is 12 hours, and then system testing, which is also 4-5 hours, so wait
 » 11 days ago, # |   0 260473966 why is this failing? I cant seem to find the issue.
•  » » 11 days ago, # ^ |   0 res = b[prevdist] + (d - a[prevdist]) * ((b[prevdist + 1] - b[prevdist]) / (a[prevdist + 1] - a[prevdist])); is wrong since you do the division first, which would lose precision.correct version: res = b[prevdist] + (d - a[prevdist]) * (b[prevdist + 1] - b[prevdist]) / (a[prevdist + 1] - a[prevdist]);
•  » » » 9 days ago, # ^ | ← Rev. 2 →   0 Learned this three things: 1. simplifying the equation so that division operations are less resulting less floating point errors. (Though not much experienced in this, I'll be glad to accept tips!) 2. precedence (* comes before /) 3. associativity (/ comes before *)Thanks a lot, your comment helped!
 » 11 days ago, # |   0 it run well and output correct answer in my c++ ide ,but wrong on test 31, 260475302
 » 11 days ago, # |   0 In C, you say "Below is the shortest solution we know of". What about my solution? https://codeforces.com/contest/1971/submission/260294806
 » 11 days ago, # | ← Rev. 4 →   0 For Problem C 1971C - Clock and Strings, We can:1.Perform a,b,c,d = min(a,b), max(a,b), min(c,d), max(c,d) 2.Check if a
•  » » 11 days ago, # ^ |   0 interesting , can u show ur submission ?
 » 11 days ago, # |   0 If anyone is interested in solving problem H without fully implementing 2-SAT algo, here is a solution.
 » 11 days ago, # |   0 Those who used float/double in E ------------------> :(
•  » » 11 days ago, # ^ | ← Rev. 2 →   0 Then what to use there & why not use double/float?Thanks
•  » » » 9 days ago, # ^ |   0 There has been a lot of discussion on this. Check out the discussions on this blog, and you'll understand. It's actually about precision errors that occur when you convert to double/float.
 » 11 days ago, # | ← Rev. 3 →   0 Got Hacked in "E — Find the Car" due to unnecessary cast to double :( Test case1 1000000000 2 1 999999998 1000000000 999999999 1000000000 999999997 
 » 11 days ago, # |   0 my submission got hacked it gave wrong answer on test case 21 but when i run that test case on my ide other than that of cf it is giving the expected output . Can somebody help https://codeforces.com/contest/1971/submission/260487849
•  » » 11 days ago, # ^ |   0 You are given the whole input of TC21 and it's easy to calculate the real answer by hand, so you should be able to debug what went wrong in your code. The expected answer for the fourth query is: $\displaystyle \frac{45 \cdot 2}{6} = 15$. Your code produces inaccurate results due to the use of double.Basically, you shouldn't use double in this problem. It's very hard to make calculation using double right (there are more tricky edge cases; see hacks). It's possible to solve this problem with just integer arithmetic, which gives precise answers.
 » 11 days ago, # | ← Rev. 5 →   0 For someone who need a small hack test case for E Test case1 10 1 1 10 58 5 answer is 29, you might get 28 due to precision errors.
 » 11 days ago, # |   0 in problem F if we can implement a function g that returns the number of points that have a distance d
 » 11 days ago, # | ← Rev. 4 →   0 In Problem E ,I submitted the following code : My Submissionbut it gives wrong answer on test case : 1 6 1 1 6 45 2the expected output is 15 but my code's output is 14When i debug my code, i found that whole error occurs in the line long long ans=floorl(time); bcoz the value of time before was 15 but after taking floorl it became 14.I don't understand why this is happening on my system and also on online judge.Is this a bug of C++ 20?? or i have done something wrong in my code.I have also used fixed<
•  » » 11 days ago, # ^ |   0 The value of time before floorl is 14.999999999999999999, so floorl(time) is 14. Floating point arithmetic is inaccurate by design, so this is expected behavior.
•  » » » 11 days ago, # ^ |   0 what best practice should we follow when dealing with floating point arithmetic.
•  » » » 11 days ago, # ^ |   0 Ok,got it.Thanks.But don't understand while debugging why it shows time 15 instead of 14.99999999 .
•  » » » » 11 days ago, # ^ |   0 When cout/cerr prints a floating point numbers, the default precision is only 6 digits (IIRC), which is insufficient for double / long doubles. To get sufficiently accurate representation, use: cout << setprecision(30) << time << '\n'; or cout << format("{}\n", time); (the latter requires C++20).
•  » » » » » 11 days ago, # ^ |   0 Thanks,very informative.
•  » » 11 days ago, # ^ |   +1 I don't know why but changing ((dis-a[ind-1])/speed) to ((dis-a[ind-1])*(b[ind]-b[ind-1]))/(a[ind]-a[ind-1]); worksCan someone prove why it's working ?
•  » » » 11 days ago, # ^ |   0 double x=1/3; double y=3; int ans=(floor)(x*y); cout<
•  » » 11 days ago, # ^ |   0 you can't trust doubles, there can be errors. better way would be this
 » 11 days ago, # |   0 Can someone explain why this is not working ? I thought long double's precision is enough .submission : 260494210
 » 11 days ago, # |   0 flamestorm can you give solution without using atcoder library of problem H??
•  » » 11 days ago, # ^ |   0 i wrote my own 2-sat in H after contest, you can look at my solution: 260463835
 » 11 days ago, # |   0 Here i got a shorter solve of problem C 260325595 flamestorm
•  » » 11 days ago, # ^ |   0 Nice
 » 11 days ago, # |   +6 Problem F reminded me of my Computer Graphics course, where we discussed how to draw a circle efficiently on the screen. (It involves avoiding FP computation and replacing multiplication with addition.)So my solution works as follows. Let point P start at $(0, r)$. For every step, checks if $P$ falls in the range. Then, P moves to the right 1 unit, and if $|OP| \ge r+1$, revert the previous move and move P down 1 unit instead. Repeat until you reach $(r, 0)$, and multiply the answer by 4. Code#include #include #include #include #include #include #include using namespace std; typedef pair pii; typedef vector vint; typedef long long ll; const long long N = 500100; inline ll dist(ll x, ll y) { return x*x + y*y; } int main() { int z; cin >> z; while(z--){ ll n; scanf("%lld", &n); ll x = 0, y = n; ll ans = 0; while(y > 0) { ll d2 = dist(x, y); if(d2 >= n*n && d2 < (n+1) * (n+1)) // Not the fastest! ans++; if(dist(x+1, y) >= (n+1) * (n+1)) y--; else x++; } printf("%lld\n", ans<<2); } return 0; } This algorithm works because the width is 1. The reason why CG introduced this algorithm is that it never requires calculating the $|OP|^2$ by performing 2 multiplications, but you can instead calculate the increment of $|OP|^2$ in O(1) additions for each iteration.
 » 11 days ago, # | ← Rev. 3 →   0 this is my first contest on codeforces...can anybody tell me why i don't get the score yet? i did particitate in the contest during the time it was held.
•  » » 11 days ago, # ^ |   0 the contest is now retested using tests included in hacks. after this retesting phase you will get your rating
 » 11 days ago, # | ← Rev. 2 →   0 Could someone explain for me this statement from editorial of H: at least 2 of (x,y,z) are true ⟺ at least one of (x,y) is true, at least one of (y,z) is true, and at least one of (z,x) is true. I mean, without using truth table
•  » » 11 days ago, # ^ |   0 0 true variables is obviousif only one variable is true (let it be $x$) is true, then 2 out of 3 statements will evalutate to true becuase $x$ is present in two equations. but if you turn two variables true (let them be $x$ and $y$), then all 3 equations will evaluate to true (2 of which because of variable $x$ and another one because of variable $y$ which we couldn't use before)
•  » » 11 days ago, # ^ | ← Rev. 2 →   +3 It's tedious but you can obtain that by using the distributive law of boolean logic: $a \land (b \lor c) = (a \land b) \lor (a \land c)$ and $a \lor (b \land c) = (a \lor b) \land (a \lor c)$, where $\land$ means logical "and" and $\lor$ means logical "or".First, the condition "at least two of x, y, z are true" can be translated to: $(x \land y) \lor (y \land z) \lor (z \land x)$. What we want to prove is $(x \land y) \lor (y \land z) \lor (z \land x) = (x \lor y) \land (y \lor z) \land (z \lor x)$.Let's consider just the first two terms. By the distributive law, we get $(x \land y) \lor (y \land z) = (x \lor (y \land z)) \land (y \lor (y \land z)) = (x \lor y) \land (x \lor z) \land (y \lor y) \land (y \lor z)$. Since $y \lor y = y$, and $y$ must be true in this conjunction, $x \lor y$ and $y \lor z$ are always true, thus they are redundant and can be removed. Therefore we get: $(x \land y) \lor (y \land z) = (x \lor z) \land y$.You can derive $((x \lor z) \land y) \lor (z \land x) = (x \lor y) \land (y \lor z) \land (z \lor x)$ by expanding the expression in a similar manner. I leave this as your homework because I've written too much $\TeX$ s already :)
•  » » 10 days ago, # ^ |   0 Forward implication is trivial since atmost 1 variable can be false. Backward implication is also trivial. Assume 2 are false, wlog let them x, y. Then clearly there are 2 things wrong in (x, y) pair. Contradiction
 » 11 days ago, # |   0 Why am i gettng wrong answer on test case 6 in F, where the value of r is 1e5. Submission link and when I am printing it for the 1e5 case, it gives correct answer. Submission link for accepted
 » 11 days ago, # |   0 Int the problem F wouldn't be the area of the region be 2*pie*r + pie
»
11 days ago, # |
-11

In problem E

# include<bits/stdc++.h>

using namespace std; // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds;

// #define ordered_set tree<int, null_type,less, rb_tree_tag,tree_order_statistics_node_update>

# define vsz(x) ((long long) x.size())

typedef long long ll; typedef long double lld; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector vi; typedef vector vl; typedef vector vpi; typedef vector vpl; typedef long long ll; typedef unsigned long long ull; typedef long double lld;

void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << ''' << x << ''';} void __print(const char *x) {cerr << '"' << x << '"';} void __print(const string &x) {cerr << '"' << x << '"';} void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << '}';} void _print() {cerr << "]\n";} template <typename T, typename... V> void print(T t, V... v) {_print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

# endif

void solve() { // TODO: Add your code here int n,k,q; cin>>n>>k>>q; vector a(k+1); vector b(k+1);

a[0]= 0;
b[0]= 0;
for(int i=1;i<=k;i++){
cin >> a[i];
}

for(int i=1;i<=k;i++) {
cin>>b[i];

}

while(q--){
int d;
cin>>d;
int it = lower_bound(a.begin(), a.end(), d) - a.begin();

double t2,x2;
if(d==a[it]){

cout << b[it] << ' ';
continue;

}
else it--;

ll ans = b[it];
ll t = ((d-a[it])*(b[it+1]-b[it])) / (a[it+1]-a[it]);
// if(ans - int(ans) >= 0.5) ans = int(ans + 1);
// else ans = int(ans);
cout << ans + t << ' ';
}
cout << '\n';

}

int main() { #ifndef ONLINE_JUDGE freopen("Error.txt", "w", stderr); #endif send help; int _t;cin>>_t;while(_t--) solve(); return 0; }

ABOVE SOL got accepted

# include<bits/stdc++.h>

using namespace std; // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds;

// #define ordered_set tree<int, null_type,less, rb_tree_tag,tree_order_statistics_node_update>

# define vsz(x) ((long long) x.size())

typedef long long ll; typedef long double lld; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector vi; typedef vector vl; typedef vector vpi; typedef vector vpl; typedef long long ll; typedef unsigned long long ull; typedef long double lld;

void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << ''' << x << ''';} void __print(const char *x) {cerr << '"' << x << '"';} void __print(const string &x) {cerr << '"' << x << '"';} void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << '}';} void _print() {cerr << "]\n";} template <typename T, typename... V> void print(T t, V... v) {_print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

# endif

void solve() { // TODO: Add your code here int n,k,q; cin>>n>>k>>q; vector a(k+1); vector b(k+1); vector dp(k+1, 0); a[0]= 0; b[0]= 0; for(int i=1;i<=k;i++){ cin >> a[i]; }

for(int i=1;i<=k;i++) {
cin>>b[i];

}

while(q--){
double d;
cin>>d;
int it = lower_bound(a.begin(), a.end(), d) - a.begin();

double t2,x2;
if(d==a[it]){

cout << b[it] << " ";
continue;

}
else it--;

ll ans = b[it];
ll t = ((d-a[it])*(b[it+1]-b[it])) / (a[it+1]-a[it]);
// if(ans - int(ans) >= 0.5) ans = int(ans + 1);
// else ans = int(ans);
cout << ans + t << " ";
}
cout << '\n';

}

int main() { #ifndef ONLINE_JUDGE freopen("Error.txt", "w", stderr); #endif send help; int _t;cin>>_t;while(_t--) solve(); return 0; }

ABOVE got rejected

only difference is the double d and int d in the while loop query can anyone tell me whats wrong

I got hacked my initial cases were passed correctly

•  » » 11 days ago, # ^ |   0 Pro tip :always share your code as a submission link or no one is reading it. like this 260430183
 » 11 days ago, # |   +1 What is the best way to deal with precision issues when using floating points like in problem E? MY SOLUTIONThanks in advance
 » 11 days ago, # | ← Rev. 4 →   0 My very intuitive solution of problem c : 260585157
 » 10 days ago, # |   0 Can anyone help me indentifying why my code is giving runtime error for this following code in Problem G: "https://codeforces.com/contest/1971/submission/260600724"
•  » » 9 days ago, # ^ |   0 I modified your submission in 2 places. Now it can AC. See submission
•  » » » 9 days ago, # ^ |   0 Hey thanks, it got an AC. I removed the equality sign from comparator and got correct answer, but still can't figure out why removing equality sign from comparator got an AC.
•  » » » » 9 days ago, # ^ | ← Rev. 2 →   0 (Disclaimer: my claim has a little bit of rule of thumbs and informal terminologies here, since I was half unsure, half wanting to simplify the topic)Normally for programming languages, defined comparator that takes two entities $a$ and $b$ should return true if and only if $a$ should be placed before $b$, and it will look upon those comparisons returning true to dictate the final order of the list/array.Thus if you consider $a \le b$ as true, and in fact $a = b$, comparator will take both compare(a,b) and compare(b,a) as true, thus sending those two entities into an endless loop of placing one before another. This part is an undefined behavior, that different compiler implementations will have different responses to this (and in this exact case, most implementations will break your code, either through TLE or RTE).Removing equal sign will break that loop, ensuring that the array/list can be sorted in a deterministic way in the comparator's viewpoint.
•  » » » » » 9 days ago, # ^ | ← Rev. 2 →   0 Yes, your point makes lot of sense but if both the "compare" functions should return true, then the compiler should ideally make both the elements stay at their own place. Why it should end in an infinite loop ?Like it can also occur in cases when sorting an array with all elements equal
•  » » » » » » 9 days ago, # ^ |   0 This part, I apologize, I can't explain further, coz' I also don't know in-depth. It's not really supposed to be compiler's doing at this point, but how the sorting algorithm in the library works internally, and it is over my head (usually in a programming language, sorting algorithm is a hybrid of things, so without digging in I can't tell for sure).
•  » » » » » » 8 days ago, # ^ |   +3 A comparator (in c++ atleast) is supposed to return true IFF a should be placed before b. This is the standard of the language.By returning true when a = b, you are basically telling the compiler to put a before b, and also to put b before a.
 » 10 days ago, # |   -8 https://codeforces.com/problemset/submission/1971/260624825can anyone hep me how to deal with this error (wrong output format Expected integer, but "1e+009" found)thank you
•  » » 10 days ago, # ^ |   0 cout << int(b[k]) << " ";
•  » » 10 days ago, # ^ |   0 also change (b[i + 1] - b[i]) / (a[i + 1] - a[i]) * (c - a[i]); to (c - a[i])*(b[i + 1] - b[i]) / (a[i + 1] - a[i]);
 » 10 days ago, # |   0 why are we using -a[i] in editorial soln of problem G  ~~~~~ mp[a[i]>>2].push(-a[i]); ~~~~~
•  » » 9 days ago, # ^ |   0 So that priority queue gives min value instead of max value.
»
10 days ago, # |
0

~~~~~

# include <bits/stdc++.h>

using namespace std; const int M = 1000000007;

void hello() { int n; cin >> n; vector a(n); map<int, deque> f; for(int i = 0; i < n; i++) { cin >> a[i]; f[a[i] >> 2].push_back(a[i]); } for(int i = 0; i < n; i++) { if(f[a[i] >> 2].size() > 1) { sort(f[a[i] >> 2].begin(), f[a[i] >> 2].end()); } } for(int i = 0; i < n; i++) { cout << f[a[i] >> 2].front() << " "; f[a[i] >> 2].pop_front(); } cout << "\n"; }

int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; cin >> t; while(t--) { hello(); } return 0; }~~~~~

can anyone plz help me with this, getting tle on test 13

 » 9 days ago, # |   0 can anybody tell me what is wrong with my code, its giving wa on test case 3 #define int long long const int maxn=1003; vector adj[maxn]; vector adj_t[maxn]; vector topo; int colors[maxn]; bool visited[maxn]; void dfs(int node) { visited[node]=1; for(auto it:adj[node]) { if(!visited[it]) dfs(it); } topo.pb(node); } void dfs2(int node,int color) { visited[node]=1; colors[node]=color; for(auto it:adj_t[node]) { if(!visited[it]) dfs2(it,color); } } void solve(){ int n; cin>>n; for(int i=0;i<=2*n+2;i++) { adj[i].clear(); adj_t[i].clear(); } topo.clear(); memset(colors,0,sizeof(colors)); vector> arr(3,vector(n)); for(int i=0;i<3;i++) { for(int j=0;j>arr[i][j]; } for(int i=0;i> t; while (t--) { //write code here solve(); } return 0; } 
•  » » 4 days ago, # ^ |   0 for clarification i got my mistake for every clause A v B not A -> B not B -> A both these edges should be added but i just added not A -> B
 » 9 days ago, # |   0 How to correct this precision error? 260750048  Spoiler...void solve() { ll n,k,q; cin>>n>>k>>q; vectora(k),b(k); for(int i=0;i>a[i]; } for(int i=0;i>b[i]; } a.insert(a.begin(),0); b.insert(b.begin(),0); vectorspeed; k++; for(int i=1;i>num; ll idx = lower_bound(a.begin(),a.end(),num)-a.begin(); ll total= a[idx]-a[idx-1]; if(num==a[idx]){ cout<(rem) / speed[idx]; cout << fixed << setprecision(10); cout << static_cast(b[idx-1] + tm) << " "; } } cout<
•  » » 9 days ago, # ^ |   0 first of all never use float always use double or long double .But in this problem that is not enought.just write the whole formula tm = rem * (b[idx+1]-b[idx])/(a[idx+1]-a[idx])
•  » » » 9 days ago, # ^ |   0 Thanks, it all worked!
 » 9 days ago, # |   0 Hey, a question regarding problem G (in C++). My code gives TLE when using unordered_map, but is accepted when using map. Why is it so? Most of the time I am using unordered_map and in this case, although the solution is correct, it is a bit of a bummer that it gives TLE (because how would I know that the problem is the use of unordered_map).
•  » » 6 days ago, # ^ |   0 I'd assume that there are some tests (either from main or hacking phase) that exploits the hashing algorithm of unordered_map, causing enough collisions to make its operations $\mathcal{O}(n)$ instead of the average $\mathcal{O}(1)$.map is $\mathcal{O}(\log n)$ constantly so such tests are harmless to it.
 » 8 days ago, # |   0 For C can anyone find error in my code https://codeforces.com/contest/1971/submission/260905825
•  » » 6 days ago, # ^ | ← Rev. 3 →   0 Mostly precision errors to me.A few rules of thumbs: Ditch float, use double and long double when needed. float's fp16 nature has very low precision. Only use floating point numbers when there are no alternatives. Here, as the problem only requires the answer rounded down, you can do everything with int/long long, just make sure you do the correct calculating order (there is only one dividing operation per query, so do it last).
 » 8 days ago, # |   0 1971H - ±1Why in the four testcase of problem H, the case 6 1 3 -6 2 5 2 1 3 -2 -3 -6 -5 -2 -1 -3 2 3 1Say no?, the array [1, 1, 1, 1, 1, -1] doesn't works?
•  » » 7 days ago, # ^ |   0 col3 is -6 -2 -3, with array [1, 1, 1, 1, 1, -1], it would be 1 -1 -1. Sort them, we find the middle row is -1.
•  » » » 7 days ago, # ^ |   0 'each column', yeah i dont realized that until now, thanks a lot for answering and your help :D
 » 7 days ago, # |   0 6 1 3 -6 2 5 2 1 3 -2 -3 -6 -5 -2 -1 -3 2 3 1 explain this test help me I think it cout YES with [1,1,1,1,1,-1]
•  » » 7 days ago, # ^ |   0 The Sort Is in each columna, no the all of the matriz, so su need each columna only have a -1, ( the case 4, in third column dont work with [1, 1,1,1,1,-1], because you have un that column 1, -1, -1, AND sorted, you have -1, -1, 1, where you have a -1 in the middle and can't win)
 » 7 days ago, # |   0 Amazing tutorials and solutions. Thanks.
 » 6 days ago, # |   0 For G, why I use map is correct, but when I use unordered_map is timeout? 261159622
 » 5 days ago, # |   0 Could please someone explain me what is wrong with my 2-SAT implementation for the problem H? My attempt fails on the test 3 with wrong answer: https://codeforces.com/contest/1971/submission/261300539. I guess there should be a problem somewhere in a Tarjan's algorithm implementation, because earlier I used less optimized way to find SCC, and it worked up to test 7, where it timed out.
•  » » 5 days ago, # ^ |   0 Okay, I just tried to rewrite the code, and now my solution passes. If someone is interested in another correct code for problem H: https://codeforces.com/contest/1971/submission/261434608
 » 5 days ago, # |   0 My second solution to clock & string int n; int main() { cin >> n; for (;n; n--) { int a, b, c, d; cin >> a >> b >> c >> d; if (a < b) swap(a, b); if (c < d) swap(c, d); int diff1 = a - c; int diff2 = b - d; if (!((diff1 > 0) ^ (diff2 > 0)) && ((c > b && diff1 > 0) or (a > d && diff1 < 0))) { cout << "YES" << endl; } else { cout << "NO" << endl; } } return 0; } 
 » 4 days ago, # |   0 Here's a neat little solution for F, I observed that all points on the circle perimeter are touching one another, so we can just "trace" the circle and bfs every point within the correct distance. Very easy solution when you do it this way. void solve(){ int r; cin >> r; map, int> vis; queue q; q.push({0, r}); int ans = 0; while (!q.empty()) { auto [i, j] = q.front(); q.pop(); if (vis[{i, j}]++) continue; int sq = sqrt(i*i+j*j); ans += (r <= sq && sq < r+1); for (int a = -1; a <= 1; a++) { for (int b = -1; b <= 1; b++) { int new_sq = sqrt((i+a)*(i+a) + (j+b)*(j+b)); if (new_sq >= r && new_sq < r+1) q.push({i+a, j+b}); } } } cout << ans << endl; } 
 » 3 days ago, # |   0 Hi All,Can anyone help why this solution is incorrect for problem F public static void main(String[] args) { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); int test = sc.nextInt(); while (test-- > 0) { long n = sc.nextLong(); long count = 0; for (long i = n; i > 0; i--) { long high = numHigh(((n + 1L) * (n + 1L)) - (i * i)); long low = numLow((n * n) - (i * i)); count += high - low + 1L; } out.println(count * 4); } out.close(); } public static long numHigh(long sum) { long sqrt = (long) Math.sqrt((double) sum); return sqrt * sqrt == sum ? sqrt - 1L : sqrt; } public static long numLow(long sum) { long sqrt = (long) Math.sqrt((double) sum); return sqrt * sqrt == sum ? sqrt : sqrt + 1L; }