PUSSY_LICKING_LOLI_69's blog

By PUSSY_LICKING_LOLI_69, history, 4 weeks ago, In English

Link to the problem: https://codeforces.me/contest/741/problem/D

I came up with a solution using Small To Large and Xor Hashing, but my time complexity is $$$O(n*log^2(n)*26)$$$, which is still not optimized enough. It got the extra $$$log$$$ from using map, and I'm not sure of how to get rid of the map. Can someone help me pls?

My Code (I switched to unordered_map and it still TLEs)

EDIT: Got rid of the map, not sure how to explain it tho. And the solution above would've WAed test 32 because i forgot to make the default value of the map to be -INF

Accepted solution: https://codeforces.me/contest/741/submission/287930415

Full text and comments »

By PUSSY_LICKING_LOLI_69, history, 4 weeks ago, In English

Given a graph with n nodes and m edges, is it possible to find the maximum number of edges such that each node is in at most one edge?

constraints:

n<=1000

m<=n*(n-1)/2

Full text and comments »

By PUSSY_LICKING_LOLI_69, history, 2 months ago, In English

Given a fixed k (k<=1e6), make an array F of size n (n<=1e6) , with F[i] be the number of ways to pick AT MOST k elements from i elements.

Is there a way to create this array efficiently?

Full text and comments »

By PUSSY_LICKING_LOLI_69, history, 2 months ago, In English

Given 2 strings $$$A$$$ and $$$B$$$, count how many $$$DIFFERENT$$$ strings that can be created by combining a prefix of $$$A$$$ and a prefix of $$$B$$$ (the prefix of $$$A$$$ is written first, then the prefix of $$$B$$$)

Constraints:

$$$|A|,|B| <= 1e5$$$

both strings only have ASCII characters from $$$a$$$ to $$$z$$$

can some one come up with a solution, I would really appreciate it :D

Full text and comments »

By PUSSY_LICKING_LOLI_69, history, 2 months ago, In English

Given an array A of size n. Do these q queries:

1 pos x: assign A[pos] = x;

2 l r k: find k-th smallest element in range [l,r]

Constraints:

n,q <= 1e5

A[i], x <= 1e9

My first aproach was to use a Wavelet tree with a BST(specifically a Treap) on each of its nodes. This gives a time complexity of O(n*log^2) and can do online queries(I still did it offline, i had to read all the input and compress the values because i don't want to make the Wavelet tree dynamic). However it has a really high constant factor and it takes 7-8 seconds to run with the full constraints.

Here's my code if you're interested (sorry if it's poorly written):

My Code

It is allowed to do queries offline, and the problem also has a tag of paralel binary search.

Can someone please show me the intended solution with paralel binary search (or even optimize my current code) ?

UPDATE: Solution founded :D https://robert1003.github.io/2020/02/05/parallel-binary-search.html#a-hrefhttpacmhdueducnshowproblemphppid5412hdu5412---crb-and-queriesa

Full text and comments »

By PUSSY_LICKING_LOLI_69, history, 2 months ago, In English

I've been messing with struct and pointers in C++ and got this problem.

This code gives an error saying " ‘x’ does not name a type " at the line marked below

struct A{
    A *a;
};

struct B{
    A *x;
    x = NULL; // this line gives error
};

What causes this and how do I fix this problem?

Full text and comments »

By PUSSY_LICKING_LOLI_69, history, 3 months ago, In English

I recently came across this problem while solving E1 of Codeforces Round 967 (Div. 2)

My original code used (a+=b)%p; and it worked perfectly with small test cases, but it gave WA when the test cases get larger. After i changed it to a =(a+b)%p; the code got accepted.

I'm a bit frustrated because it took me until after the contest was finished that i found the dumb mistake that probably stopped me from getting the Candidate Master title, so I made this post to discuss the differences between those 2 syntax to help people avoid the same mistake as me (and mostly just for me to vent T^T )

Here's my original code (Please don't pay attention to the dumb variable names hehe)

My Code

It only worked on test 1, and failed test 2. However, when i changed this line, it worked perfectly

//for(int j = 2;j<=k;j++) (dp2[i][j]+=dp2[i][j-1])%p;
for(int j = 2;j<=k;j++) dp2[i][j]=(dp2[i][j]+dp2[i][j-1])%p;

Can anyone explain why this single line broke my code? :(

Full text and comments »