Compare commits

...

9 Commits

Author SHA1 Message Date
f15819c41d Add yet another problem. 2024-09-26 14:28:03 -03:00
e88ec279a0 Finally finish the problem
This was tough... Hopefully it mean I got better too.
2024-09-25 17:52:28 -03:00
a8ea27af8b I am losing all hope 2024-09-25 12:15:29 -03:00
7a65f9096c Another attempt at doing the problem.
Alright, at least now I'm close...
2024-09-24 23:12:30 -03:00
8ab89b4660 Start doing a new problem.
I had to leave while I was finishing this, I'll finish it
later.
2024-09-24 17:56:51 -03:00
7b07ae17d3 Add another problem from phase 2
This problem is pretty simple, just a simple dsu.
2024-09-24 15:04:35 -03:00
e616787d38 Add another problem
I knew the algorithm for this, but didn't knew how it was
called.
2024-09-24 14:51:25 -03:00
8953861485 Add another problem
HOW THE FUCK DID THIS ACTUALLY WORKED?
2024-09-23 17:40:11 -03:00
6bae5b3c39 Reorganize the repo and add another solution 2024-09-22 18:49:12 -03:00
10 changed files with 756 additions and 1 deletions

5
.gitignore vendored
View File

@ -1 +1,4 @@
build
*
!*/
!*.cpp
!.gitignore

118
2000/saldo.cpp Normal file
View File

@ -0,0 +1,118 @@
/* Problem URL: https://neps.academy/br/exercise/650 */
#include <bits/stdc++.h>
using namespace std;
#define V vector
#define rmin(a, b) a = min(a, b)
#define rmax(a, b) a = max(a, b)
#define rep(i, lim) for (size_t i = 0; i < (lim); i++)
#define nrep(i, s, lim) for (size_t i = s; i < (lim); i++)
#define repv(i, v) for (auto &i : (v))
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
#define sortv(v) sort(v.begin(), v.end())
#define all(v) (v).begin(), (v).end()
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vvvvi = vector<vvvi>;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vvvvl = vector<vvvl>;
template<class v>
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
os << vec[0];
for (size_t i = 1; i < vec.size(); i++) {
os << ' ' << vec[i];
}
os << '\n';
return os;
}
template<class v>
auto operator>>(istream &is, vector<v> &vec)->istream& {
for (auto &i : vec) {
is >> i;
}
return is;
}
template<class v>
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
for (auto &i : vec) {
os << i[0];
for (size_t j = 1; j < i.size(); j++) {
os << ' ' << i[j];
}
os << '\n';
}
return os;
}
template<class v>
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
for (auto &i : vec) {
for (auto &j : i) {
is >> j;
}
}
return is;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 0;
int n;
while (cin >> n, n) {
if (t) {
cout << '\n';
}
t++;
vl sum(n + 1);
sum[0] = 0;
for (size_t i = 1; i <= n; i++) {
ll a, b;
cin >> a >> b;
sum[i] = a - b + sum[i - 1];
}
ll ans = 0;
ll left = 0;
ll right = 0;
ll minor = 0;
ll mleft = 1;
for (size_t i = 1; i <= n; i++) {
if (sum[i - 1] < minor) {
minor = sum[i - 1];
mleft = i;
}
if (sum[i] - minor > ans || (sum[i] - minor == ans && (ll)i - mleft >= right - left)) {
ans = sum[i] - minor;
left = mleft;
right = i;
}
}
cout << "Teste " << t << '\n';
if (ans == 0) {
cout << "nenhum\n";
} else {
cout << left << ' ' << right << '\n';
}
}
}

113
2010/phase2/fusoes.cpp Normal file
View File

@ -0,0 +1,113 @@
/* Problem URL: https://br.spoj.com/problems/FUSOES1/ */
#include <bits/stdc++.h>
using namespace std;
#define V vector
#define rmin(a, b) a = min(a, b)
#define rmax(a, b) a = max(a, b)
#define rep(i, lim) for (size_t i = 0; i < (lim); i++)
#define nrep(i, s, lim) for (size_t i = s; i < (lim); i++)
#define repv(i, v) for (auto &i : (v))
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
#define sortv(v) sort(v.begin(), v.end())
#define all(v) (v).begin(), (v).end()
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vvvvi = vector<vvvi>;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vvvvl = vector<vvvl>;
template<class v>
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
os << vec[0];
for (size_t i = 1; i < vec.size(); i++) {
os << ' ' << vec[i];
}
os << '\n';
return os;
}
template<class v>
auto operator>>(istream &is, vector<v> &vec)->istream& {
for (auto &i : vec) {
is >> i;
}
return is;
}
template<class v>
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
for (auto &i : vec) {
os << i[0];
for (size_t j = 1; j < i.size(); j++) {
os << ' ' << i[j];
}
os << '\n';
}
return os;
}
template<class v>
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
for (auto &i : vec) {
for (auto &j : i) {
is >> j;
}
}
return is;
}
vi dsu;
int find_p(int a)
{
if (dsu[a] == a) {
return a;
}
return dsu[a] = find_p(dsu[a]);
}
void make_pair(int a, int b)
{
int ap = find_p(a);
int bp = find_p(b);
dsu[bp] = ap;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
dsu.resize(n);
for (size_t i = 0; i < n; i++) {
dsu[i] = i;
}
while (m--) {
char op;
int a, b;
cin >> op >> a >> b;
a--, b--;
if (op == 'C') {
cout << (find_p(a) == find_p(b) ? "S\n" : "N\n");
continue;
}
make_pair(a, b);
}
}

90
2014/phase2/corredor.cpp Normal file
View File

@ -0,0 +1,90 @@
/* Problem URL: https://neps.academy/br/exercise/76 */
#include <bits/stdc++.h>
using namespace std;
#define V vector
#define rmin(a, b) a = min(a, b)
#define rmax(a, b) a = max(a, b)
#define rep(i, lim) for (size_t i = 0; i < (lim); i++)
#define nrep(i, s, lim) for (size_t i = s; i < (lim); i++)
#define repv(i, v) for (auto &i : (v))
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
#define sortv(v) sort(v.begin(), v.end())
#define all(v) (v).begin(), (v).end()
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vvvvi = vector<vvvi>;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vvvvl = vector<vvvl>;
template<class v>
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
os << vec[0];
for (size_t i = 1; i < vec.size(); i++) {
os << ' ' << vec[i];
}
os << '\n';
return os;
}
template<class v>
auto operator>>(istream &is, vector<v> &vec)->istream& {
for (auto &i : vec) {
is >> i;
}
return is;
}
template<class v>
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
for (auto &i : vec) {
os << i[0];
for (size_t j = 1; j < i.size(); j++) {
os << ' ' << i[j];
}
os << '\n';
}
return os;
}
template<class v>
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
for (auto &i : vec) {
for (auto &j : i) {
is >> j;
}
}
return is;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
ll soma = 0;
ll maxi = 0;
while (n--) {
ll n;
cin >> n;
soma += n;
rmax(soma, 0LL);
rmax(maxi, soma);
}
cout << maxi << '\n';
}

221
2015/phase2/fila.cpp Normal file
View File

@ -0,0 +1,221 @@
/* Problem URL: https://olimpiada.ic.unicamp.br/pratique/p2/2015/f2/fila/ */
#include <bits/stdc++.h>
using namespace std;
#define V vector
#define rmin(a, b) a = min(a, b)
#define rmax(a, b) a = max(a, b)
#define rep(i, lim) for (size_t i = 0; i < (lim); i++)
#define nrep(i, s, lim) for (size_t i = s; i < (lim); i++)
#define repv(i, v) for (auto &i : (v))
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
#define sortv(v) sort(v.begin(), v.end())
#define all(v) (v).begin(), (v).end()
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vvvvi = vector<vvvi>;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vvvvl = vector<vvvl>;
template<class v>
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
os << vec[0];
for (size_t i = 1; i < vec.size(); i++) {
os << ' ' << vec[i];
}
os << '\n';
return os;
}
template<class v>
auto operator>>(istream &is, vector<v> &vec)->istream& {
for (auto &i : vec) {
is >> i;
}
return is;
}
template<class v>
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
for (auto &i : vec) {
os << i[0];
for (size_t j = 1; j < i.size(); j++) {
os << ' ' << i[j];
}
os << '\n';
}
return os;
}
template<class v>
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
for (auto &i : vec) {
for (auto &j : i) {
is >> j;
}
}
return is;
}
#define int ll
struct insertion {
int pos;
int val;
insertion(int pos, int val): pos(pos),
val(val) {}
};
struct query {
int type;
int pos;
ll val;
query() : type(0), pos(0), val(0) {}
query(int type, int pos, ll val): type(type),
pos(pos),
val(val) {}
};
vl segtree;
vl bit;
ll search(int n, int l, int r, int lim, int v)
{
if (segtree[n] <= v || l >= lim) {
return 0;
}
if (l == r) {
return l;
}
int mid = (l + r) / 2;
ll ans = segtree[n * 2 + 1] > v ? search(n * 2 + 1, mid + 1, r, lim, v) : 0;
return ans ?: search(n * 2, l, mid, lim, v);
}
void add(int i, int v = 1)
{
for (; i < bit.size(); i += (i & -i)) {
bit[i] += v;
}
}
ll get(int v)
{
ll ans = 0;
for (int i = 31; i >= 0; i--) {
ll tmp = (1 << i) + ans;
if (tmp >= bit.size()) {
continue;
}
if (bit[tmp] <= v) {
v -= bit[tmp];
ans = tmp;
}
}
if (v == 0) return ans;
return -1;
}
ll sum(int i)
{
ll ans = 0;
for (; i > 0; i -= i & -i) {
ans += bit[i];
}
return ans;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vl queue(n);
V<insertion> inserts;
// cin >> queue;
rep(i, n) {
int val;
cin >> val;
inserts.emplace_back(i, val);
}
int q;
cin >> q;
V<query> queries(q + n);
for (size_t i = 0; i < inserts.size(); i++) {
queries[i] = query(0, inserts[i].pos, inserts[i].val);
}
size_t num = inserts.size();
nrep(i, n, n + q) {
int type, pos;
ll value;
cin >> type >> pos >> value;
queries[i] = query(type, pos, value);
if (type == 0) {
num++;
}
}
vl act(num, -1);
bit.assign(queries.size() + 1, 0);
for (size_t i = 1; i <= queries.size(); i++) {
add(i);
}
for (auto itr = queries.rbegin(); itr != queries.rend(); itr++) {
auto &[t, p, v] = *itr;
if (t == 0) {
p = get(p) + 1;
add(p, -1);
continue;
}
p = get(p - 1) + 1;
}
while (act.size() != 0 && __builtin_popcount(act.size()) != 1) {
act.push_back(-1);
}
segtree.assign(act.size() * 2, -1);
bit.assign(act.size() + 1, 0);
for (auto [type, pos, value] : queries) {
// cerr << bit;
if (type == 0) {
add(pos);
act[pos - 1] = value;
segtree[act.size() + pos - 1] = value;
for (size_t i = (act.size() + pos - 1) / 2; i > 0; i /= 2) {
segtree[i] = max(segtree[i * 2], segtree[i * 2 + 1]);
}
continue;
}
int ans = search(1, 1, act.size(), pos, act[pos - 1] + value);
cout << sum(ans) << '\n';
}
}

