답안 #155997

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
155997 2019-10-02T14:14:17 Z ASDF123 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
30 / 100
3000 ms 26520 KB
#include <bits/stdc++.h>
//#define int long long
#define fr first
#define sc second
#define all(s) s.begin(), s.end()
#define szof(s) (int)s.size()
using namespace std;

const int N = (int)1e6 + 5;
const int INF = 1e9 + 7;
const int MOD = (int)1e9 + 7;

int tests = 1;
int n, l, r, k;
int a[N];
int tree[N * 4], pref[N];

void build(int v = 1, int tl = 1, int tr = N) {
  if (tl == tr) {
    tree[v] = a[tl];
    return;
  }
  int mid = tl + tr >> 1;
  build(v + v, tl, mid);
  build(v + v + 1, mid + 1, tr);
  tree[v] = min(tree[v + v], tree[v + v + 1]);
}

int get(int l, int r, int v = 1, int tl = 1, int tr = N) {
  if (l <= tl && tr <= r) {
    return tree[v];
  }
  if (l > tr || tl > r) {
    return INF;
  }
  int mid = tl + tr >> 1;
  return min(get(l, r, v + v, tl, mid), get(l, r, v + v + 1, mid + 1, tr));
}

int bad(int l, int r) {
  return pref[r - 1] - pref[l - 1];
}


void solve() {
  scanf("%d%d%d", &l, &r, &k);

  if (k < get(l, r)) {
    if (bad(l, r)) {
      puts("0");
    } else {
      puts("1");
    }
    return;
  }

  set <int> st;
  set <int> ::iterator it;
  bool ok = true;
  int mn = INF;

  for (int i = r; i >= l; i--) {
    if (i == r) {
      st.insert(a[i]);
      mn = min(mn, a[i]);
      continue;
    }
    if (mn < a[i]) {
      it = st.lower_bound(a[i]);
      it--;
      if (*it + a[i] > k) {
        ok = false;
        break;
      }
    }
    st.insert(a[i]);
    mn = min(mn, a[i]);
  }

  if (ok) {
    puts("1");
  } else {
    puts("0");
  }
}

main() {
  scanf("%d%d", &n, &tests);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  build();

  for (int i = 1; i <= n; i++) {
    pref[i] = pref[i - 1] + (a[i] > a[i + 1]);
  }

//  for (int i = 1; i <= n; i++) {
//    cout << pref[i] << " ";
//  }cout << endl;
//
//  while (1) {
//    int l, r;
//    cin >> l >> r;
//    cout << get(l, r) << endl;
//  }


  while (tests--) {
    solve();
  }
}

Compilation message

sortbooks.cpp: In function 'void build(int, int, int)':
sortbooks.cpp:23:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid = tl + tr >> 1;
             ~~~^~~~
sortbooks.cpp: In function 'int get(int, int, int, int, int)':
sortbooks.cpp:36:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid = tl + tr >> 1;
             ~~~^~~~
sortbooks.cpp: At global scope:
sortbooks.cpp:87:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
sortbooks.cpp: In function 'void solve()':
sortbooks.cpp:46:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &l, &r, &k);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:88:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &n, &tests);
   ~~~~~^~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:90:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &a[i]);
     ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 8568 KB Output is correct
2 Correct 15 ms 8440 KB Output is correct
3 Correct 17 ms 8568 KB Output is correct
4 Correct 16 ms 8568 KB Output is correct
5 Correct 16 ms 8568 KB Output is correct
6 Correct 17 ms 8568 KB Output is correct
7 Correct 17 ms 8568 KB Output is correct
8 Correct 26 ms 8540 KB Output is correct
9 Correct 20 ms 8568 KB Output is correct
10 Correct 17 ms 8568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 8568 KB Output is correct
2 Correct 15 ms 8440 KB Output is correct
3 Correct 17 ms 8568 KB Output is correct
4 Correct 16 ms 8568 KB Output is correct
5 Correct 16 ms 8568 KB Output is correct
6 Correct 17 ms 8568 KB Output is correct
7 Correct 17 ms 8568 KB Output is correct
8 Correct 26 ms 8540 KB Output is correct
9 Correct 20 ms 8568 KB Output is correct
10 Correct 17 ms 8568 KB Output is correct
11 Correct 23 ms 8568 KB Output is correct
12 Correct 27 ms 8696 KB Output is correct
13 Correct 28 ms 8696 KB Output is correct
14 Correct 35 ms 8824 KB Output is correct
15 Correct 32 ms 8696 KB Output is correct
16 Correct 1456 ms 8928 KB Output is correct
17 Correct 792 ms 8824 KB Output is correct
18 Correct 133 ms 8568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1618 ms 18448 KB Output is correct
2 Correct 1410 ms 18468 KB Output is correct
3 Correct 1419 ms 18472 KB Output is correct
4 Correct 1417 ms 18572 KB Output is correct
5 Correct 1412 ms 26520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3039 ms 9424 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 8568 KB Output is correct
2 Correct 15 ms 8440 KB Output is correct
3 Correct 17 ms 8568 KB Output is correct
4 Correct 16 ms 8568 KB Output is correct
5 Correct 16 ms 8568 KB Output is correct
6 Correct 17 ms 8568 KB Output is correct
7 Correct 17 ms 8568 KB Output is correct
8 Correct 26 ms 8540 KB Output is correct
9 Correct 20 ms 8568 KB Output is correct
10 Correct 17 ms 8568 KB Output is correct
11 Correct 23 ms 8568 KB Output is correct
12 Correct 27 ms 8696 KB Output is correct
13 Correct 28 ms 8696 KB Output is correct
14 Correct 35 ms 8824 KB Output is correct
15 Correct 32 ms 8696 KB Output is correct
16 Correct 1456 ms 8928 KB Output is correct
17 Correct 792 ms 8824 KB Output is correct
18 Correct 133 ms 8568 KB Output is correct
19 Execution timed out 3027 ms 18980 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 8568 KB Output is correct
2 Correct 15 ms 8440 KB Output is correct
3 Correct 17 ms 8568 KB Output is correct
4 Correct 16 ms 8568 KB Output is correct
5 Correct 16 ms 8568 KB Output is correct
6 Correct 17 ms 8568 KB Output is correct
7 Correct 17 ms 8568 KB Output is correct
8 Correct 26 ms 8540 KB Output is correct
9 Correct 20 ms 8568 KB Output is correct
10 Correct 17 ms 8568 KB Output is correct
11 Correct 23 ms 8568 KB Output is correct
12 Correct 27 ms 8696 KB Output is correct
13 Correct 28 ms 8696 KB Output is correct
14 Correct 35 ms 8824 KB Output is correct
15 Correct 32 ms 8696 KB Output is correct
16 Correct 1456 ms 8928 KB Output is correct
17 Correct 792 ms 8824 KB Output is correct
18 Correct 133 ms 8568 KB Output is correct
19 Correct 1618 ms 18448 KB Output is correct
20 Correct 1410 ms 18468 KB Output is correct
21 Correct 1419 ms 18472 KB Output is correct
22 Correct 1417 ms 18572 KB Output is correct
23 Correct 1412 ms 26520 KB Output is correct
24 Execution timed out 3039 ms 9424 KB Time limit exceeded
25 Halted 0 ms 0 KB -