Please, try EDU on Codeforces! New educational section with videos, subtitles, texts, and problems. ×

Qualified's blog

By Qualified, 4 days ago, In English,

In the new CodeForces program EDU, the first problem, linked here Problem here is my below solution. This works in

(credit to Zeus_NoT_Zues for pointing out that it is O(nlog(n)) I originally put O(n) :P)

O(nlog(n))
#include "bits/stdc++.h"
using namespace std;

string s;
vector<string> a;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(20);

	cin >> s;
	for(int i = (int)s.size() - 1; i >= 0; i--) {
		string x(1, s[i]);
		a.push_back(x);
	}
	for(int i = 1; i < (int)a.size(); i++) {
		a[i] += a[i - 1];
	}
	sort(a.begin(), a.end());
	cout << (int)s.size() << ' ';
	for(int i = 0; i < (int)a.size(); i++) {
		cout << (int)s.size() + 1 - (int)a.size() - 1 << ' ';
	}
	cout << endl;
}


Help would be greatly appreciated.

Read more »

 
 
 
 
  • Vote: I like it
  • 0
  • Vote: I do not like it

By Qualified, history, 6 days ago, In English,

My debugging template is:

#define ts to_string
string ts(char c) { return string(1, c); }
string ts(bool b) { return b ? "true" : "false"; }
string ts(const char* s) { return (string)s; }
string ts(string s) { return s; }
template<class A> string ts(complex<A> c) { 
	stringstream ss; ss << c; return ss.str(); }
string ts(vector<bool> v) { 
	string res = "{"; for(int i = 0; i < si(v); ++i) res += char('0' + v[i]);
	res += "}"; return res; }
template<size_t SZ> string ts(bitset<SZ> b) {
	string res = ""; for(int i = 0; i < SZ; ++i) res += char('0' + b[i]);
	return res; }
template<class A, class B> string ts(pair<A,B> p);
template<class T> string ts(T v) {
	bool fst = 1; string res = "{";
	for (const auto& x: v) {
		if (!fst) res += ", ";
		fst = 0; res += ts(x);
	}
	res += "}"; return res;
}
template<class A, class B> string ts(pair<A,B> p) {
	return "(" + ts(p.f) + ", " + ts(p.s) + ")"; }

void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
	cerr << ts(h); if (sizeof...(t)) cerr << ", ";
	DBG(t...); }
#ifdef LOCAL
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

When I type

dbg(a, n)

where 'a' is the vector name and n is the size of the vector. 'a' contains the following {1, 2, 3, 4, 5} and n = 5

it prints

[a, n]: [{1, 2, 3, 4, 5}, 5]

but I want it to print

[a]: [{1, 2, 3, 4, 5}]
[n]: [5]

without having to type

dbg(a);
dbg(n);

Is there any way to do this?

Read more »

 
 
 
 
  • Vote: I like it
  • +3
  • Vote: I do not like it

By Qualified, history, 7 days ago, In English,

I just noticed that the contest conflicts with my schedule. When I go to the contest page, I go to friends and there is no "x" button to the right of my name. MikeMirzayanov please fix this. Here it is Picture.

UPD: Has been fixed :D

Read more »

 
 
 
 
  • Vote: I like it
  • +4
  • Vote: I do not like it

By Qualified, 11 days ago, In English,

Do you write your own C++ code for cin and cout? Maybe operator overloading, templates. Like Benq. What is the code for them? Sorry for bad english. :P

Read more »

 
 
 
 
  • Vote: I like it
  • -12
  • Vote: I do not like it

By Qualified, 13 days ago, In English,

Why not use

#include <bits/extc++.h>

It has all of the policy based data structure "includes" in these articles Implicit cartesian tree in GNU C++ STL C++ STL: Policy based data structures and everything included in

#include <bits/stdtr1c++.h>

and

#include <bits/stdc++.h>

Also, with precompiled headers, it runs in about the same time as

#include <bits/stdc++.h>

Link to the file of

#include <bits/extc++.h>

Read more »

 
 
 
 
  • Vote: I like it
  • +38
  • Vote: I do not like it

By Qualified, history, 2 weeks ago, In English,

The title says it all...

Read more »

 
 
 
 
  • Vote: I like it
  • 0
  • Vote: I do not like it

By Qualified, history, 2 weeks ago, In English,

Many times, I get WA but don't know where to start when debugging, do you guys have a test case generator? Or something like that? Thanks!

Read more »

 
 
 
 
  • Vote: I like it
  • +2
  • Vote: I do not like it

By Qualified, history, 2 weeks ago, In English,

By script, I mean what method do you use to stress test your solution(code maybe?)

Read more »

 
 
 
 
  • Vote: I like it
  • +3
  • Vote: I do not like it

By Qualified, history, 3 weeks ago, In English,

In USACO, what would the ratings of the problems be on CF? Any thoughts? Like bronze problems are xyz rating silver problems are this much rating.

Read more »

 
 
 
 
  • Vote: I like it
  • +3
  • Vote: I do not like it

By Qualified, history, 3 weeks ago, In English,

I am seeing many blogs about precompiled headers and how it can decrease compilation time. I am wondering how do I do this on Vim in Windows? Thanks in advance.

Read more »

 
 
 
 
  • Vote: I like it
  • +3
  • Vote: I do not like it

By Qualified, history, 4 weeks ago, In English,

Have you ever wondered how to make your very own template? In all of the other IDEs like VSCode, Sublime have templates in which you type in a set string of characters like "cpp" and then your template appears. This is actually very simple and only requires one line of code in your .vimrc

nnoremap cpp :-1read ABC<CR>

where "ABC" is the location of that file containing your template. The "cpp" after "nnoremap" actually determines what you should type into vim in order for your template to appear. For example:

nnoremap cpp :-1read C:\Users\Qualified\Desktop\Template\template.cpp<CR>

where Qualified is the name of my computer and Template is the folder which contains the template.cpp file which holds my template.

Hope that this helped many people!

Read more »

 
 
 
 
  • Vote: I like it
  • -1
  • Vote: I do not like it

By Qualified, history, 4 weeks ago, In English,

What is your compiler flags when using Vim for C++? Where do you put them?

Read more »

 
 
 
 
  • Vote: I like it
  • +26
  • Vote: I do not like it

By Qualified, history, 4 weeks ago, In English,

When I'm using:

#define rep(i, a, b) for(int i = a; i < b; i++)
#define per(i, a, b) for(int i = a; i >= b; i--)

how do I do

for(;;)

with the

rep(i, a, b)
per(i, a, b)

Read more »

 
 
 
 
  • Vote: I like it
  • -20
  • Vote: I do not like it

By Qualified, history, 4 weeks ago, In English,

Mine was when I got a +45 rating change. Although that isn't a lot, I finally improved. Look at rating graph, kinda trash. I want to hear yours.

Read more »

 
 
 
 
  • Vote: I like it
  • +22
  • Vote: I do not like it

By Qualified, history, 4 weeks ago, In English,

I've been seeing a lot of people using debug templates but when I copy and paste it, I don't know how to use it. Is there anything that I should know? Thanks in advance.

Read more »

 
 
 
 
  • Vote: I like it
  • -7
  • Vote: I do not like it

By Qualified, history, 4 weeks ago, In English,

When you get a WA on a testcase, do you look at the test case that you failed at or do you simulate a contest by not looking at the test cases. Thanks in advance.

Read more »

 
 
 
 
  • Vote: I like it
  • -8
  • Vote: I do not like it

By Qualified, history, 5 weeks ago, In English,

I'm wondering which method is better. Thanks in advance.

Read more »

 
 
 
 
  • Vote: I like it
  • -4
  • Vote: I do not like it

By Qualified, history, 5 weeks ago, In English,

Is there a difference between std::array like array<int, 2> MyArray = {1, 2}; and int arr[2] = {1, 2}; Time complexities? Different functionalities?

Read more »

 
 
 
 
  • Vote: I like it
  • -1
  • Vote: I do not like it

By Qualified, history, 5 weeks ago, In English,

I am doing C-Maximal Value. How would you construct the greedy algorithm? Thanks in advance.

Read more »

 
 
 
 
  • Vote: I like it
  • -8
  • Vote: I do not like it

By Qualified, history, 6 weeks ago, In English,

I see people using "ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);" I personally use "ios::sync_with_stdio(0); cin.tie(0);" without the "cout.tie(0);". What is the difference? Is the first option faster than the second?

Read more »

 
 
 
 
  • Vote: I like it
  • +12
  • Vote: I do not like it

By Qualified, history, 6 weeks ago, In English,

Is there a difference in time between the two methods? Which one is better and why?

Read more »

 
 
 
 
  • Vote: I like it
  • +11
  • Vote: I do not like it

By Qualified, history, 6 weeks ago, In English,

Is there a difference between puts("Hi"); and cout << "Hi"; in time complexity or any benefit of using one over the other?

Read more »

 
 
 
 
  • Vote: I like it
  • -9
  • Vote: I do not like it

By Qualified, history, 6 weeks ago, In English,

Hi, I am trying to do 723B - Text Document Analysis and here is my code.

Code

When I input 37, which is the example input, the program just returns maxx and cnt. I don't understand this. Am I doing something wrong. BTW I am using GVim.

Read more »

 
 
 
 
  • Vote: I like it
  • -20
  • Vote: I do not like it

By Qualified, history, 6 weeks ago, In English,

I would always do if I wanted to insert 'a' into the beginning of the string. reverse(s.begin(), s.end()); s += 'a'; reverse(s.begin(), s.end()); Is there a built-in function to insert a character in the beginning of a string?

Read more »

 
 
 
 
  • Vote: I like it
  • +8
  • Vote: I do not like it

By Qualified, history, 7 weeks ago, In English,

Many problems require the use of finding the adjacent cells of a cell regarding boundaries. Is their an easy way to do this?

Read more »

 
 
 
 
  • Vote: I like it
  • +5
  • Vote: I do not like it