답안 #1059647

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1059647 2024-08-15T06:43:34 Z NeroZein Sličnost (COI23_slicnost) C++17
24 / 100
3000 ms 5480 KB
#include "bits/stdc++.h"
using namespace std;

#ifdef Nero
#include "Deb.h"
#else
#define debug(...)
#endif

const int N = 1e5 + 5; 

int n, k;
int ind[N]; 
int lazy[N * 2];
pair<int, int> seg[N * 2];

pair<int, int> combine(pair<int, int> x, pair<int, int> y) {
  if (x.first < y.first) swap(x, y);
  if (x.first == y.first) {
    x.second += y.second;
  }
  return x; 
}

void build(int nd, int l, int r) {
  if (l == r) {
    seg[nd].second = 1;
    return;
  }
  int mid = (l + r) >> 1;
  int rs = nd + ((mid - l + 1) << 1);
  build(nd + 1, l, mid);
  build(rs, mid + 1, r); 
  seg[nd] = combine(seg[nd + 1], seg[rs]); 
}

void push(int nd, int l, int r) {
  if (!lazy[nd]) {
    return;
  }
  seg[nd].first += lazy[nd];
  if (l != r) {
    int mid = (l + r) >> 1;
    int rs = nd + ((mid - l + 1) << 1);
    lazy[nd + 1] += lazy[nd];
    lazy[rs] += lazy[nd]; 
  }
  lazy[nd] = 0;
}

void upd(int nd, int l, int r, int s, int e, int v) {
  push(nd, l, r); 
  if (l >= s && r <= e) {
    lazy[nd] = v;
    push(nd, l, r);
    return;
  }
  int mid = (l + r) >> 1;
  int rs = nd + ((mid - l + 1) << 1);
  if (mid >= e) {
    upd(nd + 1, l, mid, s, e, v); 
    push(rs, mid + 1, r); 
  } else {
    if (mid < s) {
      upd(rs, mid + 1, r, s, e, v);
      push(nd + 1, l, mid); 
    } else {
      upd(nd + 1, l, mid, s, e, v);
      upd(rs, mid + 1, r, s, e, v); 
    }
  }
  seg[nd] = combine(seg[nd + 1], seg[rs]);
}

void upd(int l, int r, int v) {
  if (l < n) {
    upd(0, 0, n - 1, l, min(n - 1, r), v); 
  }
}

pair<int, int> qry(int nd, int l, int r, int s, int e) {
  push(nd, l, r); 
  if (l >= s && r <= e) {
    return seg[nd];
  }
  int mid = (l + r) >> 1;
  int rs = nd + ((mid - l + 1) << 1);
  if (mid >= e) {
    return qry(nd + 1, l, mid, s, e);
  } else {
    if (mid < s) {
      return qry(rs, mid + 1, r, s, e);
    } else {
      return combine(qry(nd + 1, l, mid, s, e), qry(rs, mid + 1, r, s, e));
    }
  }
}

void solve(vector<int> a) {
  for (int i = 0; i < k; ++i) {
    upd(ind[a[i]], ind[a[i]] + k - 1, 1); 
  }
  pair<int, int> ans; 
  for (int i = k - 1; i < n; ++i) {
    auto v = qry(0, 0, n - 1, k - 1, n - 1);
    ans = combine(ans, v);
    upd(ind[a[i - k + 1]], ind[a[i - k + 1]] + k - 1, -1);
    if (i + 1 < n) {
      upd(ind[a[i + 1]], ind[a[i + 1]] + k - 1, 1);       
    }
  }
  for (int i = n - k + 1; i < n; ++i) {
    upd(ind[a[i]], ind[a[i]] + k - 1, -1); 
  }
  cout << ans.first << ' ' << ans.second << '\n'; 
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int q;
  cin >> n >> k >> q;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<int> b(n); 
  for (int i = 0; i < n; ++i) {
    cin >> b[i]; 
    ind[b[i]] = i; 
  }
  build(0, 0, n - 1); 
  solve(a); 
  while (q--) {
    int t;
    cin >> t;
    swap(a[t - 1], a[t]); 
    solve(a); 
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 3 ms 604 KB Output is correct
18 Correct 4 ms 604 KB Output is correct
19 Correct 4 ms 476 KB Output is correct
20 Correct 4 ms 600 KB Output is correct
21 Correct 4 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 4 ms 672 KB Output is correct
24 Correct 4 ms 856 KB Output is correct
25 Correct 5 ms 604 KB Output is correct
26 Correct 5 ms 604 KB Output is correct
27 Correct 5 ms 572 KB Output is correct
28 Correct 4 ms 472 KB Output is correct
29 Correct 4 ms 472 KB Output is correct
30 Correct 3 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 3 ms 604 KB Output is correct
18 Correct 4 ms 604 KB Output is correct
19 Correct 4 ms 476 KB Output is correct
20 Correct 4 ms 600 KB Output is correct
21 Correct 4 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 4 ms 672 KB Output is correct
24 Correct 4 ms 856 KB Output is correct
25 Correct 5 ms 604 KB Output is correct
26 Correct 5 ms 604 KB Output is correct
27 Correct 5 ms 572 KB Output is correct
28 Correct 4 ms 472 KB Output is correct
29 Correct 4 ms 472 KB Output is correct
30 Correct 3 ms 604 KB Output is correct
31 Correct 74 ms 5212 KB Output is correct
32 Correct 76 ms 5248 KB Output is correct
33 Correct 65 ms 5212 KB Output is correct
34 Correct 129 ms 5204 KB Output is correct
35 Correct 124 ms 5468 KB Output is correct
36 Correct 106 ms 5204 KB Output is correct
37 Correct 46 ms 5468 KB Output is correct
38 Correct 113 ms 5212 KB Output is correct
39 Incorrect 75 ms 5480 KB Output isn't correct
40 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 2 ms 356 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 2 ms 360 KB Output is correct
20 Correct 3 ms 468 KB Output is correct
21 Correct 2 ms 356 KB Output is correct
22 Correct 3 ms 480 KB Output is correct
23 Correct 2 ms 460 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 2 ms 344 KB Output is correct
26 Correct 2 ms 344 KB Output is correct
27 Correct 2 ms 472 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 2 ms 476 KB Output is correct
30 Correct 2 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 3 ms 604 KB Output is correct
18 Correct 4 ms 604 KB Output is correct
19 Correct 4 ms 476 KB Output is correct
20 Correct 4 ms 600 KB Output is correct
21 Correct 4 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 4 ms 672 KB Output is correct
24 Correct 4 ms 856 KB Output is correct
25 Correct 5 ms 604 KB Output is correct
26 Correct 5 ms 604 KB Output is correct
27 Correct 5 ms 572 KB Output is correct
28 Correct 4 ms 472 KB Output is correct
29 Correct 4 ms 472 KB Output is correct
30 Correct 3 ms 604 KB Output is correct
31 Correct 2 ms 364 KB Output is correct
32 Correct 2 ms 356 KB Output is correct
33 Correct 2 ms 348 KB Output is correct
34 Correct 2 ms 360 KB Output is correct
35 Correct 3 ms 468 KB Output is correct
36 Correct 2 ms 356 KB Output is correct
37 Correct 3 ms 480 KB Output is correct
38 Correct 2 ms 460 KB Output is correct
39 Correct 2 ms 348 KB Output is correct
40 Correct 2 ms 344 KB Output is correct
41 Correct 2 ms 344 KB Output is correct
42 Correct 2 ms 472 KB Output is correct
43 Correct 2 ms 348 KB Output is correct
44 Correct 2 ms 476 KB Output is correct
45 Correct 2 ms 348 KB Output is correct
46 Execution timed out 3052 ms 600 KB Time limit exceeded
47 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 3 ms 604 KB Output is correct
18 Correct 4 ms 604 KB Output is correct
19 Correct 4 ms 476 KB Output is correct
20 Correct 4 ms 600 KB Output is correct
21 Correct 4 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 4 ms 672 KB Output is correct
24 Correct 4 ms 856 KB Output is correct
25 Correct 5 ms 604 KB Output is correct
26 Correct 5 ms 604 KB Output is correct
27 Correct 5 ms 572 KB Output is correct
28 Correct 4 ms 472 KB Output is correct
29 Correct 4 ms 472 KB Output is correct
30 Correct 3 ms 604 KB Output is correct
31 Correct 74 ms 5212 KB Output is correct
32 Correct 76 ms 5248 KB Output is correct
33 Correct 65 ms 5212 KB Output is correct
34 Correct 129 ms 5204 KB Output is correct
35 Correct 124 ms 5468 KB Output is correct
36 Correct 106 ms 5204 KB Output is correct
37 Correct 46 ms 5468 KB Output is correct
38 Correct 113 ms 5212 KB Output is correct
39 Incorrect 75 ms 5480 KB Output isn't correct
40 Halted 0 ms 0 KB -