제출 #1173675

#제출 시각아이디문제언어결과실행 시간메모리
1173675belgianbotEditor (BOI15_edi)C++20
15 / 100
174 ms16472 KiB
/* AUTHOR : BELGIANBOT */ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template<typename T> void read(T& x) { cin >> x;} template<typename T1, typename T2> void read(pair<T1, T2>& p) { read(p.first), read(p.second);} template<typename T> void read(vector<T>& v) { for (auto& x : v) read(x); } template<typename T1, typename T2> void read(T1& x, T2& y) { read(x), read(y); } template<typename T1, typename T2, typename T3> void read(T1& x, T2& y, T3& z) { read(x), read(y), read(z); } template<typename T1, typename T2, typename T3, typename T4> void read(T1& x, T2& y, T3& z, T4& zz) { read(x), read(y), read(z), read(zz); } template<typename T> void print(vector<T>& v) { for (auto& x : v) cout << x << ' '; cout << endl; } #define quit(x) return (void)(cout << x << endl) #define pb push_back #define fi first #define se second #define ordered_set tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define mp make_pair #define sz(x) (int)(x.size()) #define YES cout<<"YES\n" #define NO cout<<"NO\n" #define QYES quit("YES") #define QNO quit("NO") #define cmin(a, b) a = min(a, b) #define cmax(a, b) a = max(a, b) #define int long long #define double long double const int inf = numeric_limits<int>::max() / 4; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int MOD = 1e9+7, LOG=20; void solve(); signed main() { ios::sync_with_stdio(false); cin.tie(0); int t = 1; //cin >> t; while (t--) solve(); return 0; } int k, n, m, p, q; const int N = 300000; vector<vector<int>> adj; vector<int> t; vector<pair<int,int>> state; void build() { for (int i = n-1; i>0; i--) t[i] = min(t[i<<1],t[i<<1|1]); } void update(int pos, int value) { t[pos+=n] = value; for (int i = pos >> 1; i > 0; i >>= 1) t[i] = min(t[i<<1],t[i<<1|1]); } int query(int l, int r) { int res = inf; for (l += n, r += n+1; l < r; l >>= 1, r >>= 1) { if (l&1) res = min(res, t[l++]); if (r&1) res = min(res, t[--r]); } return res; } void solve() { cin >> n; t.resize(4 * n, inf); state.resize(n); multiset<pair<int,int>> st; for (int i = 0; i < n; i++) { int a; cin >> a; if (a > 0) { state[i] = {a,i}; update(i, 0); st.insert({i,a}); } else { a = -a; int l = 0, r = i, res = 0; while (l <= r) { int mid = (r + l) / 2; int q = query(mid, r); if (q < a) { res = mid; l = mid+1; } else r = mid-1; } state[i] = state[res]; update(i, a); if (!query(res, res)) st.erase(st.lower_bound({res, -1})); else { update(state[i].se, 0); st.insert({state[i].se, state[i].fi}); } update(res, inf); } cout << (st.empty() ?0: (--st.end())->second) << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...