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 "bubblesort2.h"
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int lz[4 * N], t[4 * N];
void push(int u, int l, int r) {
t[u] += lz[u];
if(l != r) lz[2 * u] += lz[u], lz[2 * u + 1] += lz[u];
lz[u] = 0;
}
void upd(int u, int st, int en, int l, int r, int v) {
if(lz[u]) push(u, l, r);
if(l > en || r < st) return;
if(st <= l && r <= en) {
lz[u] = v;
push(u, l, r);
return;
}
int mid = (l + r) / 2;
upd(2 * u, st, en, l, mid, v); upd(2 * u + 1, st, en, mid + 1, r, v);
t[u] = max(t[2 * u], t[2 * u + 1]);
}
std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> V){
vector<pair<int,int>> v;
for(int i = 0; i < A.size(); i++) {
v.push_back({A[i], i});
}
for(int i = 0; i < X.size(); i++) {
v.push_back({V[i], X[i]});
}
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
int n = v.size();
for(int i = 1; i <= 4 * n; i++) t[i] = -N;
for(int i = 0; i < A.size(); i++) {
int x = lower_bound(v.begin(), v.end(), make_pair(A[i], i)) - v.begin() + 1;
upd(1, x, x, 1, n, +N + i);
upd(1, x + 1, n,1, n, -1);
}
vector<int> ans(X.size());
for(int i = 0; i < X.size(); i++) {
int x = lower_bound(v.begin(), v.end(), make_pair(A[X[i]], X[i])) - v.begin() + 1;
upd(1, x, x, 1, n, -X[i] - N);
upd(1, x + 1, n, 1, n, 1);
A[X[i]] = V[i];
x = lower_bound(v.begin(), v.end(), make_pair(A[X[i]], X[i])) - v.begin() + 1;
upd(1, x, x, 1, n, +N + X[i]);
upd(1, x + 1, n, 1, n, -1); // cur_ID - act_ID unda iyos max
ans[i] = t[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:25:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(int i = 0; i < A.size(); i++) {
| ~~^~~~~~~~~~
bubblesort2.cpp:28:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for(int i = 0; i < X.size(); i++) {
| ~~^~~~~~~~~~
bubblesort2.cpp:35:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for(int i = 0; i < A.size(); i++) {
| ~~^~~~~~~~~~
bubblesort2.cpp:41:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | 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... |