Submission #978800

#TimeUsernameProblemLanguageResultExecution timeMemory
978800stefanopulosSličnost (COI23_slicnost)C++17
17 / 100
375 ms278644 KiB
#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <bits/stdc++.h> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ldb; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef pair<ldb,ldb> pdd; #define ff(i,a,b) for(int i = a; i <= b; i++) #define fb(i,b,a) for(int i = b; i >= a; i--) #define trav(a,x) for(auto& a : x) #define sz(a) (int)(a).size() #define fi first #define se second #define pb push_back #define lb lower_bound #define ub upper_bound #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // os.order_of_key(k) the number of elements in the os less than k // *os.find_by_order(k) print the k-th smallest number in os(0-based) const int mod = 1000000007; const int inf = 1e9 + 5; const int mxN = 100005; int n, k, q; int A[mxN]; int B[mxN]; int poz[mxN]; int L[mxN]; int R[mxN]; int idx = 0; int root[100 * mxN], ls[100 * mxN], rs[100 * mxN], lenj[100 * mxN]; ll bor[100 * mxN][2]; void build(int& v, int tl, int tr){ v = ++idx; lenj[v] = 0; if(tl == tr){ bor[v][0] = 0; bor[v][1] = 1; return; } int mid = (tl + tr) / 2; build(ls[v], tl, mid); build(rs[v], mid + 1, tr); bor[v][0] = max(bor[ls[v]][0], bor[rs[v]][0]); bor[v][1] = (bor[ls[v]][0] == bor[v][0] ? bor[ls[v]][1] : 0) + (bor[rs[v]][0] == bor[v][0] ? bor[rs[v]][1] : 0); } void propagate(int v, int tl, int tr){ if(lenj[v] != 0){ bor[v][0] += lenj[v]; if(tl != tr){ lenj[ls[v]] += lenj[v]; lenj[rs[v]] += lenj[v]; } lenj[v] = 0; } } void lazyupd(int& v, int rv, int tl, int tr, int l, int r, int val){ v = ++idx; ls[v] = ls[rv]; rs[v] = rs[rv]; bor[v][0] = bor[rv][0]; bor[v][1] = bor[rv][1]; lenj[v] += lenj[rv]; propagate(v, tl, tr); if(tl > tr || tl > r || l > tr)return; if(tl >= l && tr <= r){ lenj[v] += val; propagate(v, tl, tr); return; } int mid = (tl + tr) / 2; lazyupd(ls[v], ls[rv], tl, mid, l, r, val); lazyupd(rs[v], rs[rv], mid + 1, tr, l, r, val); bor[v][0] = max(bor[ls[v]][0], bor[rs[v]][0]); bor[v][1] = (bor[ls[v]][0] == bor[v][0] ? bor[ls[v]][1] : 0) + (bor[rs[v]][0] == bor[v][0] ? bor[rs[v]][1] : 0); } void calc(){ idx = 0; build(root[1],1,n - k + 1); ff(i,1,k){ int l = L[poz[A[i]]]; int r = R[poz[A[i]]]; lazyupd(root[1],root[1],1,n - k + 1,l,r,1); } int mx = bor[root[1]][0]; ll br = bor[root[1]][1]; ff(i,k + 1,n){ int l1 = L[poz[A[i - k]]]; int r1 = R[poz[A[i - k]]]; lazyupd(root[i - k + 1],root[i - k],1,n - k + 1,l1,r1,-1); int l2 = L[poz[A[i]]]; int r2 = R[poz[A[i]]]; lazyupd(root[i - k + 1],root[i - k + 1],1,n - k + 1,l2,r2,1); if(bor[root[i - k + 1]][0] > mx){ mx = bor[root[i - k + 1]][0]; br = bor[root[i - k + 1]][1]; } else if(bor[root[i - k + 1]][0] == mx)br += bor[root[i - k + 1]][1]; } cout << mx << " " << br << '\n'; } int main(){ cin.tie(0)->sync_with_stdio(0); cin >> n >> k >> q; ff(i,1,n)cin >> A[i]; ff(i,1,n)cin >> B[i], poz[B[i]] = i; ff(i,1,n){ L[i] = max(1, i - k + 1); R[i] = min(i, n - k + 1); } calc(); while(q--){ int t; cin >> t; // int a = A[t]; // int b = A[t + 1]; // int x = t - k + 1; // if(x >= 1){ // } // int y = t + k - 1; swap(A[t], A[t + 1]); calc(); } return 0; } /* 4 3 0 2 4 1 3 1 2 3 4 // probati bojenje sahovski */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...