# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
766495 | 2023-06-25T17:16:31 Z | nnhzzz | medians (balkan11_medians) | C++14 | 83 ms | 12800 KB |
// cre: Nguyen Ngoc Hung - Train VOI 2024 :> #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <unordered_set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #include <cstring> #include <unordered_map> #include <cmath> #include <cassert> #include <random> using namespace std; #define uniquev(v) sort(all(v)),(v).resize(unique(all(v))-(v).begin()) #define __nnhzzz__ signed main() #define reset(x,val) memset((x),(val),sizeof(x)) #define bit(i,j) ((i>>j)&1LL) #define mask(i) (1LL<<i) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define sz(x) (int)(x).size() #define fi first #define se second #define INF 0x3f3f3f3f typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ldb; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pii> vpii; const int oo = 1e9+197; const int maxn = 1e5+7,N = 1e2+3; const int MOD = 1e9+7,MOD1 = 1e9+207,MOD2 = 1e9+407,MOD3 = 998244353; template<typename T1, typename T2> bool mini(T1 &a, T2 b){if(a>b){a=b;return true;}return false;} template<typename T1, typename T2> bool maxi(T1 &a, T2 b){if(a<b){a=b;return true;}return false;} template<typename T> T gcd(T a, T b) { while(b) { a %= b; swap(a,b); } return a; } template<typename T> T lcm(T a, T b) { return a/gcd(a,b)*b; } /* ---------------------------------------------------------------- END OF TEMPLATE ---------------------------------------------------------------- Nguyen Ngoc Hung - nnhzzz Training for VOI24 gold medal ---------------------------------------------------------------- */ struct FENWICK_TREE{ vi f; int n; void update(int id, int val){ for(; id<=n; id+=id&-id){ f[id] += val; } } int get(int id){ int res = 0; for(; id>0; id-=id&-id){ res += f[id]; } return res; } int get(int l, int r){ return get(r)-get(l-1); } FENWICK_TREE(int _ = 0):n(_){ f.resize(n+1); } }fen; int a[maxn]; set<int> s; void ans(int val){ cout << val << " "; s.erase(s.find(val)); fen.update(val,1); } void solve(){ int n; cin >> n; for(int i = 1; i<=n; i++){ cin >> a[i]; } for(int i = 1; i<2*n; i++){ s.insert(i); } fen = FENWICK_TREE(n<<1|1); for(int i = 1; i<=n; i++){ if(s.find(a[i])!=s.end()){ ans(a[i]); } while(fen.get(a[i])<i){ ans(*s.begin()); } while(fen.get(a[i],2*n)<i){ ans(*--s.end()); } } } __nnhzzz__{ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define name "test" if(fopen(name".inp","r")){ freopen(name".inp","r",stdin); freopen(name".out","w",stdout); } #define name1 "nnhzzz" if(fopen(name1".inp","r")){ freopen(name1".inp","r",stdin); freopen(name1".out","w",stdout); } int test = 1; while(test--){ solve(); } cerr << "\nTime elapsed: " << 1000*clock()/CLOCKS_PER_SEC << "ms\n"; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 332 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 1 ms | 340 KB | Output is correct |
13 | Correct | 1 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 468 KB | Output is correct |
2 | Correct | 3 ms | 724 KB | Output is correct |
3 | Correct | 5 ms | 1236 KB | Output is correct |
4 | Correct | 13 ms | 2260 KB | Output is correct |
5 | Correct | 23 ms | 4208 KB | Output is correct |
6 | Correct | 48 ms | 8232 KB | Output is correct |
7 | Correct | 83 ms | 12800 KB | Output is correct |