답안 #901241

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
901241 2024-01-09T08:13:48 Z duckindog Osumnjičeni (COCI21_osumnjiceni) C++14
110 / 110
224 ms 32336 KB
//from duckindog wth depressiong
#include<bits/stdc++.h>

using namespace std;

using pii = pair<int, int>;
const int N = 2e5 + 10;
int n;
int lt[N], rt[N];

int f[N][19];
bool chk(pii x, pii y) {
  bool pass = 0;
  for (int i = 0; i < 2; ++i) {
    pass |= (x.second < y.first || x.first > y.second) ;
    swap(x, y);
  }
  return pass;
}

void init() {

  set<pii> duck;
  int j = 1;
  for (int i = 1; i <= n; ++i) {
    duck.erase({lt[i - 1], rt[i - 1]});

    if (j < i) {
      duck.clear();
      j = i;
    }

    while (j <= n) {
      pii now = {lt[j], rt[j]};
      auto it = duck.lower_bound(now);
      bool pass = chk(*it, now);

      if (it != duck.begin()) it--;
      pass &= chk(*it, now);
      if (pass) {
        duck.insert(now);
        j += 1;
      } else break;

    }

    f[i][0] = j;

  }
  for (int j = 1; j <= 18; ++j) {
    for (int i = 1; i <= n; ++i) {
      f[i][j] = f[f[i][j - 1]][j - 1];
    }
  }

}
int get(int l, int r) {
  int answer = 0;
  for (int i = 18; i >= 0; --i) {
    if (!f[l][i] || f[l][i] > r) continue;
    l = f[l][i];
    answer += 1 << i;
  }
  return answer + 1;
}

int32_t main() {
  cin.tie(0)->sync_with_stdio(0);

  if (fopen("duck.inp", "r")) {
    freopen("duck.inp", "r", stdin);
    freopen("duck.out", "w", stdout);
  }
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> lt[i] >> rt[i];
  init();

  int m; cin >> m;
  while (m--) {
    int p, q; cin >> p >> q;
    cout << get(p, q) << '\n';
  }

}

Compilation message

