#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 < n; 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);
}
//cout << "!!! " << Get(0, elems.size()) << endl;
vi ans(x.size());
for (int i = 0; i < q; i++)
{
int pos = x[i];
Add(a[i] + 1, elems.size(), 1);
act[a[i]] = 0;
a[pos] = v[i];
a[pos] = mm[{a[pos], pos}];
act[a[i]] = 1;
Add(a[i] + 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 10
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
*/
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++)
~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
768 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
768 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
529 ms |
4064 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
768 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |