#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL
const int N = 1000002;
int tree[N];
int push[N];
int act[N];
void Add(int l, int r, int x)
{
for (int i = l; i < r; i++) tree[i] += x;
}
int Get(int l, int r)
{
int res = 0;
for (int i = l; i < r; i++) if (act[i]) res = max(res, tree[i]);
return res;
}
vi countScans(vi a, vi x, vi v)
{
vector<pair<int, int> > elems;
int n = a.size();
int q = x.size();
for (int i = 0; i < n; i++)
{
elems.push_back({a[i], i});
}
for (int i = 0; i < q; i++)
{
elems.push_back({v[i], x[i]});
}
uniq(elems);
map<pii, int> mm;
for (int i = 0; i < elems.size(); i++)
{
mm[elems[i]] = i;
}
for (int i = 0; i < elems.size(); i++)
{
tree[i] = elems[i].second;
}
for (int i = 0; i < n; i++)
{
a[i] = mm[{a[i], i}];
act[a[i]] = 1;
Add(a[i] + 1, elems.size(), -1);
}
vi ans(q);
for (int i = 0; i < q; i++)
{
int pos = x[i];
Add(a[pos] + 1, elems.size(), 1);
act[a[pos]] = 0;
a[pos] = v[i];
a[pos] = mm[{a[pos], pos}];
act[a[pos]] = 1;
Add(a[pos] + 1, elems.size(), -1);
ans[i] = Get(0, elems.size());
}
return ans;
}
#ifdef LOCAL
signed main()
{
int n, q;
cin >> n >> q;
vi a(n), x(q), v(q);
forn(i, n) cin >> a[i];
forn(i, q) cin >> x[i] >> v[i];
vi ans = countScans(a, x, v);
forn(i, q) cout << ans[i] << "\n";
}
#endif // LOCAL
/*
10 20
1 2 3 4 5 1 2 3 4 5
0 10
1 9
2 8
3 7
4 6
5 5
6 4
7 3
8 2
9 1
0 10
1 9
2 8
3 7
4 6
5 5
6 4
7 3
8 2
9 1
*/
Compilation message
bubblesort2.cpp: In function 'vi countScans(vi, vi, vi)':
bubblesort2.cpp:64:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < elems.size(); i++)
~~^~~~~~~~~~~~~~
bubblesort2.cpp:68:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < elems.size(); i++)
~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
7 ms |
512 KB |
Output is correct |
3 |
Correct |
34 ms |
768 KB |
Output is correct |
4 |
Correct |
33 ms |
768 KB |
Output is correct |
5 |
Correct |
33 ms |
768 KB |
Output is correct |
6 |
Correct |
30 ms |
768 KB |
Output is correct |
7 |
Correct |
32 ms |
768 KB |
Output is correct |
8 |
Correct |
32 ms |
768 KB |
Output is correct |
9 |
Correct |
34 ms |
768 KB |
Output is correct |
10 |
Correct |
25 ms |
768 KB |
Output is correct |
11 |
Correct |
25 ms |
760 KB |
Output is correct |
12 |
Correct |
25 ms |
768 KB |
Output is correct |
13 |
Correct |
22 ms |
640 KB |
Output is correct |
14 |
Correct |
24 ms |
768 KB |
Output is correct |
15 |
Correct |
24 ms |
760 KB |
Output is correct |
16 |
Correct |
20 ms |
640 KB |
Output is correct |
17 |
Correct |
20 ms |
640 KB |
Output is correct |
18 |
Correct |
20 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
7 ms |
512 KB |
Output is correct |
3 |
Correct |
34 ms |
768 KB |
Output is correct |
4 |
Correct |
33 ms |
768 KB |
Output is correct |
5 |
Correct |
33 ms |
768 KB |
Output is correct |
6 |
Correct |
30 ms |
768 KB |
Output is correct |
7 |
Correct |
32 ms |
768 KB |
Output is correct |
8 |
Correct |
32 ms |
768 KB |
Output is correct |
9 |
Correct |
34 ms |
768 KB |
Output is correct |
10 |
Correct |
25 ms |
768 KB |
Output is correct |
11 |
Correct |
25 ms |
760 KB |
Output is correct |
12 |
Correct |
25 ms |
768 KB |
Output is correct |
13 |
Correct |
22 ms |
640 KB |
Output is correct |
14 |
Correct |
24 ms |
768 KB |
Output is correct |
15 |
Correct |
24 ms |
760 KB |
Output is correct |
16 |
Correct |
20 ms |
640 KB |
Output is correct |
17 |
Correct |
20 ms |
640 KB |
Output is correct |
18 |
Correct |
20 ms |
640 KB |
Output is correct |
19 |
Correct |
493 ms |
1792 KB |
Output is correct |
20 |
Correct |
651 ms |
2040 KB |
Output is correct |
21 |
Correct |
589 ms |
2040 KB |
Output is correct |
22 |
Correct |
648 ms |
2044 KB |
Output is correct |
23 |
Correct |
449 ms |
1792 KB |
Output is correct |
24 |
Correct |
454 ms |
1792 KB |
Output is correct |
25 |
Correct |
401 ms |
1784 KB |
Output is correct |
26 |
Correct |
405 ms |
1784 KB |
Output is correct |
27 |
Correct |
352 ms |
1664 KB |
Output is correct |
28 |
Correct |
356 ms |
1664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
357 ms |
3060 KB |
Output is correct |
2 |
Correct |
8121 ms |
6640 KB |
Output is correct |
3 |
Execution timed out |
9071 ms |
10220 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
7 ms |
512 KB |
Output is correct |
3 |
Correct |
34 ms |
768 KB |
Output is correct |
4 |
Correct |
33 ms |
768 KB |
Output is correct |
5 |
Correct |
33 ms |
768 KB |
Output is correct |
6 |
Correct |
30 ms |
768 KB |
Output is correct |
7 |
Correct |
32 ms |
768 KB |
Output is correct |
8 |
Correct |
32 ms |
768 KB |
Output is correct |
9 |
Correct |
34 ms |
768 KB |
Output is correct |
10 |
Correct |
25 ms |
768 KB |
Output is correct |
11 |
Correct |
25 ms |
760 KB |
Output is correct |
12 |
Correct |
25 ms |
768 KB |
Output is correct |
13 |
Correct |
22 ms |
640 KB |
Output is correct |
14 |
Correct |
24 ms |
768 KB |
Output is correct |
15 |
Correct |
24 ms |
760 KB |
Output is correct |
16 |
Correct |
20 ms |
640 KB |
Output is correct |
17 |
Correct |
20 ms |
640 KB |
Output is correct |
18 |
Correct |
20 ms |
640 KB |
Output is correct |
19 |
Correct |
493 ms |
1792 KB |
Output is correct |
20 |
Correct |
651 ms |
2040 KB |
Output is correct |
21 |
Correct |
589 ms |
2040 KB |
Output is correct |
22 |
Correct |
648 ms |
2044 KB |
Output is correct |
23 |
Correct |
449 ms |
1792 KB |
Output is correct |
24 |
Correct |
454 ms |
1792 KB |
Output is correct |
25 |
Correct |
401 ms |
1784 KB |
Output is correct |
26 |
Correct |
405 ms |
1784 KB |
Output is correct |
27 |
Correct |
352 ms |
1664 KB |
Output is correct |
28 |
Correct |
356 ms |
1664 KB |
Output is correct |
29 |
Correct |
357 ms |
3060 KB |
Output is correct |
30 |
Correct |
8121 ms |
6640 KB |
Output is correct |
31 |
Execution timed out |
9071 ms |
10220 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |