#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
void read(T &x)
{
x = 0;
register int c;
while ((c = getchar()) && (c > '9' || c < '0'))
;
for (; c >= '0' && c <= '9'; c = getchar())
x = x * 10 + c - '0';
}
constexpr bool typetest = 0;
constexpr int N = 5e5 + 5;
constexpr int Inf = 1e9 + 7;
struct FenwickTree
{
int a[N * 2];
int n;
FenwickTree()
{
memset(a, 0, sizeof a);
}
void Update(int p, int v)
{
for (; p <= n; p += p & -p)
a[p] += v;
}
int Get(int p)
{
int ans(0);
for (; p; p -= p & -p)
ans += a[p];
return ans;
}
} g;
struct SegmentTree
{
int n;
int lazy[N * 8], st[N * 8];
SegmentTree()
{
memset(lazy, 0, sizeof lazy);
fill_n(st, N * 8, -Inf);
}
void Push(int id)
{
if (lazy[id] != 0)
{
if (st[id << 1] != -Inf)
st[id << 1] += lazy[id];
lazy[id << 1] += lazy[id];
if (st[id << 1 | 1] != -Inf)
st[id << 1 | 1] += lazy[id];
lazy[id << 1 | 1] += lazy[id];
lazy[id] = 0;
}
}
void Update(int id, int l, int r, const int &x, const int &v)
{
if (l > x || r < x)
return;
if (l == x && r == x)
{
st[id] = v;
return;
}
Push(id);
Update(id << 1, l, (l + r) / 2, x, v);
Update(id << 1 | 1, (l + r) / 2 + 1, r, x, v);
st[id] = max(st[id << 1], st[id << 1 | 1]);
}
void Update(int x, int v)
{
Update(1, 1, n, x, v);
}
void Update(int id, int l, int r, const int &a, const int &b, const int &v)
{
if (l > b || r < a)
return;
if (l >= a && r <= b)
{
st[id] += v;
lazy[id] += v;
return;
}
Push(id);
Update(id << 1, l, (l + r) / 2, a, b, v);
Update(id << 1 | 1, (l + r) / 2 + 1, r, a, b, v);
st[id] = max(st[id << 1], st[id << 1 | 1]);
}
void Update(int l, int r, int v)
{
Update(1, 1, n, l, r, v);
}
} f;
vector<int> s;
set<int> pos[N * 2];
int n, m;
#define Find(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin() + 1)
vector<int> countScans(vector<int> a, vector<int> x, vector<int> v)
{
vector<int> ans(x.size(), 0);
n = a.size();
m = x.size();
for (int i = 0; i < n; ++i)
s.emplace_back(a[i]);
for (int i = 0; i < m; ++i)
s.emplace_back(v[i]);
sort(s.begin(), s.end());
s.resize(unique(s.begin(), s.end()) - s.begin());
f.n = g.n = s.size();
for (int i = 0; i < n; ++i)
{
a[i] = Find(s, a[i]);
g.Update(a[i], 1);
pos[a[i]].insert(i);
}
for (int i = 0; i < (int)s.size(); ++i)
if (!pos[i + 1].empty())
f.Update(i + 1, *pos[i + 1].rbegin() + 1 - g.Get(i + 1));
for (int i = 0; i < m; ++i)
{
v[i] = Find(s, v[i]);
pos[a[x[i]]].erase(x[i]);
f.Update(a[x[i]], s.size(), 1);
g.Update(a[x[i]], -1);
if (pos[a[x[i]]].empty())
f.Update(a[x[i]], -Inf);
else
f.Update(a[x[i]], *pos[a[x[i]]].rbegin() + 1 - g.Get(a[x[i]]));
a[x[i]] = v[i];
pos[a[x[i]]].insert(x[i]);
f.Update(a[x[i]], s.size(), -1);
g.Update(a[x[i]], 1);
f.Update(v[i], *pos[v[i]].rbegin() + 1 - g.Get(v[i]));
ans[i] = f.st[1];
}
return ans;
}
Compilation message
bubblesort2.cpp: In function 'void read(T&)':
bubblesort2.cpp:12:18: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
12 | register int c;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
82500 KB |
Output is correct |
2 |
Correct |
44 ms |
82472 KB |
Output is correct |
3 |
Correct |
48 ms |
82572 KB |
Output is correct |
4 |
Correct |
49 ms |
82592 KB |
Output is correct |
5 |
Correct |
48 ms |
82592 KB |
Output is correct |
6 |
Correct |
45 ms |
82636 KB |
Output is correct |
7 |
Correct |
45 ms |
82628 KB |
Output is correct |
8 |
Correct |
44 ms |
82632 KB |
Output is correct |
9 |
Correct |
46 ms |
82520 KB |
Output is correct |
10 |
Correct |
45 ms |
82572 KB |
Output is correct |
11 |
Correct |
46 ms |
82628 KB |
Output is correct |
12 |
Correct |
53 ms |
82636 KB |
Output is correct |
13 |
Correct |
45 ms |
82640 KB |
Output is correct |
14 |
Correct |
45 ms |
82604 KB |
Output is correct |
15 |
Correct |
45 ms |
82580 KB |
Output is correct |
16 |
Correct |
45 ms |
82564 KB |
Output is correct |
17 |
Correct |
48 ms |
82628 KB |
Output is correct |
18 |
Correct |
48 ms |
82612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
82500 KB |
Output is correct |
2 |
Correct |
44 ms |
82472 KB |
Output is correct |
3 |
Correct |
48 ms |
82572 KB |
Output is correct |
4 |
Correct |
49 ms |
82592 KB |
Output is correct |
5 |
Correct |
48 ms |
82592 KB |
Output is correct |
6 |
Correct |
45 ms |
82636 KB |
Output is correct |
7 |
Correct |
45 ms |
82628 KB |
Output is correct |
8 |
Correct |
44 ms |
82632 KB |
Output is correct |
9 |
Correct |
46 ms |
82520 KB |
Output is correct |
10 |
Correct |
45 ms |
82572 KB |
Output is correct |
11 |
Correct |
46 ms |
82628 KB |
Output is correct |
12 |
Correct |
53 ms |
82636 KB |
Output is correct |
13 |
Correct |
45 ms |
82640 KB |
Output is correct |
14 |
Correct |
45 ms |
82604 KB |
Output is correct |
15 |
Correct |
45 ms |
82580 KB |
Output is correct |
16 |
Correct |
45 ms |
82564 KB |
Output is correct |
17 |
Correct |
48 ms |
82628 KB |
Output is correct |
18 |
Correct |
48 ms |
82612 KB |
Output is correct |
19 |
Correct |
57 ms |
83080 KB |
Output is correct |
20 |
Correct |
58 ms |
83140 KB |
Output is correct |
21 |
Correct |
59 ms |
83140 KB |
Output is correct |
22 |
Correct |
61 ms |
83096 KB |
Output is correct |
23 |
Correct |
57 ms |
83140 KB |
Output is correct |
24 |
Correct |
68 ms |
83140 KB |
Output is correct |
25 |
Correct |
59 ms |
83132 KB |
Output is correct |
26 |
Correct |
59 ms |
83052 KB |
Output is correct |
27 |
Correct |
56 ms |
83156 KB |
Output is correct |
28 |
Correct |
56 ms |
83140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
84120 KB |
Output is correct |
2 |
Correct |
91 ms |
85440 KB |
Output is correct |
3 |
Correct |
131 ms |
86528 KB |
Output is correct |
4 |
Correct |
160 ms |
86576 KB |
Output is correct |
5 |
Correct |
165 ms |
86468 KB |
Output is correct |
6 |
Correct |
132 ms |
86584 KB |
Output is correct |
7 |
Correct |
127 ms |
86484 KB |
Output is correct |
8 |
Correct |
125 ms |
86476 KB |
Output is correct |
9 |
Correct |
126 ms |
86512 KB |
Output is correct |
10 |
Correct |
117 ms |
86500 KB |
Output is correct |
11 |
Correct |
113 ms |
86500 KB |
Output is correct |
12 |
Correct |
107 ms |
86464 KB |
Output is correct |
13 |
Correct |
105 ms |
86600 KB |
Output is correct |
14 |
Correct |
106 ms |
86460 KB |
Output is correct |
15 |
Correct |
113 ms |
86544 KB |
Output is correct |
16 |
Correct |
101 ms |
86508 KB |
Output is correct |
17 |
Correct |
102 ms |
86460 KB |
Output is correct |
18 |
Correct |
100 ms |
86576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
82500 KB |
Output is correct |
2 |
Correct |
44 ms |
82472 KB |
Output is correct |
3 |
Correct |
48 ms |
82572 KB |
Output is correct |
4 |
Correct |
49 ms |
82592 KB |
Output is correct |
5 |
Correct |
48 ms |
82592 KB |
Output is correct |
6 |
Correct |
45 ms |
82636 KB |
Output is correct |
7 |
Correct |
45 ms |
82628 KB |
Output is correct |
8 |
Correct |
44 ms |
82632 KB |
Output is correct |
9 |
Correct |
46 ms |
82520 KB |
Output is correct |
10 |
Correct |
45 ms |
82572 KB |
Output is correct |
11 |
Correct |
46 ms |
82628 KB |
Output is correct |
12 |
Correct |
53 ms |
82636 KB |
Output is correct |
13 |
Correct |
45 ms |
82640 KB |
Output is correct |
14 |
Correct |
45 ms |
82604 KB |
Output is correct |
15 |
Correct |
45 ms |
82580 KB |
Output is correct |
16 |
Correct |
45 ms |
82564 KB |
Output is correct |
17 |
Correct |
48 ms |
82628 KB |
Output is correct |
18 |
Correct |
48 ms |
82612 KB |
Output is correct |
19 |
Correct |
57 ms |
83080 KB |
Output is correct |
20 |
Correct |
58 ms |
83140 KB |
Output is correct |
21 |
Correct |
59 ms |
83140 KB |
Output is correct |
22 |
Correct |
61 ms |
83096 KB |
Output is correct |
23 |
Correct |
57 ms |
83140 KB |
Output is correct |
24 |
Correct |
68 ms |
83140 KB |
Output is correct |
25 |
Correct |
59 ms |
83132 KB |
Output is correct |
26 |
Correct |
59 ms |
83052 KB |
Output is correct |
27 |
Correct |
56 ms |
83156 KB |
Output is correct |
28 |
Correct |
56 ms |
83140 KB |
Output is correct |
29 |
Correct |
55 ms |
84120 KB |
Output is correct |
30 |
Correct |
91 ms |
85440 KB |
Output is correct |
31 |
Correct |
131 ms |
86528 KB |
Output is correct |
32 |
Correct |
160 ms |
86576 KB |
Output is correct |
33 |
Correct |
165 ms |
86468 KB |
Output is correct |
34 |
Correct |
132 ms |
86584 KB |
Output is correct |
35 |
Correct |
127 ms |
86484 KB |
Output is correct |
36 |
Correct |
125 ms |
86476 KB |
Output is correct |
37 |
Correct |
126 ms |
86512 KB |
Output is correct |
38 |
Correct |
117 ms |
86500 KB |
Output is correct |
39 |
Correct |
113 ms |
86500 KB |
Output is correct |
40 |
Correct |
107 ms |
86464 KB |
Output is correct |
41 |
Correct |
105 ms |
86600 KB |
Output is correct |
42 |
Correct |
106 ms |
86460 KB |
Output is correct |
43 |
Correct |
113 ms |
86544 KB |
Output is correct |
44 |
Correct |
101 ms |
86508 KB |
Output is correct |
45 |
Correct |
102 ms |
86460 KB |
Output is correct |
46 |
Correct |
100 ms |
86576 KB |
Output is correct |
47 |
Correct |
576 ms |
95068 KB |
Output is correct |
48 |
Correct |
2199 ms |
119148 KB |
Output is correct |
49 |
Correct |
2349 ms |
136452 KB |
Output is correct |
50 |
Correct |
2366 ms |
136460 KB |
Output is correct |
51 |
Correct |
2355 ms |
136528 KB |
Output is correct |
52 |
Correct |
2352 ms |
136464 KB |
Output is correct |
53 |
Correct |
2314 ms |
136456 KB |
Output is correct |
54 |
Correct |
2199 ms |
136612 KB |
Output is correct |
55 |
Correct |
2296 ms |
136768 KB |
Output is correct |
56 |
Correct |
2192 ms |
136620 KB |
Output is correct |
57 |
Correct |
2290 ms |
136628 KB |
Output is correct |
58 |
Correct |
2215 ms |
136684 KB |
Output is correct |
59 |
Correct |
1994 ms |
135276 KB |
Output is correct |
60 |
Correct |
2062 ms |
135272 KB |
Output is correct |
61 |
Correct |
1984 ms |
135332 KB |
Output is correct |
62 |
Correct |
1861 ms |
135128 KB |
Output is correct |
63 |
Correct |
1897 ms |
135172 KB |
Output is correct |
64 |
Correct |
1860 ms |
135156 KB |
Output is correct |
65 |
Correct |
1691 ms |
134988 KB |
Output is correct |
66 |
Correct |
1688 ms |
135084 KB |
Output is correct |
67 |
Correct |
1672 ms |
135088 KB |
Output is correct |