#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;
const int INF=0x3f3f3f3f;
const int N=5e5+5;
const int OFF=(1<<20);
int n, q, ma;
vector <int> sol;
vector <pii> saz;
int T[2*OFF];
int prop[2*OFF];
int F[2*N];
void propag(int pos) {
if (!prop[pos]) return;
T[pos]+=prop[pos];
if (pos<OFF) {
prop[pos*2]+=prop[pos];
prop[pos*2+1]+=prop[pos];
}
prop[pos]=0;
}
//fl=0 interval, fl=1-> postavi
void update(int a, int b, int val, int fl, int pos=1, int lo=0, int hi=OFF) {
propag(pos);
if (lo>=b || hi<=a) return;
if (lo>=a && hi<=b) {
if (fl) T[pos]=val;
else prop[pos]+=val;
propag(pos);
return;
}
int mid=(lo+hi)/2;
update(a, b, val, fl, pos*2, lo, mid);
update(a, b, val, fl, pos*2+1, mid, hi);
T[pos]=max(T[pos*2], T[pos*2+1]);
}
int query() {
propag(1);
return T[1];
}
void upd_f(int x, int val) {
for (; x<=ma; x+=x&-x) F[x]+=val;
}
int manji(int x) {
x--;
int ret=0;
for (; x>0; x-=x&-x) ret+=F[x];
return ret;
}
void postavi(int x, int val) {
update(x, x+1, val, 1);
}
#define DEBUG 0
vector<int> countScans(vector<int> A, vector<int> XX, vector<int> V){
n=A.size();
q=V.size();
for (int i=0; i<n; ++i) saz.pb(mp(A[i], i));
for (int i=0; i<q; ++i) saz.pb(mp(V[i], XX[i]));
sort(saz.begin(), saz.end());
saz.erase(unique(saz.begin(), saz.end()), saz.end());
for (int i=0; i<n; ++i) A[i]=lower_bound(saz.begin(), saz.end(), mp(A[i], i))-saz.begin()+1;
for (int i=0; i<q; ++i) V[i]=lower_bound(saz.begin(), saz.end(), mp(V[i], XX[i]))-saz.begin()+1;
#if DEBUG
printf("A: ");
for (int x:A) printf("%d ", x);
printf("\nV: ");
for (int x:V) printf("%d ", x);
printf("\n");
#endif // DEBUG
ma=(int)saz.size()+1;
for (int i=0; i<n; ++i) upd_f(A[i], 1);
fill(T, T+2*OFF, -INF);
for (int i=0; i<n; ++i) {
T[OFF+A[i]]=i-manji(A[i]);
#if DEBUG
printf("broj: %d, val: %d\n", A[i], i-manji(A[i]));
#endif
}
for (int i=OFF-1; i>0; --i) T[i]=max(T[i*2], T[i*2+1]);
for (int i=0; i<q; ++i) {
int x=A[XX[i]], y=V[i];
A[XX[i]]=y;
upd_f(x, -1);
upd_f(y, 1);
postavi(x, -INF);
postavi(y, XX[i]-manji(y));
#if DEBUG
printf("pos: %d, x: %d, y: %d\n", XX[i], x, y);
printf("nova vrijednost: %d\n", XX[i]-manji(y));
#endif // DEBUG
update(y+1, ma, -1, 0);
update(x+1, ma, 1, 0);
#if DEBUG
printf("interval [%d, %d] +1 \n", x+1, ma-1);
printf("interval [%d, %d] -1 \n", y+1, ma-1);
printf("\n\n");
#endif
sol.pb(query());
}
return sol;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8684 KB |
Output is correct |
2 |
Correct |
10 ms |
8684 KB |
Output is correct |
3 |
Correct |
14 ms |
8812 KB |
Output is correct |
4 |
Correct |
15 ms |
8940 KB |
Output is correct |
5 |
Correct |
14 ms |
8812 KB |
Output is correct |
6 |
Correct |
13 ms |
8812 KB |
Output is correct |
7 |
Correct |
14 ms |
8940 KB |
Output is correct |
8 |
Correct |
14 ms |
8812 KB |
Output is correct |
9 |
Correct |
14 ms |
8812 KB |
Output is correct |
10 |
Correct |
14 ms |
8812 KB |
Output is correct |
11 |
Correct |
13 ms |
8940 KB |
Output is correct |
12 |
Correct |
14 ms |
8812 KB |
Output is correct |
13 |
Correct |
13 ms |
8812 KB |
Output is correct |
14 |
Correct |
13 ms |
8812 KB |
Output is correct |
15 |
Correct |
13 ms |
8812 KB |
Output is correct |
16 |
Correct |
14 ms |
8812 KB |
Output is correct |
17 |
Correct |
14 ms |
8812 KB |
Output is correct |
18 |
Correct |
14 ms |
8812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8684 KB |
Output is correct |
2 |
Correct |
10 ms |
8684 KB |
Output is correct |
3 |
Correct |
14 ms |
8812 KB |
Output is correct |
4 |
Correct |
15 ms |
8940 KB |
Output is correct |
5 |
Correct |
14 ms |
8812 KB |
Output is correct |
6 |
Correct |
13 ms |
8812 KB |
Output is correct |
7 |
Correct |
14 ms |
8940 KB |
Output is correct |
8 |
Correct |
14 ms |
8812 KB |
Output is correct |
9 |
Correct |
14 ms |
8812 KB |
Output is correct |
10 |
Correct |
14 ms |
8812 KB |
Output is correct |
11 |
Correct |
13 ms |
8940 KB |
Output is correct |
12 |
Correct |
14 ms |
8812 KB |
Output is correct |
13 |
Correct |
13 ms |
8812 KB |
Output is correct |
14 |
Correct |
13 ms |
8812 KB |
Output is correct |
15 |
Correct |
13 ms |
8812 KB |
Output is correct |
16 |
Correct |
14 ms |
8812 KB |
Output is correct |
17 |
Correct |
14 ms |
8812 KB |
Output is correct |
18 |
Correct |
14 ms |
8812 KB |
Output is correct |
19 |
Correct |
31 ms |
9404 KB |
Output is correct |
20 |
Correct |
35 ms |
9452 KB |
Output is correct |
21 |
Correct |
35 ms |
9472 KB |
Output is correct |
22 |
Correct |
36 ms |
9452 KB |
Output is correct |
23 |
Correct |
42 ms |
9600 KB |
Output is correct |
24 |
Correct |
43 ms |
9452 KB |
Output is correct |
25 |
Correct |
34 ms |
9452 KB |
Output is correct |
26 |
Correct |
34 ms |
9452 KB |
Output is correct |
27 |
Correct |
34 ms |
9324 KB |
Output is correct |
28 |
Correct |
34 ms |
9324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
9704 KB |
Output is correct |
2 |
Correct |
108 ms |
11080 KB |
Output is correct |
3 |
Correct |
217 ms |
12768 KB |
Output is correct |
4 |
Correct |
204 ms |
12768 KB |
Output is correct |
5 |
Correct |
213 ms |
12768 KB |
Output is correct |
6 |
Correct |
208 ms |
12768 KB |
Output is correct |
7 |
Correct |
249 ms |
12768 KB |
Output is correct |
8 |
Correct |
210 ms |
12768 KB |
Output is correct |
9 |
Correct |
205 ms |
12896 KB |
Output is correct |
10 |
Correct |
177 ms |
12384 KB |
Output is correct |
11 |
Correct |
190 ms |
12384 KB |
Output is correct |
12 |
Correct |
183 ms |
12384 KB |
Output is correct |
13 |
Correct |
178 ms |
12384 KB |
Output is correct |
14 |
Correct |
178 ms |
12384 KB |
Output is correct |
15 |
Correct |
175 ms |
12348 KB |
Output is correct |
16 |
Correct |
180 ms |
12000 KB |
Output is correct |
17 |
Correct |
178 ms |
12128 KB |
Output is correct |
18 |
Correct |
177 ms |
12128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8684 KB |
Output is correct |
2 |
Correct |
10 ms |
8684 KB |
Output is correct |
3 |
Correct |
14 ms |
8812 KB |
Output is correct |
4 |
Correct |
15 ms |
8940 KB |
Output is correct |
5 |
Correct |
14 ms |
8812 KB |
Output is correct |
6 |
Correct |
13 ms |
8812 KB |
Output is correct |
7 |
Correct |
14 ms |
8940 KB |
Output is correct |
8 |
Correct |
14 ms |
8812 KB |
Output is correct |
9 |
Correct |
14 ms |
8812 KB |
Output is correct |
10 |
Correct |
14 ms |
8812 KB |
Output is correct |
11 |
Correct |
13 ms |
8940 KB |
Output is correct |
12 |
Correct |
14 ms |
8812 KB |
Output is correct |
13 |
Correct |
13 ms |
8812 KB |
Output is correct |
14 |
Correct |
13 ms |
8812 KB |
Output is correct |
15 |
Correct |
13 ms |
8812 KB |
Output is correct |
16 |
Correct |
14 ms |
8812 KB |
Output is correct |
17 |
Correct |
14 ms |
8812 KB |
Output is correct |
18 |
Correct |
14 ms |
8812 KB |
Output is correct |
19 |
Correct |
31 ms |
9404 KB |
Output is correct |
20 |
Correct |
35 ms |
9452 KB |
Output is correct |
21 |
Correct |
35 ms |
9472 KB |
Output is correct |
22 |
Correct |
36 ms |
9452 KB |
Output is correct |
23 |
Correct |
42 ms |
9600 KB |
Output is correct |
24 |
Correct |
43 ms |
9452 KB |
Output is correct |
25 |
Correct |
34 ms |
9452 KB |
Output is correct |
26 |
Correct |
34 ms |
9452 KB |
Output is correct |
27 |
Correct |
34 ms |
9324 KB |
Output is correct |
28 |
Correct |
34 ms |
9324 KB |
Output is correct |
29 |
Correct |
25 ms |
9704 KB |
Output is correct |
30 |
Correct |
108 ms |
11080 KB |
Output is correct |
31 |
Correct |
217 ms |
12768 KB |
Output is correct |
32 |
Correct |
204 ms |
12768 KB |
Output is correct |
33 |
Correct |
213 ms |
12768 KB |
Output is correct |
34 |
Correct |
208 ms |
12768 KB |
Output is correct |
35 |
Correct |
249 ms |
12768 KB |
Output is correct |
36 |
Correct |
210 ms |
12768 KB |
Output is correct |
37 |
Correct |
205 ms |
12896 KB |
Output is correct |
38 |
Correct |
177 ms |
12384 KB |
Output is correct |
39 |
Correct |
190 ms |
12384 KB |
Output is correct |
40 |
Correct |
183 ms |
12384 KB |
Output is correct |
41 |
Correct |
178 ms |
12384 KB |
Output is correct |
42 |
Correct |
178 ms |
12384 KB |
Output is correct |
43 |
Correct |
175 ms |
12348 KB |
Output is correct |
44 |
Correct |
180 ms |
12000 KB |
Output is correct |
45 |
Correct |
178 ms |
12128 KB |
Output is correct |
46 |
Correct |
177 ms |
12128 KB |
Output is correct |
47 |
Correct |
704 ms |
23256 KB |
Output is correct |
48 |
Correct |
2768 ms |
53320 KB |
Output is correct |
49 |
Correct |
2939 ms |
56784 KB |
Output is correct |
50 |
Correct |
2970 ms |
57140 KB |
Output is correct |
51 |
Correct |
2950 ms |
56848 KB |
Output is correct |
52 |
Correct |
2883 ms |
56832 KB |
Output is correct |
53 |
Correct |
2927 ms |
56804 KB |
Output is correct |
54 |
Correct |
2850 ms |
56904 KB |
Output is correct |
55 |
Correct |
2867 ms |
57416 KB |
Output is correct |
56 |
Correct |
2779 ms |
56904 KB |
Output is correct |
57 |
Correct |
2807 ms |
57008 KB |
Output is correct |
58 |
Correct |
2829 ms |
56928 KB |
Output is correct |
59 |
Correct |
2630 ms |
54288 KB |
Output is correct |
60 |
Correct |
2405 ms |
54312 KB |
Output is correct |
61 |
Correct |
2572 ms |
54232 KB |
Output is correct |
62 |
Correct |
2523 ms |
53448 KB |
Output is correct |
63 |
Correct |
2501 ms |
53448 KB |
Output is correct |
64 |
Correct |
2497 ms |
53308 KB |
Output is correct |
65 |
Correct |
2337 ms |
52484 KB |
Output is correct |
66 |
Correct |
2310 ms |
52612 KB |
Output is correct |
67 |
Correct |
2321 ms |
52496 KB |
Output is correct |