#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 |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
16 ms |
384 KB |
Output is correct |
4 |
Correct |
16 ms |
384 KB |
Output is correct |
5 |
Correct |
15 ms |
384 KB |
Output is correct |
6 |
Correct |
13 ms |
384 KB |
Output is correct |
7 |
Correct |
14 ms |
384 KB |
Output is correct |
8 |
Correct |
15 ms |
384 KB |
Output is correct |
9 |
Correct |
15 ms |
384 KB |
Output is correct |
10 |
Correct |
15 ms |
384 KB |
Output is correct |
11 |
Correct |
15 ms |
384 KB |
Output is correct |
12 |
Correct |
15 ms |
384 KB |
Output is correct |
13 |
Correct |
15 ms |
384 KB |
Output is correct |
14 |
Correct |
14 ms |
384 KB |
Output is correct |
15 |
Correct |
14 ms |
384 KB |
Output is correct |
16 |
Correct |
15 ms |
384 KB |
Output is correct |
17 |
Correct |
17 ms |
384 KB |
Output is correct |
18 |
Correct |
14 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
16 ms |
384 KB |
Output is correct |
4 |
Correct |
16 ms |
384 KB |
Output is correct |
5 |
Correct |
15 ms |
384 KB |
Output is correct |
6 |
Correct |
13 ms |
384 KB |
Output is correct |
7 |
Correct |
14 ms |
384 KB |
Output is correct |
8 |
Correct |
15 ms |
384 KB |
Output is correct |
9 |
Correct |
15 ms |
384 KB |
Output is correct |
10 |
Correct |
15 ms |
384 KB |
Output is correct |
11 |
Correct |
15 ms |
384 KB |
Output is correct |
12 |
Correct |
15 ms |
384 KB |
Output is correct |
13 |
Correct |
15 ms |
384 KB |
Output is correct |
14 |
Correct |
14 ms |
384 KB |
Output is correct |
15 |
Correct |
14 ms |
384 KB |
Output is correct |
16 |
Correct |
15 ms |
384 KB |
Output is correct |
17 |
Correct |
17 ms |
384 KB |
Output is correct |
18 |
Correct |
14 ms |
384 KB |
Output is correct |
19 |
Correct |
192 ms |
632 KB |
Output is correct |
20 |
Correct |
244 ms |
768 KB |
Output is correct |
21 |
Correct |
214 ms |
812 KB |
Output is correct |
22 |
Correct |
225 ms |
888 KB |
Output is correct |
23 |
Correct |
216 ms |
768 KB |
Output is correct |
24 |
Correct |
219 ms |
768 KB |
Output is correct |
25 |
Correct |
217 ms |
768 KB |
Output is correct |
26 |
Correct |
217 ms |
768 KB |
Output is correct |
27 |
Correct |
213 ms |
768 KB |
Output is correct |
28 |
Correct |
207 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1388 ms |
760 KB |
Output is correct |
2 |
Correct |
4822 ms |
1636 KB |
Output is correct |
3 |
Execution timed out |
9044 ms |
2432 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
16 ms |
384 KB |
Output is correct |
4 |
Correct |
16 ms |
384 KB |
Output is correct |
5 |
Correct |
15 ms |
384 KB |
Output is correct |
6 |
Correct |
13 ms |
384 KB |
Output is correct |
7 |
Correct |
14 ms |
384 KB |
Output is correct |
8 |
Correct |
15 ms |
384 KB |
Output is correct |
9 |
Correct |
15 ms |
384 KB |
Output is correct |
10 |
Correct |
15 ms |
384 KB |
Output is correct |
11 |
Correct |
15 ms |
384 KB |
Output is correct |
12 |
Correct |
15 ms |
384 KB |
Output is correct |
13 |
Correct |
15 ms |
384 KB |
Output is correct |
14 |
Correct |
14 ms |
384 KB |
Output is correct |
15 |
Correct |
14 ms |
384 KB |
Output is correct |
16 |
Correct |
15 ms |
384 KB |
Output is correct |
17 |
Correct |
17 ms |
384 KB |
Output is correct |
18 |
Correct |
14 ms |
384 KB |
Output is correct |
19 |
Correct |
192 ms |
632 KB |
Output is correct |
20 |
Correct |
244 ms |
768 KB |
Output is correct |
21 |
Correct |
214 ms |
812 KB |
Output is correct |
22 |
Correct |
225 ms |
888 KB |
Output is correct |
23 |
Correct |
216 ms |
768 KB |
Output is correct |
24 |
Correct |
219 ms |
768 KB |
Output is correct |
25 |
Correct |
217 ms |
768 KB |
Output is correct |
26 |
Correct |
217 ms |
768 KB |
Output is correct |
27 |
Correct |
213 ms |
768 KB |
Output is correct |
28 |
Correct |
207 ms |
768 KB |
Output is correct |
29 |
Correct |
1388 ms |
760 KB |
Output is correct |
30 |
Correct |
4822 ms |
1636 KB |
Output is correct |
31 |
Execution timed out |
9044 ms |
2432 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |