hi_63

69

hi_63
2天前
#include <iostream>
#include <algorithm>
using namespace std;

const int N = 100010;

int a[N];

int main()
{
int n;
cin >> n;
for(int i = 0; i < n; i++)
cin >> a[i];

sort(a, a + n);

int res = 0;

for(int i = 0; i < n; i++)
res += abs(a[i] - a[n / 2]);

cout << res;

return 0;
}


hi_63
2天前

### 题目描述

blablabla

#### 样例

blablabla


### 算法1

blablabla

#### C++ 代码

blablabla


### 算法2

blablabla

#### C++ 代码

#include <iostream>
#include <algorithm>
using namespace std;

const int N = 100010;

int a[N];

int main()
{
int n;
cin >> n;
for(int i = 0; i < n; i++)
cin >> a[i];

sort(a, a + n);

int res = 0;

for(int i = 0; i < n; i++)
res += abs(a[i] - a[n / 2]);

cout << res;

return 0;
}


hi_63
2天前

### 题目描述

blablabla

#### 样例

blablabla


### 算法1

blablabla

#### C++ 代码

blablabla


### 算法2

blablabla

#### C++ 代码

#include <iostream>
using namespace std;

int main()
{
int a, b;
cin >> a >> b;
cout << a + b;
return 0;
}


hi_63
19天前
#include <iostream>
using namespace std;

const int N = 100010;

int m;
int e[N], l[N], r[N], idx;

//在节点a的右边插入一个数x
void insert(int a, int x)
{
e[idx] = x;
l[idx] = a, r[idx] = r[a];
l[r[a]] = idx, r[a] = idx++;
}

//删除节点a
void remove(int a)
{
l[r[a]] = l[a];
r[l[a]] = r[a];
}

int main()
{
cin >> m;

r[0] = 1, l[1] = 0;
idx = 2;

while (m--)
{
string op;
cin >> op;
int k, x;
if (op == "L")
{
cin >> x;
insert(0, x);
}
else if (op == "R")
{
cin >> x;
insert(l[1], x);
}
else if (op == "D")
{
cin >> k;
remove(k + 1);
}
else if (op == "IL")
{
cin >> k >> x;
insert(l[k + 1], x);
}
else if (op == "IR")
{
cin >> k >> x;
insert(k + 1, x);
}
}

for (int i = r[0]; i != 1; i = r[i])
cout << e[i] << ' ';

return 0;
}


hi_63
20天前
#include <iostream>
using namespace std;

const int N = 1000010;
int a[N], q[N], n, k;

int main()
{
cin >> n >> k;
for(int i = 0; i < n; i++) cin >> a[i];

int hd = 0, tl = -1;
for(int i = 0; i < n; i++)
{
if(tl >= hd && i - k + 1 > q[hd]) hd++;
while(tl >= hd && a[q[tl]] >= a[i]) tl--;
q[++tl] = i;
if(i >= k - 1) cout << a[q[hd]] << ' ';
}
cout << endl;

hd = 0, tl = -1;
for(int i = 0; i < n; i++)
{
if(tl >= hd && i - k + 1 > q[hd]) hd++;
while(tl >= hd && a[q[tl]] <= a[i]) tl--;
q[++tl] = i;
if(i >= k - 1) cout << a[q[hd]] << ' ';
}
cout << endl;

return 0;
}


hi_63
20天前
#include <iostream>
using namespace std;

const int N = 100010;
int stk[N], n, tt;

int main()
{
cin >> n;
for(int i = 0; i < n; i++)
{
int x;
cin >> x;

while(tt && stk[tt] >= x) tt--;

if(tt) cout << stk[tt] << ' ';
else cout << -1 << ' ';

stk[++tt] = x;
}

return 0;
}


hi_63
20天前
#include <iostream>
using namespace std;

const int N = 100010;
int e[N], ne[N], idx = 0, head = -1, m, k, x;
char op;

{
}

{
e[idx] = x, ne[idx] = ne[k - 1], ne[k - 1] = idx++;
}

void remove(int k)
{
ne[k - 1] = ne[ne[k - 1]];
}

int main()
{
cin >> m;

while (m--)
{
cin >> op;

if (op == 'H')
{
cin >> x;
}
else if (op == 'I')
{
cin >> k >> x;
}
else if (op == 'D')
{
cin >> k;
if (!k)
else
remove(k);
}
}

for (int i = head; i != -1; i = ne[i])
cout << e[i] << ' ';

return 0;
}


hi_63
21天前
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

typedef pair<int, int> PII;

int n;
vector<PII> segs;

void merge(vector<PII> &segs)
{
vector<PII> res;

sort(segs.begin(), segs.end());

int st = -2e9, ed = -2e9;
for (PII seg : segs)
{
if (ed < seg.first)
{
if (st != -2e9)
res.push_back({st, ed});
st = seg.first, ed = seg.second;
}
else
ed = max(ed, seg.second);
}

if (st != -2e9)
res.push_back({st, ed});

segs = res;
}

int main()
{
cin >> n;
for (int i = 0; i < n; i++)
{
int l, r;
cin >> l >> r;
segs.push_back({l, r});
}

merge(segs);

cout << segs.size();

return 0;
}


hi_63
22天前



# include [HTML_REMOVED]

using namespace std;

const int N = 100010;
int a[N], b[N];
int n, m;

void insert(int l, int r, int c)
{
b[l] += c;
b[r + 1] -= c;
}

int main()
{
cin >> n >> m;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
insert(i, i, a[i]);
}

while(m--)
{
int l, r, c;
cin >> l >> r >> c;

insert(l, r, c);
}

for(int i = 1; i <= n; i++)
{
a[i] = a[i - 1] + b[i];
cout << a[i] << ' ';
}

return 0;


}

hi_63
22天前
#include <iostream>
using namespace std;

const int N = 100010;
int a[N], s[N];
int n;

int main()
{
cin >> n;
for(int i = 0; i < n; i++) cin >> a[i];

int res = 0;
for(int i = 0, j = 0; i < n; i++)
{
s[a[i]]++;
while(s[a[i]] > 1)
{
s[a[j]] --;
j++;
}
res = max(res, i - j + 1);
}

cout << res;

return 0;
}
`