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;
#define vi vector<int>
#define all(x) x.begin(), x.end()
const int mx = (1<<20); int seg[mx*2], lz[mx*2]; vector<pair<int, int>> mp; vi ans;
void upd(int x, int y, int v, int l = 0, int r = mp.size()-1, int i = 1){
if (l > y or r < x) return;
if (l >= x and r <= y){ seg[i] += v, lz[i] += v; return; }
int m = (l+r)/2; upd(x, y, v, l, m, i*2); upd(x, y, v, m+1, r, i*2+1);
seg[i] = max(seg[i*2], seg[i*2+1])+lz[i];
}
vi countScans(vi A, vi X, vi V){
for (int i = 0; i < A.size(); i++) mp.push_back({A[i], i});
for (int i = 0; i < X.size(); i++) mp.push_back({V[i], X[i]});
sort(all(mp)); mp.erase(unique(all(mp)), mp.end());
auto lb = [&](pair<int, int> x){ return lower_bound(all(mp), x)-mp.begin(); };
auto app = [&](int i, int sgn){// i - elems less/eq
int p = lb({A[i], i}); upd(p, p, (i+1)*sgn);
p = lb({A[i], -1}); upd(p, mp.size()-1, -sgn);
};for (int i = 0; i < A.size(); i++) app(i, 1);
for (int i = 0; i < X.size(); i++){
app(X[i], -1); A[X[i]] = V[i]; app(X[i], 1);
ans.push_back(seg[1]);
}return ans;
}
Compilation message (stderr)
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:16:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | for (int i = 0; i < A.size(); i++) mp.push_back({A[i], i});
| ~~^~~~~~~~~~
bubblesort2.cpp:17:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for (int i = 0; i < X.size(); i++) mp.push_back({V[i], X[i]});
| ~~^~~~~~~~~~
bubblesort2.cpp:23:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | };for (int i = 0; i < A.size(); i++) app(i, 1);
| ~~^~~~~~~~~~
bubblesort2.cpp:24:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for (int i = 0; i < X.size(); i++){
| ~~^~~~~~~~~~
# | 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... |