Submission #926056

#TimeUsernameProblemLanguageResultExecution timeMemory
926056AmrSličnost (COI23_slicnost)C++14
17 / 100
102 ms17120 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define S second #define F first #define all(x) (x).begin(),(x).end() #define sz size() #define Yes cout << "YES" << endl #define No cout << "NO" << endl #define pb(x) push_back(x); #define endl '\n' #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); const int N=8e5+7; ll INF=INT_MAX,mod=1e9+7; int TT=1; ll power(ll x, unsigned int y) { ll res = 1; x = x; // % mod; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res*x) ; // % mod; y = y>>1; x = (x*x) ; // % mod; } return res; } int siz = 1; pair<int,int> val[N]; int L[N]; int R[N]; int a[N]; int b[N]; int n , k , q; ll s[N]; int pro[N]; void build(ll x, ll lx, ll rx) { if(rx-lx==1) { pro[x] = 0; val[x] = {0,1}; return; } ll mid = (lx+rx)/2; build(2*x+1,lx,mid); build(2*x+2,mid,rx); val[x].S = val[2*x+1].S + val[2*x+2].S; val[x].F = 0; } void rebuild() { while(siz<=n) siz*=2; build(0,0,siz); for(int i = 1; i <= n; i++) s[i] = 0; } void update(ll l , ll r, ll num , ll x = 0, ll lx = 0, ll rx = siz) { if(lx>=r||rx<=l) return; // if(rx-lx>1) { val[2*x+1].F+=pro[x]; val[2*x+2].F+=pro[x]; pro[2*x+1] += pro[x]; pro[2*x+2] += pro[x]; pro[x] = 0; } if(lx>=l&&rx<=r) { val[x].F +=num; pro[x] +=num; return; } ll mid = (lx+rx)/2; update(l,r,num,2*x+1,lx,mid); update(l,r,num,2*x+2,mid,rx); if(val[2*x+1].F==val[2*x+2].F) val[x] = {val[2*x+1].F,val[2*x+2].S+val[2*x+1].S}; else val[x] = max(val[2*x+1],val[2*x+2]); //pro[x] = pro[2*x+1]+pro[2*x+2]; } pair<ll,ll> get() { int mx = 0; rebuild(); for(int i = 1; i < k; i++) { //cout << L[a[i]] << " " << R[a[i]] << endl; update(L[a[i]],R[a[i]]+1,1); } //update(1,siz); //return {val[0].F, val[0].S}; for(int i = k; i <= n;i++) { if(i-k>0) update(L[a[i-k]],R[a[i-k]]+1,-1); update(L[a[i]],R[a[i]]+1,1); s[val[0].F]+=val[0].S; //cout << val[0].F << " " << val[0].S << endl; mx=max(mx,val[0].F); } return {mx,s[mx]}; } void solve() { cin >> n >> k >> q; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i <= n;i++) cin >> b[i]; for(int i = 1; i <= n; i++) { L[b[i]] = max(1,i-k+1); R[b[i]] = min(i,n-k+1); //cout << L[b[i]] << " " << R[b[i]] << endl; } pair<int,int> p = get(); cout << p.F << " " << p.S << endl; while(q--) { int x; cin >> x; swap(a[x],a[x+1]); pair<int,int> p = get(); cout << p.F << " " << p.S << endl;; } } int main(){ //freopen("friday.in","r",stdin); //freopen("friday.out","w",stdout); fast; while(TT--) solve(); return 0; }
#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...