one unfinished
This commit is contained in:
28
CSES - CSES Problem Set/Playlist.cpp
Normal file
28
CSES - CSES Problem Set/Playlist.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// Created by darian on 07.06.24.
|
||||
//
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
using ll = long long;
|
||||
|
||||
int main() {
|
||||
int n; cin >> n;
|
||||
vector<ll> in(n);
|
||||
for (auto &e : in) cin >> e;
|
||||
int lo = 0;
|
||||
int hi = 0;
|
||||
int max_count = 1;
|
||||
set<ll> current = {in[0]};
|
||||
|
||||
while (hi < n - 1) {
|
||||
hi++;
|
||||
while (current.count(in[hi])) {
|
||||
current.erase(in[lo]);
|
||||
lo++;
|
||||
}
|
||||
current.insert(in[hi]);
|
||||
max_count = max(max_count, (int)current.size());
|
||||
}
|
||||
cout << max_count << endl;
|
||||
}
|
||||
26
CSES - CSES Problem Set/Towers.cpp
Normal file
26
CSES - CSES Problem Set/Towers.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// Created by darian on 07.06.24.
|
||||
//
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
using ll = long long;
|
||||
|
||||
int main() {
|
||||
int n; cin >> n;
|
||||
vector<ll> towers;
|
||||
for (int i{}; i < n; i++) {
|
||||
ll a; cin >> a;
|
||||
auto it = std::lower_bound(towers.begin(), towers.end(), a+1);
|
||||
if (it == towers.begin()) {
|
||||
if (towers.size()) towers[0] = a;
|
||||
else towers.insert(towers.begin(), a);
|
||||
} else if (it == towers.end()) {
|
||||
towers.push_back(a);
|
||||
} else {
|
||||
towers[it - towers.begin()] = a;
|
||||
}
|
||||
}
|
||||
|
||||
cout << towers.size() << endl;
|
||||
}
|
||||
30
CSES - CSES Problem Set/Traffic_Lights.cpp
Normal file
30
CSES - CSES Problem Set/Traffic_Lights.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// Created by darian on 07.06.24.
|
||||
//
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
using ll = long long;
|
||||
|
||||
int main() {
|
||||
ll x; cin >> x;
|
||||
int n; cin >> n;
|
||||
map<ll, int> distances;
|
||||
distances[x] = 1;
|
||||
set<pair<ll, ll>> lines = {{0, x}};
|
||||
|
||||
for (int i{}; i < n; i++) {
|
||||
ll t; cin >> t;
|
||||
auto it = lines.lower_bound({t, t});
|
||||
--it;
|
||||
auto p = *it;
|
||||
lines.erase(p);
|
||||
lines.insert({p.first, t});
|
||||
lines.insert({t, p.second});
|
||||
if (distances[p.second - p.first] == 1) distances.erase(p.second - p.first);
|
||||
distances[t - p.first]++;
|
||||
distances[p.second - t]++;
|
||||
cout << (*distances.rbegin()).first << endl;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user