Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5a0d8f2

Browse files
Added problems
1 parent 5e44bda commit 5a0d8f2

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
typedef long int li;
6+
typedef long long int lli;
7+
typedef vector<long long int> vlli;
8+
typedef vector<int> vi;
9+
typedef stack<long long int> slli;
10+
11+
/*
12+
13+
METHOD 1: Multiset using custom operator sorts according to distance
14+
15+
struct Comparator
16+
{
17+
bool operator()(pair<lli, lli> const &p1, pair<lli, lli> const &p2)
18+
{
19+
return (p1.second - p1.first) > (p2.second - p2.first);
20+
}
21+
};
22+
23+
void task()
24+
{
25+
26+
lli x, n;
27+
cin >> x >> n;
28+
29+
multiset<pair<lli, lli>, Comparator> streets;
30+
31+
streets.insert(make_pair(0, x));
32+
33+
lli location;
34+
35+
vector<lli> response;
36+
37+
for (lli i = 0; i < n; i++)
38+
{
39+
40+
cin >> location;
41+
42+
auto it = streets.begin();
43+
44+
for (; it != streets.end(); it++)
45+
{
46+
if (location > (*it).first && location < (*it).second)
47+
{
48+
break;
49+
}
50+
}
51+
52+
lli start = (*it).first;
53+
lli end = (*it).second;
54+
55+
streets.erase(it);
56+
57+
streets.insert(make_pair(start, location));
58+
streets.insert(make_pair(location, end));
59+
60+
auto top = *streets.begin();
61+
62+
response.emplace_back(top.second - top.first);
63+
}
64+
65+
for (auto res : response)
66+
{
67+
cout << res << ' ';
68+
}
69+
70+
cout << '\n';
71+
}
72+
73+
*/
74+
75+
void task()
76+
{
77+
78+
lli x, n;
79+
cin >> x >> n;
80+
81+
set<lli> points{0, x};
82+
multiset<lli> lengths{x};
83+
84+
lli point;
85+
86+
for (int i = 0; i < n; i++)
87+
{
88+
cin >> point;
89+
90+
auto it = points.upper_bound(point);
91+
92+
auto left = *prev(it);
93+
auto right = *it;
94+
95+
lengths.erase(lengths.find(right - left));
96+
97+
lengths.insert(point - left);
98+
lengths.insert(right - point);
99+
100+
points.insert(it, point);
101+
102+
cout << *lengths.rbegin() << ' ';
103+
}
104+
105+
cout << '\n';
106+
}
107+
108+
int main()
109+
{
110+
111+
ios::sync_with_stdio(0);
112+
cin.tie(0);
113+
114+
task();
115+
116+
return 0;
117+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /