#include <bits/stdc++.h>
#include "bubblesort2.h"
using namespace std;
#define ll long long
const int base = 1<<20;
const ll INF = 1e18+7;
const ll MAXN = 1e6+7;
ll tree[base<<1];
ll lazy[base<<1];
int n;
void push(ll v){
lazy[2*v] += lazy[v];
lazy[2*v+1] += lazy[v];
tree[2*v] += lazy[v];
tree[2*v+1] += lazy[v];
lazy[v] = 0;
}
ll p, k;
ll val;
void update(ll v, ll l, ll r){
if(l > k || r < p) return;
if(p <= l && r <= k){
tree[v] += val;
lazy[v] += val;
}
else{
ll mid = (l+r)/2;
push(v);
update(2*v, l, mid);
update(2*v+1, mid+1, r);
tree[v] = max(tree[2*v], tree[2*v+1]);
}
}
ll query(ll v, ll l, ll r){
if(l > k || r < p) return -INF;
if(p <= l && r <= k){
return tree[v];
}
else{
ll mid = (l+r)/2;
push(v);
auto lQ = query(2*v, l, mid);
auto rQ = query(2*v+1, mid+1, r);
return max(lQ, rQ);
}
}
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V){
n = A.size();
int Q = X.size();
vector<int> res(Q);
vector<ll> skalowanie;
for(auto i : A){
skalowanie.push_back(i);
}
for(auto i : V){
skalowanie.push_back(i);
}
sort(skalowanie.begin(), skalowanie.end());
map<int, int> skalowanie2;
for(int i = 0; i < skalowanie.size(); ++i){
if(skalowanie2[skalowanie[i]] == 0) skalowanie2[skalowanie[i]] = i+1;
}
int id = skalowanie.size();
p = 0, k = id;
val = -INF;
update(1, 1, id);
for(int i = 0; i < n; ++i){
A[i] = skalowanie2[A[i]]++;
p = 0, k = A[i]-1;
val = 1;
update(1, 1, id);
p = k = A[i];
val = INF + i;
update(1, 1, id);
}
for(int i = 0; i < Q; ++i){
p = 0, k = A[X[i]]-1;
val = -1;
update(1, 1, id);
p = k = A[X[i]];
val = -INF;
update(1, 1, id);
A[X[i]] = skalowanie2[V[i]]++;
p = 0, k = A[X[i]]-1;
val = 1;
update(1, 1, id);
p = k = A[X[i]];
val = INF + X[i];
update(1, 1, id);
p = 0, k = id;
res[i] = query(1, 1, id) - n + 1;
}
return res;
}
Compilation message
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:78:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for(int i = 0; i < skalowanie.size(); ++i){
| ~~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2384 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
4 ms |
2640 KB |
Output is correct |
4 |
Correct |
5 ms |
2640 KB |
Output is correct |
5 |
Correct |
4 ms |
2640 KB |
Output is correct |
6 |
Correct |
6 ms |
2860 KB |
Output is correct |
7 |
Correct |
4 ms |
2640 KB |
Output is correct |
8 |
Correct |
6 ms |
2896 KB |
Output is correct |
9 |
Correct |
4 ms |
2640 KB |
Output is correct |
10 |
Correct |
4 ms |
2640 KB |
Output is correct |
11 |
Correct |
4 ms |
2640 KB |
Output is correct |
12 |
Correct |
4 ms |
2640 KB |
Output is correct |
13 |
Correct |
4 ms |
2732 KB |
Output is correct |
14 |
Correct |
4 ms |
2640 KB |
Output is correct |
15 |
Correct |
4 ms |
2764 KB |
Output is correct |
16 |
Correct |
4 ms |
2640 KB |
Output is correct |
17 |
Correct |
4 ms |
2808 KB |
Output is correct |
18 |
Correct |
4 ms |
2640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2384 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
4 ms |
2640 KB |
Output is correct |
4 |
Correct |
5 ms |
2640 KB |
Output is correct |
5 |
Correct |
4 ms |
2640 KB |
Output is correct |
6 |
Correct |
6 ms |
2860 KB |
Output is correct |
7 |
Correct |
4 ms |
2640 KB |
Output is correct |
8 |
Correct |
6 ms |
2896 KB |
Output is correct |
9 |
Correct |
4 ms |
2640 KB |
Output is correct |
10 |
Correct |
4 ms |
2640 KB |
Output is correct |
11 |
Correct |
4 ms |
2640 KB |
Output is correct |
12 |
Correct |
4 ms |
2640 KB |
Output is correct |
13 |
Correct |
4 ms |
2732 KB |
Output is correct |
14 |
Correct |
4 ms |
2640 KB |
Output is correct |
15 |
Correct |
4 ms |
2764 KB |
Output is correct |
16 |
Correct |
4 ms |
2640 KB |
Output is correct |
17 |
Correct |
4 ms |
2808 KB |
Output is correct |
18 |
Correct |
4 ms |
2640 KB |
Output is correct |
19 |
Correct |
15 ms |
7648 KB |
Output is correct |
20 |
Correct |
18 ms |
8028 KB |
Output is correct |
21 |
Correct |
21 ms |
8144 KB |
Output is correct |
22 |
Correct |
18 ms |
8016 KB |
Output is correct |
23 |
Correct |
19 ms |
7872 KB |
Output is correct |
24 |
Correct |
17 ms |
7756 KB |
Output is correct |
25 |
Correct |
16 ms |
7760 KB |
Output is correct |
26 |
Correct |
15 ms |
7756 KB |
Output is correct |
27 |
Correct |
16 ms |
7760 KB |
Output is correct |
28 |
Correct |
17 ms |
7760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
7380 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2384 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
4 ms |
2640 KB |
Output is correct |
4 |
Correct |
5 ms |
2640 KB |
Output is correct |
5 |
Correct |
4 ms |
2640 KB |
Output is correct |
6 |
Correct |
6 ms |
2860 KB |
Output is correct |
7 |
Correct |
4 ms |
2640 KB |
Output is correct |
8 |
Correct |
6 ms |
2896 KB |
Output is correct |
9 |
Correct |
4 ms |
2640 KB |
Output is correct |
10 |
Correct |
4 ms |
2640 KB |
Output is correct |
11 |
Correct |
4 ms |
2640 KB |
Output is correct |
12 |
Correct |
4 ms |
2640 KB |
Output is correct |
13 |
Correct |
4 ms |
2732 KB |
Output is correct |
14 |
Correct |
4 ms |
2640 KB |
Output is correct |
15 |
Correct |
4 ms |
2764 KB |
Output is correct |
16 |
Correct |
4 ms |
2640 KB |
Output is correct |
17 |
Correct |
4 ms |
2808 KB |
Output is correct |
18 |
Correct |
4 ms |
2640 KB |
Output is correct |
19 |
Correct |
15 ms |
7648 KB |
Output is correct |
20 |
Correct |
18 ms |
8028 KB |
Output is correct |
21 |
Correct |
21 ms |
8144 KB |
Output is correct |
22 |
Correct |
18 ms |
8016 KB |
Output is correct |
23 |
Correct |
19 ms |
7872 KB |
Output is correct |
24 |
Correct |
17 ms |
7756 KB |
Output is correct |
25 |
Correct |
16 ms |
7760 KB |
Output is correct |
26 |
Correct |
15 ms |
7756 KB |
Output is correct |
27 |
Correct |
16 ms |
7760 KB |
Output is correct |
28 |
Correct |
17 ms |
7760 KB |
Output is correct |
29 |
Incorrect |
15 ms |
7380 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |