답안 #1059654

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1059654 2024-08-15T06:46:32 Z NeroZein Sličnost (COI23_slicnost) C++17
57 / 100
3000 ms 5720 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, long long> combine(pair<int, long long> x, pair<int, long long> 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, long long> 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 1 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 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 348 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 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 348 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 3 ms 604 KB Output is correct
18 Correct 3 ms 600 KB Output is correct
19 Correct 4 ms 716 KB Output is correct
20 Correct 4 ms 716 KB Output is correct
21 Correct 3 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 5 ms 600 KB Output is correct
24 Correct 3 ms 604 KB Output is correct
25 Correct 4 ms 604 KB Output is correct
26 Correct 5 ms 856 KB Output is correct
27 Correct 5 ms 720 KB Output is correct
28 Correct 4 ms 604 KB Output is correct
29 Correct 4 ms 604 KB Output is correct
30 Correct 3 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 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 348 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 3 ms 604 KB Output is correct
18 Correct 3 ms 600 KB Output is correct
19 Correct 4 ms 716 KB Output is correct
20 Correct 4 ms 716 KB Output is correct
21 Correct 3 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 5 ms 600 KB Output is correct
24 Correct 3 ms 604 KB Output is correct
25 Correct 4 ms 604 KB Output is correct
26 Correct 5 ms 856 KB Output is correct
27 Correct 5 ms 720 KB Output is correct
28 Correct 4 ms 604 KB Output is correct
29 Correct 4 ms 604 KB Output is correct
30 Correct 3 ms 604 KB Output is correct
31 Correct 48 ms 5336 KB Output is correct
32 Correct 65 ms 5376 KB Output is correct
33 Correct 69 ms 5456 KB Output is correct
34 Correct 103 ms 5208 KB Output is correct
35 Correct 113 ms 5464 KB Output is correct
36 Correct 73 ms 5312 KB Output is correct
37 Correct 45 ms 5468 KB Output is correct
38 Correct 107 ms 5316 KB Output is correct
39 Correct 76 ms 5720 KB Output is correct
40 Correct 109 ms 5156 KB Output is correct
41 Correct 121 ms 5340 KB Output is correct
42 Correct 132 ms 5208 KB Output is correct
43 Correct 108 ms 5324 KB Output is correct
44 Correct 100 ms 5468 KB Output is correct
45 Correct 72 ms 5208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 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 348 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 2 ms 600 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 3 ms 348 KB Output is correct
20 Correct 3 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 4 ms 484 KB Output is correct
24 Correct 2 ms 344 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 3 ms 348 KB Output is correct
29 Correct 2 ms 432 KB Output is correct
30 Correct 3 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 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 348 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 3 ms 604 KB Output is correct
18 Correct 3 ms 600 KB Output is correct
19 Correct 4 ms 716 KB Output is correct
20 Correct 4 ms 716 KB Output is correct
21 Correct 3 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 5 ms 600 KB Output is correct
24 Correct 3 ms 604 KB Output is correct
25 Correct 4 ms 604 KB Output is correct
26 Correct 5 ms 856 KB Output is correct
27 Correct 5 ms 720 KB Output is correct
28 Correct 4 ms 604 KB Output is correct
29 Correct 4 ms 604 KB Output is correct
30 Correct 3 ms 604 KB Output is correct
31 Correct 2 ms 348 KB Output is correct
32 Correct 2 ms 600 KB Output is correct
33 Correct 2 ms 348 KB Output is correct
34 Correct 3 ms 348 KB Output is correct
35 Correct 3 ms 348 KB Output is correct
36 Correct 2 ms 348 KB Output is correct
37 Correct 2 ms 348 KB Output is correct
38 Correct 4 ms 484 KB Output is correct
39 Correct 2 ms 344 KB Output is correct
40 Correct 2 ms 348 KB Output is correct
41 Correct 2 ms 348 KB Output is correct
42 Correct 2 ms 348 KB Output is correct
43 Correct 3 ms 348 KB Output is correct
44 Correct 2 ms 432 KB Output is correct
45 Correct 3 ms 348 KB Output is correct
46 Execution timed out 3089 ms 716 KB Time limit exceeded
47 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 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 348 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 3 ms 604 KB Output is correct
18 Correct 3 ms 600 KB Output is correct
19 Correct 4 ms 716 KB Output is correct
20 Correct 4 ms 716 KB Output is correct
21 Correct 3 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 5 ms 600 KB Output is correct
24 Correct 3 ms 604 KB Output is correct
25 Correct 4 ms 604 KB Output is correct
26 Correct 5 ms 856 KB Output is correct
27 Correct 5 ms 720 KB Output is correct
28 Correct 4 ms 604 KB Output is correct
29 Correct 4 ms 604 KB Output is correct
30 Correct 3 ms 604 KB Output is correct
31 Correct 48 ms 5336 KB Output is correct
32 Correct 65 ms 5376 KB Output is correct
33 Correct 69 ms 5456 KB Output is correct
34 Correct 103 ms 5208 KB Output is correct
35 Correct 113 ms 5464 KB Output is correct
36 Correct 73 ms 5312 KB Output is correct
37 Correct 45 ms 5468 KB Output is correct
38 Correct 107 ms 5316 KB Output is correct
39 Correct 76 ms 5720 KB Output is correct
40 Correct 109 ms 5156 KB Output is correct
41 Correct 121 ms 5340 KB Output is correct
42 Correct 132 ms 5208 KB Output is correct
43 Correct 108 ms 5324 KB Output is correct
44 Correct 100 ms 5468 KB Output is correct
45 Correct 72 ms 5208 KB Output is correct
46 Correct 2 ms 348 KB Output is correct
47 Correct 2 ms 600 KB Output is correct
48 Correct 2 ms 348 KB Output is correct
49 Correct 3 ms 348 KB Output is correct
50 Correct 3 ms 348 KB Output is correct
51 Correct 2 ms 348 KB Output is correct
52 Correct 2 ms 348 KB Output is correct
53 Correct 4 ms 484 KB Output is correct
54 Correct 2 ms 344 KB Output is correct
55 Correct 2 ms 348 KB Output is correct
56 Correct 2 ms 348 KB Output is correct
57 Correct 2 ms 348 KB Output is correct
58 Correct 3 ms 348 KB Output is correct
59 Correct 2 ms 432 KB Output is correct
60 Correct 3 ms 348 KB Output is correct
61 Execution timed out 3089 ms 716 KB Time limit exceeded
62 Halted 0 ms 0 KB -