Submission #1260934

#TimeUsernameProblemLanguageResultExecution timeMemory
1260934tminhIndex (COCI21_index)C++20
60 / 110
2594 ms49716 KiB
#pragma GCC target("avx") #pragma GCC optimize(3) #pragma GCC optimize("Ofast") #pragma GCC optimize("inline") #pragma GCC optimize("-fgcse") #pragma GCC optimize("-fgcse-lm") #pragma GCC optimize("-fipa-sra") #pragma GCC optimize("-ftree-pre") #pragma GCC optimize("-ftree-vrp") #pragma GCC optimize("-fpeephole2") #pragma GCC optimize("-ffast-math") #pragma GCC optimize("-fsched-spec") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("-falign-jumps") #pragma GCC optimize("-falign-loops") #pragma GCC optimize("-falign-labels") #pragma GCC optimize("-fdevirtualize") #pragma GCC optimize("-fcaller-saves") #pragma GCC optimize("-fcrossjumping") #pragma GCC optimize("-fthread-jumps") #pragma GCC optimize("-funroll-loops") #pragma GCC optimize("-fwhole-program") #pragma GCC optimize("-freorder-blocks") #pragma GCC optimize("-fschedule-insns") #pragma GCC optimize("inline-functions") #pragma GCC optimize("-ftree-tail-merge") #pragma GCC optimize("-fschedule-insns2") #pragma GCC optimize("-fstrict-aliasing") #pragma GCC optimize("-fstrict-overflow") #pragma GCC optimize("-falign-functions") #pragma GCC optimize("-fcse-skip-blocks") #pragma GCC optimize("-fcse-follow-jumps") #pragma GCC optimize("-fsched-interblock") #pragma GCC optimize("-fpartial-inlining") #pragma GCC optimize("no-stack-protector") #pragma GCC optimize("-freorder-functions") #pragma GCC optimize("-findirect-inlining") #pragma GCC optimize("-fhoist-adjacent-loads") #pragma GCC optimize("-frerun-cse-after-loop") #pragma GCC optimize("inline-small-functions") #pragma GCC optimize("-finline-small-functions") #pragma GCC optimize("-ftree-switch-conversion") #pragma GCC optimize("-foptimize-sibling-calls") #pragma GCC optimize("-fexpensive-optimizations") #pragma GCC optimize("-funsafe-loop-optimizations") #pragma GCC optimize("inline-functions-called-once") #pragma GCC optimize("-fdelete-null-pointer-checks") #include "bits/stdc++.h" using namespace std; #define task "" #define ll long long #define endl '\n' #define fi first #define se second #define vall(a) (a).begin(), (a).end() #define sze(a) (int)a.size() #define pii pair<int, int> #define pll pair<ll, ll> #define ep emplace_back #define pb push_back #define pf push_front const ll mod = 1e9 + 7; const int N = 2e5 + 5; const ll oo = 1e18; bool START; int n, q; pii a[N]; struct ST { vector<int> st[N << 2]; void merge(int id) { int i = 0, j = 0; while(i < sze(st[id << 1]) && j < sze(st[id << 1 | 1])) { if (st[id << 1][i] < st[id << 1 | 1][j]) { st[id].pb(st[id << 1][i++]); } else { st[id].pb(st[id << 1 | 1][j++]); } } while(i < sze(st[id << 1])) st[id].pb(st[id << 1][i++]); while(j < sze(st[id << 1 | 1])) st[id].pb(st[id << 1 | 1][j++]); } void build(int id, int l, int r) { if (l == r) { st[id].pb(a[l].se); return; } int mid = (l + r) >> 1; build(id << 1, l, mid); build(id << 1 | 1, mid + 1, r); merge(id); } int get(int id, int l, int r, int u, int v, int k) { if (l == r) return st[id].back(); int p = upper_bound(vall(st[id << 1]), v) - lower_bound(vall(st[id << 1]), u); int mid = (l + r) >> 1; if (p >= k) return get(id << 1, l, mid, u, v, k); return get(id << 1 | 1, mid + 1, r, u, v, k - p); } } st; int b[N]; bool check(int x, int l, int r) { return b[st.get(1, 1, n, l, r, (r - l + 1) - x + 1)] >= x; } inline void solve() { sort(a + 1, a + 1 + n); st.build(1, 1, n); while(q--) { int L, R; cin >> L >> R; int l = 0, r = R - L + 1, ans = 0; while(l <= r) { int mid = (l + r) >> 1; if (check(mid, L, R)) { ans = mid; l = mid + 1; } else { r = mid - 1; } } cout << ans << endl; } } inline void input() { cin >> n >> q; for (int i = 1; i <= n; ++i) { cin >> a[i].fi; b[i] = a[i].fi; a[i].se = i; } return solve(); } bool END; int main() { if(fopen(task ".inp", "r")) { freopen(task ".inp", "r", stdin); freopen(task ".out", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); input(); cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << 's' << endl; cerr << "Memory: " << fabs ((&END - &START)) / 1048576.0 << "MB\n"; return 0; }

Compilation message (stderr)

index.cpp:22:39: warning: bad option '-fwhole-program' to pragma 'optimize' [-Wpragmas]
   22 | #pragma GCC optimize("-fwhole-program")
      |                                       ^
index.cpp:29:41: warning: bad option '-fstrict-overflow' to pragma 'optimize' [-Wpragmas]
   29 | #pragma GCC optimize("-fstrict-overflow")
      |                                         ^
index.cpp:31:41: warning: bad option '-fcse-skip-blocks' to pragma 'optimize' [-Wpragmas]
   31 | #pragma GCC optimize("-fcse-skip-blocks")
      |                                         ^
index.cpp:45:51: warning: bad option '-funsafe-loop-optimizations' to pragma 'optimize' [-Wpragmas]
   45 | #pragma GCC optimize("-funsafe-loop-optimizations")
      |                                                   ^
index.cpp:78:26: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   78 |         void merge(int id) {
      |                          ^
index.cpp:78:26: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
index.cpp:78:26: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
index.cpp:78:26: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
index.cpp:90:40: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   90 |         void build(int id, int l, int r) {
      |                                        ^
index.cpp:90:40: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
index.cpp:90:40: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
index.cpp:90:40: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
index.cpp:100:58: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
  100 |         int get(int id, int l, int r, int u, int v, int k) {
      |                                                          ^
index.cpp:100:58: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
index.cpp:100:58: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
index.cpp:100:58: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
index.cpp:111:31: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
  111 | bool check(int x, int l, int r) {
      |                               ^
index.cpp:111:31: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
index.cpp:111:31: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
index.cpp:111:31: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
index.cpp:115:19: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
  115 | inline void solve() {
      |                   ^
index.cpp:115:19: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
index.cpp:115:19: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
index.cpp:115:19: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
index.cpp:139:19: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
  139 | inline void input() {
      |                   ^
index.cpp:139:19: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
index.cpp:139:19: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
index.cpp:139:19: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
index.cpp:150:10: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
  150 | int main() {
      |          ^
index.cpp:150:10: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
index.cpp:150:10: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
index.cpp:150:10: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
index.cpp: In function 'int main()':
index.cpp:152:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  152 |         freopen(task ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
index.cpp:153:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  153 |         freopen(task ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...