Submission #290529

#TimeUsernameProblemLanguageResultExecution timeMemory
290529VROOM_VARUNBubble Sort 2 (JOI18_bubblesort2)C++14
0 / 100
46 ms6004 KiB
/* ID: varunra2 LANG: C++ TASK: bubblesort2 */ #include "bubblesort2.h" #include <bits/stdc++.h> using namespace std; #ifdef DEBUG #include "lib/debug.h" #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define debug_arr(...) \ cerr << "[" << #__VA_ARGS__ << "]:", debug_arr(__VA_ARGS__) #pragma GCC diagnostic ignored "-Wsign-compare" //#pragma GCC diagnostic ignored "-Wunused-parameter" //#pragma GCC diagnostic ignored "-Wunused-variable" #else #define debug(...) 42 #endif #define EPS 1e-9 #define IN(A, B, C) assert(B <= A && A <= C) #define INF (int)1e9 #define MEM(a, b) memset(a, (b), sizeof(a)) #define MOD 1000000007 #define MP make_pair #define PB push_back #define all(cont) cont.begin(), cont.end() #define rall(cont) cont.end(), cont.begin() #define x first #define y second const double PI = acos(-1.0); typedef long long ll; typedef long double ld; typedef pair<ll, ll> PII; typedef map<int, int> MPII; typedef multiset<int> MSETI; typedef set<int> SETI; typedef set<string> SETS; typedef vector<ll> VI; typedef vector<PII> VII; typedef vector<VI> VVI; typedef vector<string> VS; #define rep(i, a, b) for (int i = a; i < (b); ++i) #define trav(a, x) for (auto& a : x) #define sz(x) (int)(x).size() typedef pair<int, int> pii; typedef vector<int> vi; #pragma GCC diagnostic ignored "-Wsign-compare" // util functions int n, q; map<ll, VII> to; void coord_comp(VI& a, VI& ind, VI& b) { for (int i = 0; i < (int)a.size(); i++) { a[i] *= (ll)(1e6); a[i] += i; } for (int i = 0; i < (int)ind.size(); i++) { b[i] *= (ll)(1e6); b[i] += ind[i]; } VI comb; for (int i = 0; i < n; i++) { to[a[i]].PB(MP(0, i)); } for (int i = 0; i < q; i++) { to[b[i]].PB(MP(1, i)); } int val = 1; trav(x, to) { trav(y, x.y) { if (y.x == 0) { a[y.y] = val++; } else { b[y.y] = val++; } } } } VI segtree; VI lazy; ll mx; void push(int l, int r, int node) { if (lazy[node] == 0) return; segtree[node] += lazy[node]; if (l != r) { lazy[2 * node + 1] += lazy[node]; lazy[2 * node + 2] += lazy[node]; } lazy[node] = 0; } void upd(int tl, int tr, int l, int r, int node, int val) { push(l, r, node); if (l > tr or r < tl) return; if (l > r) return; if (l >= tl and r <= tr) { lazy[node] += val; push(l, r, node); return; } int mid = (l + r) / 2; upd(tl, tr, l, mid, 2 * node + 1, val); upd(tl, tr, mid + 1, r, 2 * node + 2, val); segtree[node] = max(segtree[2 * node + 1], segtree[2 * node + 2]); return; } inline void upd(int l, int r, int val) { upd(l, r, 0, mx - 5, 0, val); } int qry(int tl, int tr, int l, int r, int node) { push(l, r, node); if (l > tr or r < tl) return 0; if (l > r) return 0; if (l >= tl and r <= tr) { return segtree[node]; } int mid = (l + r) / 2; return max(qry(tl, tr, l, mid, 2 * node + 1), qry(tl, tr, mid + 1, r, 2 * node + 2)); } inline int qry() { return qry(0, mx - 5, 0, mx - 5, 0); } vector<int> countScans(vector<int> aa, vector<int> indind, vector<int> valval) { n = (int)aa.size(); q = (int)indind.size(); vector<ll> a; vector<ll> ind; vector<ll> val; for (int i = 0; i < n; i++) { a.PB((ll)aa[i]); } for (int i = 0; i < q; i++) { ind.PB((ll)indind[i]); val.PB((ll)valval[i]); } to.clear(); coord_comp(a, ind, val); mx = max(*max_element(all(a)), *max_element(all(val))); mx += 10; segtree.resize(4 * mx); lazy.resize(4 * mx); for (int i = 0; i < 4 * mx; i++) { segtree[i] = 0; lazy[i] = 0; } for (int i = 0; i < n; i++) { upd(a[i], a[i], i); upd(a[i] + 1, mx - 5, -1); } vector<int> ret(q); for (int i = 0; i < q; i++) { int nind = ind[i]; int oval = a[nind]; int nval = val[i]; upd(oval, oval, -nind); upd(oval + 1, mx - 5, 1); upd(nval, nval, nind); upd(nval + 1, mx - 5, -1); ret[i] = qry(); } return ret; } // int main() { // #ifndef ONLINE_JUDGE // freopen("bubblesort2.in", "r", stdin); // freopen("bubblesort2.out", "w", stdout); // #endif // cin.sync_with_stdio(0); // cin.tie(0); // vector<int> a; // vector<int> inds; // vector<int> vals; // a = {1, 2, 3, 4}; // inds = {0, 2}; // vals = {3, 1}; // vector<int> pr = countScans(a, inds, vals); // debug(pr); // a = {1, 1, 4, 3}; // inds = {0}; // vals = {2}; // pr = countScans(a, inds, vals); // debug(pr); // return 0; // }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...