답안 #792637

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
792637 2023-07-25T07:41:13 Z huutuan Index (COCI21_index) C++14
110 / 110
593 ms 62828 KB
#include<bits/stdc++.h>

using namespace std;

#define int long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)x.size())
#define sumof(x) accumulate(all(x), 0ll)

struct FenwickTree{
   int n; vector<int> t;

   void init(int _n){
      n=_n;
      t.assign(n+1, 0);
   }

   void update(int pos, int val){
      for (int i=pos; i<=n; i+=i&(-i)) t[i]+=val;
   }

   void init(int _n, int* a){
      init(_n);
      for (int i=1; i<=n; ++i) update(i, a[i]);
   }

   int get(int pos){
      int ans=0;
      for (int i=pos; i; i-=i&(-i)) ans+=t[i];
      return ans;
   }

   int get(int l, int r){
      return get(r)-get(l-1);
   }
} bit;

const int N=2e5+1;
int n, q;
int l[N], r[N], a[N];
pair<int, int> qq[N];
vector<int> v[N], pos[N];

void solve(int tc){
   // cout << "Case #" << tc << ": ";
   cin >> n >> q;
   vector<int> vals;
   for (int i=1; i<=n; ++i) cin >> a[i], pos[a[i]].push_back(i);
   for (int i=1; i<=q; ++i){
      cin >> qq[i].first >> qq[i].second;
      l[i]=1, r[i]=2e5;
   }
   for (int rep=1; rep<=20; ++rep){
      for (int i=1; i<=q; ++i) if (l[i]<=r[i]) v[(l[i]+r[i])>>1].push_back(i);
      bit.init(n);
      for (int i=2e5; i>=1; --i){
         for (int j:pos[i]) bit.update(j, 1);
         for (int j:v[i]){
            if (bit.get(qq[j].first, qq[j].second)>=i) l[j]=i+1;
            else r[j]=i-1;
         }
         v[i].clear();
      }
   }
   for (int i=1; i<=q; ++i) cout << r[i] << '\n';
}

int32_t main(){
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   int ntests=1;
   // cin >> ntests;
   for (int i=1; i<=ntests; ++i) solve(i);
   return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 9940 KB Output is correct
2 Correct 11 ms 9940 KB Output is correct
3 Correct 10 ms 9940 KB Output is correct
4 Correct 10 ms 9940 KB Output is correct
5 Correct 9 ms 9944 KB Output is correct
6 Correct 10 ms 9940 KB Output is correct
7 Correct 12 ms 10068 KB Output is correct
8 Correct 10 ms 9988 KB Output is correct
9 Correct 10 ms 9940 KB Output is correct
10 Correct 13 ms 9940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 9940 KB Output is correct
2 Correct 11 ms 9940 KB Output is correct
3 Correct 10 ms 9940 KB Output is correct
4 Correct 10 ms 9940 KB Output is correct
5 Correct 9 ms 9944 KB Output is correct
6 Correct 10 ms 9940 KB Output is correct
7 Correct 12 ms 10068 KB Output is correct
8 Correct 10 ms 9988 KB Output is correct
9 Correct 10 ms 9940 KB Output is correct
10 Correct 13 ms 9940 KB Output is correct
11 Correct 90 ms 22684 KB Output is correct
12 Correct 97 ms 22496 KB Output is correct
13 Correct 92 ms 22648 KB Output is correct
14 Correct 101 ms 22676 KB Output is correct
15 Correct 96 ms 22544 KB Output is correct
16 Correct 92 ms 22600 KB Output is correct
17 Correct 90 ms 22728 KB Output is correct
18 Correct 95 ms 22568 KB Output is correct
19 Correct 101 ms 22548 KB Output is correct
20 Correct 92 ms 22648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 9940 KB Output is correct
2 Correct 11 ms 9940 KB Output is correct
3 Correct 10 ms 9940 KB Output is correct
4 Correct 10 ms 9940 KB Output is correct
5 Correct 9 ms 9944 KB Output is correct
6 Correct 10 ms 9940 KB Output is correct
7 Correct 12 ms 10068 KB Output is correct
8 Correct 10 ms 9988 KB Output is correct
9 Correct 10 ms 9940 KB Output is correct
10 Correct 13 ms 9940 KB Output is correct
11 Correct 90 ms 22684 KB Output is correct
12 Correct 97 ms 22496 KB Output is correct
13 Correct 92 ms 22648 KB Output is correct
14 Correct 101 ms 22676 KB Output is correct
15 Correct 96 ms 22544 KB Output is correct
16 Correct 92 ms 22600 KB Output is correct
17 Correct 90 ms 22728 KB Output is correct
18 Correct 95 ms 22568 KB Output is correct
19 Correct 101 ms 22548 KB Output is correct
20 Correct 92 ms 22648 KB Output is correct
21 Correct 506 ms 61984 KB Output is correct
22 Correct 479 ms 62088 KB Output is correct
23 Correct 499 ms 62656 KB Output is correct
24 Correct 520 ms 62156 KB Output is correct
25 Correct 515 ms 62716 KB Output is correct
26 Correct 512 ms 62292 KB Output is correct
27 Correct 514 ms 62056 KB Output is correct
28 Correct 593 ms 62828 KB Output is correct
29 Correct 493 ms 61764 KB Output is correct
30 Correct 504 ms 62568 KB Output is correct