Submission #417973

#TimeUsernameProblemLanguageResultExecution timeMemory
417973ACmachineThe Potion of Great Power (CEOI20_potion)C++17
56 / 100
3029 ms76424 KiB
#include <bits/stdc++.h> using namespace std; #define FOR(i, j, k, l) for(int i = (j); i < (k); i += (l)) #define FORD(i, j, k, l) for(int i = (j); i >= (k); i -= (l)) #define REP(i, n) FOR(i, 0, n, 1) #define REPD(i, n) FOR(i, n, 0, 1) #define pb push_back #define ff first #define ss second vector<int> h; const int INF = (int)2e9 + 15; struct segtree{ vector<vector<array<int, 2>>> tree; int n; segtree(){} segtree(int sz){ n = 1; while(n < sz) n *= 2; tree.resize(2 * n); } void upd(int l, int r, array<int, 2> val){upd0(l, r, 0, n, 1, val);} void upd0(int l, int r, int beg, int end, int v, array<int, 2> val){ if(beg >= l && end <= r){ tree[v].pb(val); return; } if(beg >= r || end <= l) return; int mid = (beg + end) >> 1; upd0(l, r, beg, mid, v << 1, val); upd0(l, r, mid, end, v << 1 | 1, val); } void query0(int pos, int beg, int end, int v, vector<int> &res, int val){ if(beg > pos || end <= pos) return; array<int, 2> ts = {val, -INF}; int id = lower_bound(tree[v].begin(), tree[v].end(), ts) - tree[v].begin(); FOR(i, id, tree[v].size(), 1){ if(tree[v][i][0] != val) break; res.pb(h[tree[v][i][1]]); } if(beg == pos && end == pos + 1) return; int mid = (beg + end) >> 1; query0(pos, beg, mid, v << 1, res, val); query0(pos, mid, end, v << 1 | 1, res, val); } }; segtree st; int n; void init(int N, int d, int H[]) { n = N; REP(i, N) h.pb(H[i]); } void curseChanges(int U, int A[], int B[]) { st = segtree(U + 5); map<array<int, 2>, int> edges; FOR(i, 1, U + 1, 1){ array<int, 2> tm = {A[i - 1], B[i - 1]}; if(tm[0] > tm[1]) swap(tm[0], tm[1]); if(edges.find(tm) != edges.end()){ st.upd(edges[tm], i, tm); edges.erase(tm); } else{ edges[tm] = i; } } for(auto x : edges){ auto tm = x.ff; st.upd(x.ss, U + 1, tm); } REP(i, st.tree.size()){ int up = st.tree[i].size(); REP(j, up){ auto x = st.tree[i][j]; swap(x[0], x[1]); st.tree[i].pb(x); } sort(st.tree[i].begin(), st.tree[i].end()); } } int question(int x, int y, int v) { vector<int> f; vector<int> s; st.query0(v, 0, st.n, 1, f, x); st.query0(v, 0, st.n, 1, s, y); if(f.empty() || s.empty()){ return (int)1e9; } sort(f.begin(), f.end()); sort(s.begin(), s.end()); int ans = (int)1e9 + 5; for(int x : f){ int id = lower_bound(s.begin(), s.end(), x) - s.begin(); if(id > 0){ ans = min(ans, abs(x - s[id - 1])); } if(id < (int)s.size()){ ans = min(ans, abs(x - s[id])); } } return ans; }

Compilation message (stderr)

potion.cpp: In member function 'void segtree::query0(int, int, int, int, std::vector<int>&, int)':
potion.cpp:3:44: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    3 | #define FOR(i, j, k, l) for(int i = (j); i < (k); i += (l))
      |                                            ^
potion.cpp:38:9: note: in expansion of macro 'FOR'
   38 |         FOR(i, id, tree[v].size(), 1){
      |         ^~~
potion.cpp: In function 'void curseChanges(int, int*, int*)':
potion.cpp:3:44: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::array<int, 2> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    3 | #define FOR(i, j, k, l) for(int i = (j); i < (k); i += (l))
      |                                            ^
potion.cpp:5:19: note: in expansion of macro 'FOR'
    5 | #define REP(i, n) FOR(i, 0, n, 1)
      |                   ^~~
potion.cpp:78:5: note: in expansion of macro 'REP'
   78 |     REP(i, st.tree.size()){
      |     ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...