Submission #99636

#TimeUsernameProblemLanguageResultExecution timeMemory
99636jasony123123Bubble Sort 2 (JOI18_bubblesort2)C++11
60 / 100
9028 ms11000 KiB
#define _CRT_SECURE_NO_WARNINGS //#include "bubblesort2.h" #include <bits/stdc++.h> #include <array> //#include <ext/pb_ds/tree_policy.hpp> //#include <ext/pb_ds/assoc_container.hpp> using namespace std; //using namespace __gnu_pbds; #define FOR(i,start,end) for(int i=start;i<(int)(end);i++) #define FORE(i,start,end) for(int i=start;i<=(int)end;i++) #define RFOR(i,start,end) for(int i = start; i>end; i--) #define RFORE(i,start,end) for(int i = start; i>=end; i--) #define all(a) a.begin(), a.end() #define mt make_tuple #define mp make_pair #define v vector #define sf scanf #define pf printf #define dvar(x) cout << #x << " := " << x << "\n" #define darr(x,n) FOR(i,0,n) cout << #x << "[" << i << "]" << " := " << x[i] << "\n" typedef long long ll; typedef long double ld; typedef pair<int, int > pii; typedef pair<ll, ll> pll; //template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template<class T> void minn(T &a, T b) { a = min(a, b); } template<class T> void maxx(T &a, T b) { a = max(a, b); } void io() { #ifdef LOCAL_PROJECT freopen("input.in", "r", stdin); freopen("output.out", "w", stdout); #else #endif ios_base::sync_with_stdio(false); cin.tie(NULL); } /***************************JOI Open 18 - bubblesort***********************************/ const int inf = 1 << 20; struct LazySegTree { int sz; v<int> a; void init(int n, int val) { a = v<int>(n, val); sz = n; } int query() { int ans = 0; FOR(i, 0, sz) maxx(ans, a[i]); return ans; } void update(int lo, int hi, int val) { FORE(i, lo, hi) a[i] += val; } }; v<int> countScans(v<int> A, v<int> X, v<int> V) { int n = A.size(), q = X.size(); // compress v<pii> dat; dat.reserve(n + q); FOR(i, 0, n) dat.push_back({ A[i], i }); FOR(i, 0, q) dat.push_back({ V[i], X[i] }); sort(all(dat)); dat.resize(unique(all(dat)) - dat.begin()); FOR(i, 0, n) A[i] = lower_bound(all(dat), mp(A[i], i)) - dat.begin(); FOR(i, 0, q) V[i] = lower_bound(all(dat), mp(V[i], X[i])) - dat.begin(); // init LazySegTree tree; tree.init(dat.size(), -inf); FOR(i, 0, n) { tree.update(A[i] + 1, tree.sz - 1, -1); tree.update(A[i], A[i], inf+i); } // process q v<int> ans(q); FOR(i, 0, q) { int pos = X[i]; int _new = V[i]; int _old = A[pos]; tree.update(_old, _old, -inf - pos); tree.update(_new, _new, inf + pos); if (_new < _old) tree.update(_new + 1, _old, -1); else if (_new > _old) tree.update(_old + 1, _new, +1); A[pos] = _new; ans[i] = tree.query(); } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...