답안 #1114218

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1114218 2024-11-18T11:29:18 Z SalihSahin Sličnost (COI23_slicnost) C++14
50 / 100
145 ms 26308 KB
#include <bits/stdc++.h>
#define pb push_back
#define int long long
using namespace std;
 
const int inf = 1e15 + 10;
const int N = 2048 + 10;

pair<int, int> merge(pair<int, int> a, pair<int, int> b){
   if(a.first == b.first) return {a.first, a.second + b.second};
   else if(a.first > b.first) return a;
   else return b;
}

struct SEGT{
   vector<pair<int, int> > tree;
   vector<int> lazy;

   void init(int n){
      tree.assign(4*n, {0, 0});
      lazy.assign(4*n, 0);
   }

   void push(int ind){
      lazy[ind*2] += lazy[ind];
      tree[ind*2].first  += lazy[ind];
      lazy[ind*2+1] += lazy[ind];
      tree[ind*2+1].first += lazy[ind];
      lazy[ind] = 0;
   }

   void update(int ind, int l, int r, int ql, int qr, int val){
      if(l > r || l > qr || r < ql) return;
      if(l == r){
         tree[ind].first += val;
         tree[ind].second = 1;
      }
      else if(l >= ql && r <= qr){
         tree[ind].first += val;
         lazy[ind] += val;
      }
      else{
         int m = (l + r)/2;
         push(ind);

         update(ind*2, l, m, ql, qr, val);
         update(ind*2+1, m+1, r, ql, qr, val);

         tree[ind] = merge(tree[ind*2], tree[ind*2+1]);
         //cout<<ind<<" icin => "<<tree[ind*2].first<<" "<<tree[ind*2].second<<" ve "<<tree[ind*2+1].first<<" "<<tree[ind*2+1].second<<" mergelendi"<<endl;
      }
   }
};
 
int32_t main(){
   ios_base::sync_with_stdio(false);
   cin.tie(0); cout.tie(0);
   int n, k, query;
   cin>>n>>k>>query;
   vector<int> p(n), q(n), posp(n), posq(n);
   for(int i = 0; i < n; i++){
      cin>>p[i];
      p[i]--;
      posp[p[i]] = i;
   }
   for(int i = 0; i < n; i++){
      cin>>q[i];
      q[i]--;
      posq[q[i]] = i;
   }

   vector<pair<int, int> > segp(n), segq(n);
   int l, r;
   vector<array<int, 3> > updates[n+1];
   for(int i = 0; i < n; i++){
      l = max(0LL, posp[i] - k + 1), r = min(n, posp[i] + k) - k;
      segp[i] = {l, r};

      l = max(0LL, posq[i] - k + 1), r = min(n, posq[i] + k) - k;
      segq[i] = {l, r};

      updates[segp[i].first].pb({segq[i].first, segq[i].second, 1});
      updates[segp[i].second + 1].pb({segq[i].first, segq[i].second, -1});
   }

   pair<int, int> ans = {0, 0};
   SEGT seg;
   seg.init(n);
   for(int i = 1; i <= n; i++){
      seg.update(1, 1, n, i, i, 0);
   }
   for(int i = 0; i < n; i++){
      for(auto itr: updates[i]){
         seg.update(1, 1, n, itr[0] + 1, itr[1] + 1, itr[2]);
         //cout<<"i = "<<i<<" update => "<<itr[0]+1<<" "<<itr[1]+1<<" araligina "<<itr[2]<<endl;
      }
      //cout<<i<<" -> "<<seg.tree[1].first<<" "<<seg.tree[1].second<<endl;
      ans = merge(ans, seg.tree[1]);
   }

   cout<<ans.first<<" "<<ans.second<<endl;
   return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 508 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 2 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 508 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 2 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 7 ms 1616 KB Output is correct
17 Correct 5 ms 1784 KB Output is correct
18 Correct 4 ms 1488 KB Output is correct
19 Correct 5 ms 1616 KB Output is correct
20 Correct 6 ms 1616 KB Output is correct
21 Correct 5 ms 1616 KB Output is correct
22 Correct 4 ms 1656 KB Output is correct
23 Correct 7 ms 1616 KB Output is correct
24 Correct 6 ms 1616 KB Output is correct
25 Correct 5 ms 1616 KB Output is correct
26 Correct 7 ms 1872 KB Output is correct
27 Correct 7 ms 1692 KB Output is correct
28 Correct 6 ms 1616 KB Output is correct
29 Correct 4 ms 1616 KB Output is correct
30 Correct 4 ms 1592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 508 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 2 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 7 ms 1616 KB Output is correct
17 Correct 5 ms 1784 KB Output is correct
18 Correct 4 ms 1488 KB Output is correct
19 Correct 5 ms 1616 KB Output is correct
20 Correct 6 ms 1616 KB Output is correct
21 Correct 5 ms 1616 KB Output is correct
22 Correct 4 ms 1656 KB Output is correct
23 Correct 7 ms 1616 KB Output is correct
24 Correct 6 ms 1616 KB Output is correct
25 Correct 5 ms 1616 KB Output is correct
26 Correct 7 ms 1872 KB Output is correct
27 Correct 7 ms 1692 KB Output is correct
28 Correct 6 ms 1616 KB Output is correct
29 Correct 4 ms 1616 KB Output is correct
30 Correct 4 ms 1592 KB Output is correct
31 Correct 107 ms 24392 KB Output is correct
32 Correct 110 ms 24228 KB Output is correct
33 Correct 101 ms 22528 KB Output is correct
34 Correct 132 ms 23584 KB Output is correct
35 Correct 142 ms 26308 KB Output is correct
36 Correct 119 ms 25068 KB Output is correct
37 Correct 70 ms 24228 KB Output is correct
38 Correct 145 ms 25008 KB Output is correct
39 Correct 110 ms 25528 KB Output is correct
40 Correct 126 ms 24248 KB Output is correct
41 Correct 138 ms 25280 KB Output is correct
42 Correct 142 ms 24904 KB Output is correct
43 Correct 143 ms 24332 KB Output is correct
44 Correct 100 ms 24684 KB Output is correct
45 Correct 80 ms 23780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 508 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 2 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Incorrect 1 ms 336 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 508 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 2 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 7 ms 1616 KB Output is correct
17 Correct 5 ms 1784 KB Output is correct
18 Correct 4 ms 1488 KB Output is correct
19 Correct 5 ms 1616 KB Output is correct
20 Correct 6 ms 1616 KB Output is correct
21 Correct 5 ms 1616 KB Output is correct
22 Correct 4 ms 1656 KB Output is correct
23 Correct 7 ms 1616 KB Output is correct
24 Correct 6 ms 1616 KB Output is correct
25 Correct 5 ms 1616 KB Output is correct
26 Correct 7 ms 1872 KB Output is correct
27 Correct 7 ms 1692 KB Output is correct
28 Correct 6 ms 1616 KB Output is correct
29 Correct 4 ms 1616 KB Output is correct
30 Correct 4 ms 1592 KB Output is correct
31 Incorrect 1 ms 336 KB Output isn't correct
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 508 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 2 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 7 ms 1616 KB Output is correct
17 Correct 5 ms 1784 KB Output is correct
18 Correct 4 ms 1488 KB Output is correct
19 Correct 5 ms 1616 KB Output is correct
20 Correct 6 ms 1616 KB Output is correct
21 Correct 5 ms 1616 KB Output is correct
22 Correct 4 ms 1656 KB Output is correct
23 Correct 7 ms 1616 KB Output is correct
24 Correct 6 ms 1616 KB Output is correct
25 Correct 5 ms 1616 KB Output is correct
26 Correct 7 ms 1872 KB Output is correct
27 Correct 7 ms 1692 KB Output is correct
28 Correct 6 ms 1616 KB Output is correct
29 Correct 4 ms 1616 KB Output is correct
30 Correct 4 ms 1592 KB Output is correct
31 Correct 107 ms 24392 KB Output is correct
32 Correct 110 ms 24228 KB Output is correct
33 Correct 101 ms 22528 KB Output is correct
34 Correct 132 ms 23584 KB Output is correct
35 Correct 142 ms 26308 KB Output is correct
36 Correct 119 ms 25068 KB Output is correct
37 Correct 70 ms 24228 KB Output is correct
38 Correct 145 ms 25008 KB Output is correct
39 Correct 110 ms 25528 KB Output is correct
40 Correct 126 ms 24248 KB Output is correct
41 Correct 138 ms 25280 KB Output is correct
42 Correct 142 ms 24904 KB Output is correct
43 Correct 143 ms 24332 KB Output is correct
44 Correct 100 ms 24684 KB Output is correct
45 Correct 80 ms 23780 KB Output is correct
46 Incorrect 1 ms 336 KB Output isn't correct
47 Halted 0 ms 0 KB -