Skip to content

Commit 7756646

Browse files
ordered set begin/end problem
1 parent 927b894 commit 7756646

2 files changed

Lines changed: 140 additions & 0 deletions

File tree

CSES/movieFestivalII

22.6 KB
Binary file not shown.

CSES/movieFestivalII.cpp

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*
2+
ID: Koral Kulacoglu
3+
TASK: test
4+
LANG: C++
5+
*/
6+
7+
#include <bits/stdc++.h>
8+
9+
using namespace std;
10+
11+
typedef long long ll;
12+
typedef long double ld;
13+
typedef unsigned long long ull;
14+
typedef long double lld;
15+
typedef complex<ld> cd;
16+
17+
typedef pair<int, int> pi;
18+
typedef pair<ll,ll> pll;
19+
typedef pair<ld,ld> pld;
20+
21+
typedef vector<int> vi;
22+
typedef vector<string> vs;
23+
typedef vector<char> vc;
24+
typedef vector<ld> vld;
25+
typedef vector<ll> vll;
26+
typedef vector<pi> vpi;
27+
typedef vector<pll> vpll;
28+
typedef vector<cd> vcd;
29+
30+
template<class T> using pq = priority_queue<T>;
31+
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
32+
33+
#define FOR(i, a, b) for (int i=a; i<(b); i++)
34+
#define F0R(i, a) for (int i=0; i<(a); i++)
35+
#define FORd(i, a, b) for (int i=(a)-1; i >= b; i--)
36+
#define F0Rd(i, a) for (int i=(a)-1; i >= 0; i--)
37+
#define trav(a, x) for (auto& a : x)
38+
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
39+
40+
#define sz(x) (int)(x).size()
41+
#define all(x) x.begin(), x.end()
42+
#define mp make_pair
43+
#define pb push_back
44+
#define fir first
45+
#define sec second
46+
#define ins insert
47+
#define lbound(a, v) lower_bound(all(a), v)-a.begin()
48+
#define ubound(a, v) upper_bound(all(a), v)-a.begin()
49+
#define gcd(a, b) __gcd(a, b)
50+
#define lcm(a, b) (a*b)/gcd(a, b)
51+
52+
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
53+
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
54+
55+
void __print(int x) {cerr << x;}
56+
void __print(long x) {cerr << x;}
57+
void __print(long long x) {cerr << x;}
58+
void __print(unsigned x) {cerr << x;}
59+
void __print(unsigned long x) {cerr << x;}
60+
void __print(unsigned long long x) {cerr << x;}
61+
void __print(float x) {cerr << x;}
62+
void __print(double x) {cerr << x;}
63+
void __print(long double x) {cerr << x;}
64+
void __print(char x) {cerr << '\'' << x << '\'';}
65+
void __print(const char *x) {cerr << '\"' << x << '\"';}
66+
void __print(const string &x) {cerr << '\"' << x << '\"';}
67+
void __print(bool x) {cerr << (x ? "true" : "false");}
68+
69+
template<typename T, typename V>
70+
void __print(const pair<T, V> &x);
71+
template<typename T>
72+
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
73+
template<typename T, typename V>
74+
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
75+
void _print() {cerr << "]\n";}
76+
template <typename T, typename... V>
77+
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
78+
79+
#ifdef DEBUG
80+
#define dbg(x...) cerr <<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << endl;
81+
#else
82+
#define dbg(x...)
83+
#endif
84+
85+
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
86+
87+
struct custom_hash {
88+
size_t operator()(uint64_t x) const {
89+
x ^= rng();
90+
return x ^ (x >> 16);
91+
}
92+
};
93+
94+
const int MOD = 1000000007;
95+
const char nl = '\n';
96+
const int MX = 100001;
97+
98+
void solve() {
99+
int n, k; cin >> n >> k;
100+
vpi movies(n); FOR (i, 0, n) cin >> movies[i].fir >> movies[i].sec;
101+
102+
sort(movies.begin(), movies.end());
103+
104+
int ans = 0;
105+
multiset<int> endTimes;
106+
FOR (i, 0, n) {
107+
auto [start, end] = movies[i];
108+
109+
endTimes.ins(end);
110+
111+
while (!endTimes.empty() && *endTimes.begin() <= start) {
112+
endTimes.erase(endTimes.begin());
113+
ans++;
114+
}
115+
116+
if (sz(endTimes) > k) {
117+
auto it = endTimes.end();
118+
it--;
119+
endTimes.erase(it);
120+
}
121+
}
122+
123+
ans += sz(endTimes);
124+
125+
cout << ans << nl;
126+
}
127+
128+
int main() {
129+
cin.tie(0)->sync_with_stdio(0);
130+
cin.exceptions(cin.failbit);
131+
132+
int T = 1;
133+
// cin >> T;
134+
while(T--) {
135+
solve();
136+
}
137+
138+
return 0;
139+
}
140+

0 commit comments

Comments
 (0)