Submission #1012032

#TimeUsernameProblemLanguageResultExecution timeMemory
1012032vjudge1Index (COCI21_index)C++17
110 / 110
219 ms33944 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define int long long #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FORD(i, a, b) for (int i = (b); i >= (a); i --) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPD(i, n) for (int i = (n) - 1; i >= 0; --i) #define MASK(i) (1LL << (i)) #define BIT(x, i) (((x) >> (i)) & 1) constexpr ll LINF = (1ll << 60); constexpr int INF = (1ll << 30); constexpr int Mod = 1e9 + 7; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /* Phu Trong from Nguyen Tat Thanh High School for gifted student */ template <class X, class Y> bool minimize(X &x, const Y &y){ X eps = 1e-9; if (x > y + eps) {x = y; return 1;} return 0; } template <class X, class Y> bool maximize(X &x, const Y &y){ X eps = 1e-9; if (x + eps < y) {x = y; return 1;} return 0; } #define MAX 200005 #define N 200000 int nArr, numQuery; int A[MAX]; int L[MAX], R[MAX]; int F[MAX]; int low_bit(int p){ return (p & (-p)); } void upd(int p, int val){ for (; p <= N; p += low_bit(p)){ F[p] += val; } } int query(int p){ int res = 0; for (; p > 0; p -= low_bit(p)){ res += F[p]; } return res; } int query(int l, int r){ return query(r) - query(l - 1); } vector<int> val[MAX]; int ans[MAX]; void parallel(int l, int r, vector<int>&cand){ //solve for segment [l, r) if (l + 1 == r || cand.empty()){ for (int&i : cand) ans[i] = l; return; } int m = (l + r) >> 1; for (int i = m; i < r; ++i){ for (int &j : val[i]){ upd(j, 1); } } vector<int> ok, not_ok; for (int &i : cand){ if (query(L[i], R[i]) >= m){ ok.emplace_back(i); } else not_ok.emplace_back(i); } parallel(l, m, not_ok); for (int i = m; i < r; ++i){ for (int &j : val[i]){ upd(j, -1); } } parallel(m, r, ok); } void process(void){ cin >> nArr >> numQuery; int lim = 0; for (int i = 1; i <= nArr; ++i){ cin >> A[i], maximize(lim, A[i]); val[A[i]].emplace_back(i); } for (int i = 1; i <= numQuery; ++i) cin >> L[i] >> R[i]; vector<int> cand; for (int i = 1; i <= numQuery; ++i) cand.push_back(i); parallel(1, lim + 1, cand); for (int i = 1; i <= numQuery; ++i){ cout << ans[i] << "\n"; } } signed main(){ #define name "Whisper" cin.tie(nullptr) -> sync_with_stdio(false); //freopen(name".inp", "r", stdin); //freopen(name".out", "w", stdout); process(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...