117
2017/phase3/arranhaceu.cpp Normal file
View File

@ -0,0 +1,117 @@
#include <bits/stdc++.h>
using namespace std;
#define V vector
#define rmin(a, b) a = min(a, b)
#define rmax(a, b) a = max(a, b)
#define rep(i, lim) for (size_t i = 0; i < (lim); i++)
#define nrep(i, s, lim) for (size_t i = s; i < (lim); i++)
#define repv(i, v) for (auto &i : (v))
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
#define sortv(v) sort(v.begin(), v.end())
#define all(v) (v).begin(), (v).end()
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vvvvi = vector<vvvi>;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vvvvl = vector<vvvl>;
template<class v>
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
os << vec[0];
for (size_t i = 1; i < vec.size(); i++) {
os << ' ' << vec[i];
}
os << '\n';
return os;
}
template<class v>
auto operator>>(istream &is, vector<v> &vec)->istream& {
for (auto &i : vec) {
is >> i;
}
return is;
}
template<class v>
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
for (auto &i : vec) {
os << i[0];
for (size_t j = 1; j < i.size(); j++) {
os << ' ' << i[j];
}
os << '\n';
}
return os;
}
template<class v>
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
for (auto &i : vec) {
for (auto &j : i) {
is >> j;
}
}
return is;
}
void add(int i, int v, vl &bit)
{
for (; i < bit.size(); i += (i & -i)) {
bit[i] += v;
}
}
ll sum(int i, vl &bit)
{
ll sum = 0;
for (; i > 0; i -= (i & -i)) {
sum += bit[i];
}
return sum;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, q;
cin >> n >> q;
vl a(n);
vl bit(n + 1, 0);
cin >> a;
for (size_t i = 0; i < n; i++) {
add(i + 1, a[i], bit);
}
while (q--) {
int c;
cin >> c;
if (c) {
int k;
cin >> k;
cout << sum(k, bit) << '\n';
} else {
int i, v;
cin >> i >> v;
int prev = a[i - 1];
a[i - 1] = v;
add(i, v, bit);
add(i, -prev, bit);
}
}
}

93
2021/phase3/festa.cpp Normal file
View File

@ -0,0 +1,93 @@
#include <bits/stdc++.h>
using namespace std;
#define V vector
#define rmin(a, b) a = min(a, b)
#define rmax(a, b) a = max(a, b)
#define rep(i, lim) for (size_t i = 0; i < (lim); i++)
#define nrep(i, s, lim) for (size_t i = s; i < (lim); i++)
#define repv(i, v) for (auto &i : (v))
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
#define sortv(v) sort(v.begin(), v.end())
#define all(v) (v).begin(), (v).end()
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vvvvi = vector<vvvi>;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vvvvl = vector<vvvl>;
template<class v>
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
os << vec[0];
for (size_t i = 1; i < vec.size(); i++) {
os << ' ' << vec[i];
}
os << '\n';
return os;
}
template<class v>
auto operator>>(istream &is, vector<v> &vec)->istream& {
for (auto &i : vec) {
is >> i;
}
return is;
}
template<class v>
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
for (auto &i : vec) {
os << i[0];
for (size_t j = 1; j < i.size(); j++) {
os << ' ' << i[j];
}
os << '\n';
}
return os;
}
template<class v>
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
for (auto &i : vec) {
for (auto &j : i) {
is >> j;
}
}
return is;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n, m;
cin >> n >> m;
vl fds(m);
cin >> fds;
ll lim = n;
for (auto &i : fds) {
lim -= lim / i;
}
reverse(fds.begin(), fds.end());
for (size_t i = 0; i < lim && i < (ll)1e4; i++) {
ll act = i;
for (auto &j : fds) {
act += act / (j - 1);
}
cout << act + 1 << '\n';
}
}