답안 #643515

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
643515 2022-09-22T08:58:02 Z makanhulia Martian DNA (BOI18_dna) C++17
100 / 100
142 ms 14304 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 5;

int n, k, m, a[N], b[N], t[N], f[N], lst[N];
vector<int> pos[N];
vector<array<int,3>> ranges;

void update(int idx, int v)
{
  for(int i = idx; i <= n; i += i & -i) f[i] += v;
}

int query(int idx) 
{
  int ret = 0;
  for(int i = idx; i > 0; i -= i & -i) ret += f[i];
  return ret;
}

int sum(int l, int r)
{
  return query(r) - query(l - 1);
}

int main() 
{
  cin.tie(0); ios_base::sync_with_stdio(0);

  cin >> n >> k >> m;
  for(int i = 1; i <= n; i++) {
    cin >> a[i];
    pos[a[i]].push_back(i);
  }
  for(int i = 0; i < m; i++) {
    int x, v;
    cin >> x >> v;
    for(int j = 0; j + v - 1 < pos[x].size(); j++) {
      ranges.push_back({pos[x][j + v - 1], pos[x][j], x});
    }
  }
  sort(ranges.begin(), ranges.end());
  int ans = 1e9;
  for(auto [r, l, idx] : ranges) {
    if(l > lst[idx]) {
      if(lst[idx] > 0) update(lst[idx], -1);
      lst[idx] = l;
      update(lst[idx], 1);
    }
    int lf = 1, rg = r, z = -1;
    while(lf <= rg) {
      int mid = (lf + rg) / 2;
      if(sum(mid, r) == m) {
        lf = mid + 1, z = mid;
      } else {
        rg = mid - 1;
      }
    }
    // cout << idx << " " << l << " " << r << " " << sum(1, r) << '\n';
    if(z != -1) ans = min(ans, r - z + 1);
  }

  if(ans == 1e9) {
    cout << "impossible";
  } else {
    cout << ans;
  }
} 

Compilation message

dna.cpp: In function 'int main()':
dna.cpp:39:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     for(int j = 0; j + v - 1 < pos[x].size(); j++) {
      |                    ~~~~~~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 2 ms 4936 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Correct 3 ms 5076 KB Output is correct
4 Correct 4 ms 5076 KB Output is correct
5 Correct 4 ms 5076 KB Output is correct
6 Correct 5 ms 5204 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 8592 KB Output is correct
2 Correct 83 ms 9440 KB Output is correct
3 Correct 111 ms 9852 KB Output is correct
4 Correct 84 ms 9112 KB Output is correct
5 Correct 31 ms 8716 KB Output is correct
6 Correct 13 ms 6996 KB Output is correct
7 Correct 22 ms 7876 KB Output is correct
8 Correct 58 ms 12092 KB Output is correct
9 Correct 24 ms 7868 KB Output is correct
10 Correct 98 ms 9116 KB Output is correct
11 Correct 4 ms 5076 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
14 Correct 4 ms 5076 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 5 ms 5204 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4952 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 4 ms 4948 KB Output is correct
22 Correct 2 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 142 ms 11960 KB Output is correct
2 Correct 138 ms 11092 KB Output is correct
3 Correct 63 ms 9796 KB Output is correct
4 Correct 105 ms 10472 KB Output is correct
5 Correct 50 ms 8948 KB Output is correct
6 Correct 131 ms 14304 KB Output is correct
7 Correct 81 ms 9428 KB Output is correct
8 Correct 88 ms 10728 KB Output is correct
9 Correct 62 ms 8688 KB Output is correct
10 Correct 79 ms 9344 KB Output is correct
11 Correct 99 ms 9860 KB Output is correct
12 Correct 83 ms 9048 KB Output is correct
13 Correct 30 ms 8684 KB Output is correct
14 Correct 15 ms 6996 KB Output is correct
15 Correct 20 ms 7916 KB Output is correct
16 Correct 48 ms 12148 KB Output is correct
17 Correct 33 ms 7748 KB Output is correct
18 Correct 87 ms 8944 KB Output is correct
19 Correct 3 ms 5076 KB Output is correct
20 Correct 4 ms 5076 KB Output is correct
21 Correct 3 ms 5152 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 3 ms 5076 KB Output is correct
24 Correct 4 ms 5204 KB Output is correct
25 Correct 2 ms 4948 KB Output is correct
26 Correct 2 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 2 ms 4948 KB Output is correct
29 Correct 3 ms 4948 KB Output is correct
30 Correct 3 ms 4948 KB Output is correct
31 Correct 2 ms 4948 KB Output is correct
32 Correct 2 ms 4948 KB Output is correct
33 Correct 2 ms 4948 KB Output is correct