답안 #386349

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
386349 2021-04-06T12:27:00 Z model_code Index (COCI21_index) C++17
60 / 110
2500 ms 37772 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair
#define pb push_back

const int MAXN = 200005;
const int offset = (1 << 18);

struct tournament {
  vector <int> v[offset * 2];

  void insert(int a, int b) {
    a += offset;
    while (a) {
      v[a].pb(b);
      a /= 2;
    }
  }

  void init() {
    REP(i, offset * 2) sort(all(v[i]));
  }

  int get(int cvor, int l, int r, int &a, int &b, int &x) {
    if (l > b || r < a) return 0;
    if (l >= a && r <= b) return (lower_bound(all(v[cvor]), x) - v[cvor].begin());

    int mid = (l + r) / 2;
    return get(cvor * 2, l, mid, a, b, x) + get(cvor * 2 + 1, mid + 1, r, a, b, x);
  }
}T;

int n, q;

int main() {
  scanf("%d %d",&n,&q);
  REP(i, n) {
    int x;
    scanf("%d",&x);
    T.insert(i, x);
  }
  T.init();
  REP(t, q) {
    int l, r;
    scanf("%d %d",&l,&r);
    l--; r--;
    int lo = 1, hi = MAXN, mid;
    while (lo != hi) {
      mid = (lo + hi + 1) / 2;
      int x = r - l + 1 - T.get(1, 0, offset - 1, l, r, mid);
      if (x >= mid) lo = mid;
      else hi = mid - 1;
    }
    printf("%d\n",lo);
  }
  return 0;
}

Compilation message

index.cpp: In function 'int main()':
index.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   51 |   scanf("%d %d",&n,&q);
      |   ~~~~~^~~~~~~~~~~~~~~
index.cpp:54:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   54 |     scanf("%d",&x);
      |     ~~~~~^~~~~~~~~
index.cpp:60:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   60 |     scanf("%d %d",&l,&r);
      |     ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 12780 KB Output is correct
2 Correct 19 ms 12780 KB Output is correct
3 Correct 19 ms 12908 KB Output is correct
4 Correct 21 ms 12780 KB Output is correct
5 Correct 23 ms 12784 KB Output is correct
6 Correct 19 ms 12780 KB Output is correct
7 Correct 20 ms 12780 KB Output is correct
8 Correct 19 ms 12780 KB Output is correct
9 Correct 19 ms 12780 KB Output is correct
10 Correct 19 ms 12780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 12780 KB Output is correct
2 Correct 19 ms 12780 KB Output is correct
3 Correct 19 ms 12908 KB Output is correct
4 Correct 21 ms 12780 KB Output is correct
5 Correct 23 ms 12784 KB Output is correct
6 Correct 19 ms 12780 KB Output is correct
7 Correct 20 ms 12780 KB Output is correct
8 Correct 19 ms 12780 KB Output is correct
9 Correct 19 ms 12780 KB Output is correct
10 Correct 19 ms 12780 KB Output is correct
11 Correct 880 ms 19036 KB Output is correct
12 Correct 911 ms 18996 KB Output is correct
13 Correct 917 ms 19028 KB Output is correct
14 Correct 910 ms 19172 KB Output is correct
15 Correct 874 ms 19096 KB Output is correct
16 Correct 879 ms 19044 KB Output is correct
17 Correct 947 ms 19056 KB Output is correct
18 Correct 900 ms 19044 KB Output is correct
19 Correct 935 ms 19156 KB Output is correct
20 Correct 923 ms 19176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 12780 KB Output is correct
2 Correct 19 ms 12780 KB Output is correct
3 Correct 19 ms 12908 KB Output is correct
4 Correct 21 ms 12780 KB Output is correct
5 Correct 23 ms 12784 KB Output is correct
6 Correct 19 ms 12780 KB Output is correct
7 Correct 20 ms 12780 KB Output is correct
8 Correct 19 ms 12780 KB Output is correct
9 Correct 19 ms 12780 KB Output is correct
10 Correct 19 ms 12780 KB Output is correct
11 Correct 880 ms 19036 KB Output is correct
12 Correct 911 ms 18996 KB Output is correct
13 Correct 917 ms 19028 KB Output is correct
14 Correct 910 ms 19172 KB Output is correct
15 Correct 874 ms 19096 KB Output is correct
16 Correct 879 ms 19044 KB Output is correct
17 Correct 947 ms 19056 KB Output is correct
18 Correct 900 ms 19044 KB Output is correct
19 Correct 935 ms 19156 KB Output is correct
20 Correct 923 ms 19176 KB Output is correct
21 Execution timed out 2584 ms 37772 KB Time limit exceeded
22 Halted 0 ms 0 KB -