#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
const int BIG = 100'000'000;
vector<pair<int, int> > val;
int seg[5'000'000], lz[5'000'000];
void pushdown(int id, int l, int r){
seg[id] += lz[id];
if(l != r){
lz[id << 1] += lz[id];
lz[id << 1 | 1] += lz[id];
}
lz[id] = 0;
}
void update(int id, int l, int r, int L, int R, int x){
if(L <= l && r <= R){
lz[id] += x;
pushdown(id, l, r);
return;
}
pushdown(id, l, r);
if(R < l || r < L) return;
int m = (l + r) >> 1;
update(id << 1, l, m, L, R, x);
update(id << 1 | 1, m + 1, r, L, R, x);
seg[id] = max(seg[id << 1], seg[id << 1 | 1]);
}
vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> V){
lz[1] = -BIG;
for(int i = 0; i < A.size(); ++i)
val.push_back({A[i], i});
for(int i = 0; i < X.size(); ++i)
val.push_back({V[i], X[i]});
sort(val.begin(), val.end());
val.erase(unique(val.begin(), val.end()), val.end());
for(int i = 0; i < A.size(); ++i)
A[i] = upper_bound(val.begin(), val.end(), make_pair(A[i], i)) - val.begin();
for(int i = 0; i < A.size(); ++i)
V[i] = upper_bound(val.begin(), val.end(), make_pair(V[i], X[i])) - val.begin();
for(int i = 0; i < A.size(); ++i){
update(1, 1, val.size(), A[i] + 1, val.size(), -1);
update(1, 1, val.size(), A[i], A[i], i + BIG);
}
vector<int> answer(X.size());
for (int i = 0; i < X.size(); ++i) {
update(1, 1, val.size(), A[X[i]] + 1, val.size(), 1);
update(1, 1, val.size(), A[X[i]], A[X[i]], - BIG - X[i]);
A[X[i]] = V[i];
update(1, 1, val.size(), A[X[i]] + 1, val.size(), -1);
update(1, 1, val.size(), A[X[i]], A[X[i]], X[i] + BIG);
answer[i]=seg[1];
}
return answer;
}
Compilation message
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:37:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for(int i = 0; i < A.size(); ++i)
| ~~^~~~~~~~~~
bubblesort2.cpp:39:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(int i = 0; i < X.size(); ++i)
| ~~^~~~~~~~~~
bubblesort2.cpp:44:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(int i = 0; i < A.size(); ++i)
| ~~^~~~~~~~~~
bubblesort2.cpp:46:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int i = 0; i < A.size(); ++i)
| ~~^~~~~~~~~~
bubblesort2.cpp:49:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for(int i = 0; i < A.size(); ++i){
| ~~^~~~~~~~~~
bubblesort2.cpp:55:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for (int i = 0; i < X.size(); ++i) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
312 KB |
Output is correct |
3 |
Correct |
5 ms |
460 KB |
Output is correct |
4 |
Correct |
5 ms |
460 KB |
Output is correct |
5 |
Correct |
5 ms |
460 KB |
Output is correct |
6 |
Correct |
5 ms |
532 KB |
Output is correct |
7 |
Correct |
5 ms |
460 KB |
Output is correct |
8 |
Correct |
6 ms |
460 KB |
Output is correct |
9 |
Correct |
7 ms |
460 KB |
Output is correct |
10 |
Correct |
7 ms |
460 KB |
Output is correct |
11 |
Correct |
5 ms |
460 KB |
Output is correct |
12 |
Correct |
5 ms |
432 KB |
Output is correct |
13 |
Correct |
5 ms |
460 KB |
Output is correct |
14 |
Correct |
5 ms |
476 KB |
Output is correct |
15 |
Correct |
5 ms |
460 KB |
Output is correct |
16 |
Correct |
5 ms |
460 KB |
Output is correct |
17 |
Correct |
5 ms |
460 KB |
Output is correct |
18 |
Correct |
5 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
312 KB |
Output is correct |
3 |
Correct |
5 ms |
460 KB |
Output is correct |
4 |
Correct |
5 ms |
460 KB |
Output is correct |
5 |
Correct |
5 ms |
460 KB |
Output is correct |
6 |
Correct |
5 ms |
532 KB |
Output is correct |
7 |
Correct |
5 ms |
460 KB |
Output is correct |
8 |
Correct |
6 ms |
460 KB |
Output is correct |
9 |
Correct |
7 ms |
460 KB |
Output is correct |
10 |
Correct |
7 ms |
460 KB |
Output is correct |
11 |
Correct |
5 ms |
460 KB |
Output is correct |
12 |
Correct |
5 ms |
432 KB |
Output is correct |
13 |
Correct |
5 ms |
460 KB |
Output is correct |
14 |
Correct |
5 ms |
476 KB |
Output is correct |
15 |
Correct |
5 ms |
460 KB |
Output is correct |
16 |
Correct |
5 ms |
460 KB |
Output is correct |
17 |
Correct |
5 ms |
460 KB |
Output is correct |
18 |
Correct |
5 ms |
460 KB |
Output is correct |
19 |
Runtime error |
22 ms |
1920 KB |
Execution killed with signal 6 |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
27 ms |
2800 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
312 KB |
Output is correct |
3 |
Correct |
5 ms |
460 KB |
Output is correct |
4 |
Correct |
5 ms |
460 KB |
Output is correct |
5 |
Correct |
5 ms |
460 KB |
Output is correct |
6 |
Correct |
5 ms |
532 KB |
Output is correct |
7 |
Correct |
5 ms |
460 KB |
Output is correct |
8 |
Correct |
6 ms |
460 KB |
Output is correct |
9 |
Correct |
7 ms |
460 KB |
Output is correct |
10 |
Correct |
7 ms |
460 KB |
Output is correct |
11 |
Correct |
5 ms |
460 KB |
Output is correct |
12 |
Correct |
5 ms |
432 KB |
Output is correct |
13 |
Correct |
5 ms |
460 KB |
Output is correct |
14 |
Correct |
5 ms |
476 KB |
Output is correct |
15 |
Correct |
5 ms |
460 KB |
Output is correct |
16 |
Correct |
5 ms |
460 KB |
Output is correct |
17 |
Correct |
5 ms |
460 KB |
Output is correct |
18 |
Correct |
5 ms |
460 KB |
Output is correct |
19 |
Runtime error |
22 ms |
1920 KB |
Execution killed with signal 6 |
20 |
Halted |
0 ms |
0 KB |
- |