Main.cpp: In function 'int32_t main()':
Main.cpp:71:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |     freopen("duck.inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:72:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |     freopen("duck.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 16716 KB Output is correct
2 Correct 48 ms 19960 KB Output is correct
3 Correct 53 ms 20052 KB Output is correct
4 Correct 48 ms 20044 KB Output is correct
5 Correct 49 ms 20560 KB Output is correct
6 Correct 41 ms 19948 KB Output is correct
7 Correct 48 ms 19796 KB Output is correct
8 Correct 47 ms 19948 KB Output is correct
9 Correct 50 ms 20048 KB Output is correct
10 Correct 57 ms 19792 KB Output is correct
11 Correct 166 ms 28908 KB Output is correct
12 Correct 147 ms 27876 KB Output is correct
13 Correct 151 ms 27984 KB Output is correct
14 Correct 141 ms 24948 KB Output is correct
15 Correct 153 ms 23404 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 44 ms 20044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2652 KB Output is correct
2 Correct 3 ms 2652 KB Output is correct
3 Correct 3 ms 2652 KB Output is correct
4 Correct 3 ms 2652 KB Output is correct
5 Correct 3 ms 2652 KB Output is correct
6 Correct 5 ms 2904 KB Output is correct
7 Correct 3 ms 2652 KB Output is correct
8 Correct 3 ms 2652 KB Output is correct
9 Correct 3 ms 2648 KB Output is correct
10 Correct 3 ms 2780 KB Output is correct
11 Correct 4 ms 2904 KB Output is correct
12 Correct 4 ms 3160 KB Output is correct
13 Correct 4 ms 2908 KB Output is correct
14 Correct 4 ms 2908 KB Output is correct
15 Correct 5 ms 2724 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 3 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2652 KB Output is correct
2 Correct 3 ms 2652 KB Output is correct
3 Correct 3 ms 2652 KB Output is correct
4 Correct 3 ms 2652 KB Output is correct
5 Correct 3 ms 2652 KB Output is correct
6 Correct 5 ms 2904 KB Output is correct
7 Correct 3 ms 2652 KB Output is correct
8 Correct 3 ms 2652 KB Output is correct
9 Correct 3 ms 2648 KB Output is correct
10 Correct 3 ms 2780 KB Output is correct
11 Correct 4 ms 2904 KB Output is correct
12 Correct 4 ms 3160 KB Output is correct
13 Correct 4 ms 2908 KB Output is correct
14 Correct 4 ms 2908 KB Output is correct
15 Correct 5 ms 2724 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 3 ms 2648 KB Output is correct
18 Correct 56 ms 5484 KB Output is correct
19 Correct 51 ms 5200 KB Output is correct
20 Correct 56 ms 5408 KB Output is correct
21 Correct 52 ms 5280 KB Output is correct
22 Correct 62 ms 5788 KB Output is correct
23 Correct 51 ms 5308 KB Output is correct
24 Correct 58 ms 5352 KB Output is correct
25 Correct 55 ms 5292 KB Output is correct
26 Correct 55 ms 5196 KB Output is correct
27 Correct 50 ms 5028 KB Output is correct
28 Correct 35 ms 4948 KB Output is correct
29 Correct 49 ms 5156 KB Output is correct
30 Correct 45 ms 5260 KB Output is correct
31 Correct 39 ms 4964 KB Output is correct
32 Correct 38 ms 4908 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 43 ms 5188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 16768 KB Output is correct
2 Correct 50 ms 20316 KB Output is correct
3 Correct 46 ms 19880 KB Output is correct
4 Correct 50 ms 19888 KB Output is correct
5 Correct 49 ms 19852 KB Output is correct
6 Correct 42 ms 19888 KB Output is correct
7 Correct 47 ms 19928 KB Output is correct
8 Correct 50 ms 19796 KB Output is correct
9 Correct 49 ms 19792 KB Output is correct
10 Correct 62 ms 20048 KB Output is correct
11 Correct 152 ms 27996 KB Output is correct
12 Correct 160 ms 29524 KB Output is correct
13 Correct 149 ms 27756 KB Output is correct
14 Correct 134 ms 23808 KB Output is correct
15 Correct 145 ms 25172 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 43 ms 19816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 16716 KB Output is correct
2 Correct 48 ms 19960 KB Output is correct
3 Correct 53 ms 20052 KB Output is correct
4 Correct 48 ms 20044 KB Output is correct
5 Correct 49 ms 20560 KB Output is correct
6 Correct 41 ms 19948 KB Output is correct
7 Correct 48 ms 19796 KB Output is correct
8 Correct 47 ms 19948 KB Output is correct
9 Correct 50 ms 20048 KB Output is correct
10 Correct 57 ms 19792 KB Output is correct
11 Correct 166 ms 28908 KB Output is correct
12 Correct 147 ms 27876 KB Output is correct
13 Correct 151 ms 27984 KB Output is correct
14 Correct 141 ms 24948 KB Output is correct
15 Correct 153 ms 23404 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 44 ms 20044 KB Output is correct
18 Correct 3 ms 2652 KB Output is correct
19 Correct 3 ms 2652 KB Output is correct
20 Correct 3 ms 2652 KB Output is correct
21 Correct 3 ms 2652 KB Output is correct
22 Correct 3 ms 2652 KB Output is correct
23 Correct 5 ms 2904 KB Output is correct
24 Correct 3 ms 2652 KB Output is correct
25 Correct 3 ms 2652 KB Output is correct
26 Correct 3 ms 2648 KB Output is correct
27 Correct 3 ms 2780 KB Output is correct
28 Correct 4 ms 2904 KB Output is correct
29 Correct 4 ms 3160 KB Output is correct
30 Correct 4 ms 2908 KB Output is correct
31 Correct 4 ms 2908 KB Output is correct
32 Correct 5 ms 2724 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 3 ms 2648 KB Output is correct
35 Correct 56 ms 5484 KB Output is correct
36 Correct 51 ms 5200 KB Output is correct
37 Correct 56 ms 5408 KB Output is correct
38 Correct 52 ms 5280 KB Output is correct
39 Correct 62 ms 5788 KB Output is correct
40 Correct 51 ms 5308 KB Output is correct
41 Correct 58 ms 5352 KB Output is correct
42 Correct 55 ms 5292 KB Output is correct
43 Correct 55 ms 5196 KB Output is correct
44 Correct 50 ms 5028 KB Output is correct
45 Correct 35 ms 4948 KB Output is correct
46 Correct 49 ms 5156 KB Output is correct
47 Correct 45 ms 5260 KB Output is correct
48 Correct 39 ms 4964 KB Output is correct
49 Correct 38 ms 4908 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 43 ms 5188 KB Output is correct
52 Correct 51 ms 16768 KB Output is correct
53 Correct 50 ms 20316 KB Output is correct
54 Correct 46 ms 19880 KB Output is correct
55 Correct 50 ms 19888 KB Output is correct
56 Correct 49 ms 19852 KB Output is correct
57 Correct 42 ms 19888 KB Output is correct
58 Correct 47 ms 19928 KB Output is correct
59 Correct 50 ms 19796 KB Output is correct
60 Correct 49 ms 19792 KB Output is correct
61 Correct 62 ms 20048 KB Output is correct
62 Correct 152 ms 27996 KB Output is correct
63 Correct 160 ms 29524 KB Output is correct
64 Correct 149 ms 27756 KB Output is correct
65 Correct 134 ms 23808 KB Output is correct
66 Correct 145 ms 25172 KB Output is correct
67 Correct 0 ms 348 KB Output is correct
68 Correct 43 ms 19816 KB Output is correct
69 Correct 204 ms 23500 KB Output is correct
70 Correct 220 ms 23892 KB Output is correct
71 Correct 124 ms 23076 KB Output is correct
72 Correct 141 ms 23544 KB Output is correct
73 Correct 157 ms 23660 KB Output is correct
74 Correct 141 ms 24148 KB Output is correct
75 Correct 184 ms 23376 KB Output is correct
76 Correct 166 ms 24352 KB Output is correct
77 Correct 128 ms 23332 KB Output is correct
78 Correct 139 ms 23560 KB Output is correct
79 Correct 224 ms 32336 KB Output is correct
80 Correct 195 ms 30548 KB Output is correct
81 Correct 200 ms 30520 KB Output is correct
82 Correct 192 ms 26608 KB Output is correct
83 Correct 176 ms 26144 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 106 ms 23348 KB Output is correct