This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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
vi countScans(vi a, vi x, vi v)
{
int n = a.size(), q = x.size();
vi ans(q);
vi z(n);
for (int i = 0; i < n; i++)
{
for (int j = 0; j < i; j++)
{
if (a[j] > a[i])
{
z[i]++;
}
}
}
for (int i = 0; i < q; i++)
{
int fr = a[x[i]], to = v[i];
for (int j = x[i] + 1; j < n; j++)
{
z[j] -= (fr > a[j]);
z[j] += (to > a[j]);
}
a[x[i]] = v[i];
z[x[i]] = 0;
for (int j = 0; j < x[i]; j++)
{
z[x[i]] += a[j] > a[x[i]];
}
ans[i] = *max_element(all(z));
}
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
/*
4 2
1 2 3 4
0 3
2 1
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |