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;
#ifdef Nero
#include "Deb.h"
#else
#define debug(...)
#endif
const int M = 1e5 + 5;
int tree[M];
void upd (int id, int v) {
id++;
while (id < M) {
tree[id] += v;
id += id & -id;
}
}
int qry (int id) {
id++;
int ret = 0;
while (id > 0) {
ret += tree[id];
id -= id & -id;
}
return ret;
}
int count(vector<int> a) {
int ret = 0;
int n = (int) a.size();
vector<int> ord(n);
iota(ord.begin(), ord.end(), 0);
sort(ord.begin(), ord.end(), [&](int i, int j) {
return (a[ord[i]] == a[ord[j]] ? i > j : a[ord[i]] > a[ord[j]]);
});
for (int i : ord) {
ret = max(ret, qry(i));
upd(i, 1);
}
for (int i = 0; i < n; ++i) {
upd(i, -1);
}
return ret;
}
vector<int> countScans(vector<int> a, vector<int> x, vector<int> v) {
int q = (int) x.size();
vector<int> ret(q);
for (int i = 0; i < q; ++i) {
a[x[i]] = v[i];
ret[i] = count(a);
}
return ret;
}
//int main() {
//ios::sync_with_stdio(false);
//cin.tie(nullptr);
//int n, q;
//cin >> n >> q;
//vector<int> a(n);
//for (int i = 0; i < n; ++i) {
//cin >> a[i];
//}
//vector<int> x(q), v(q);
//for (int i = 0; i < q; ++i) {
//cin >> x[i] >> v[i];
//}
//vector<int> answers = countscans(a, x, v);
//for (int i : answers) {
//cout << i << '\n';
//}
//return 0;
//}
# | 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... |