Codeforces Round #852 (Div. 2)

Revision en1, by Yuchang_Zhu, 2023-02-13 15:15:59

Codeforces Round #852 (Div. 2) 1793A - Yet Another Promotion

include <bits/stdc++.h>

using namespace std; int main() { int t; cin>>t; while (t--) { long long a,b,c,d; cin>>a>>b>>c>>d; if (a*d<=b*(d+1)) { long long ans=(c%(d+1))*min(a,b)+c/(d+1)*d*a; cout<<ans<<endl; } else { cout<<c*b<<endl; } } return 0; } 1793B - Fedya and Array

include <bits/stdc++.h>

using namespace std; int main() { long long t; cin>>t; while (t--) { int a,b; cin>>a>>b; int cnt=0; cout<<(a-b)*2<<endl; for (int i=b;i<=a;i++) { cout<<i<<" "; } for (int i=a-1;i>=b+1;i--) { cout<<i<<" "; } cout<<endl; } return 0; } 1793C - Dora and Search

include <bits/stdc++.h>

using namespace std; void solve() { int n; cin>>n; int a[222222]={},b[222222]={}; for (int i=0;i<n;i++) { cin>>a[i]; b[i]=a[i]; } sort(b,b+n); int l1=0,r1=n,l2=0,r2=n; bool f=1; while (f) { f=0; if (a[l1]==b[l2]) { l1++; l2++; f=1; } if (a[l1]==b[r2]) { l1++; r2--; f=1; } if (a[r1]==b[l2]) { r1--; l2++; f=1; } if (a[r1]==b[r2]) { r1--; r2--; f=1; } if (r1-l1<2) { cout<<"-1"<<endl; return ; } } cout<<l1+1<<" "<<r1+1<<endl; } int main() { int t; cin>>t; while (t--) { solve(); } return 0; } 1793D - Moscow Gorillas

include <bits/stdc++.h>

using namespace std; int p[222222],q[222222]; int main() { int n; cin>>n; for (int i=1;i<=n;i++) { int a; cin>>a; p[a]=i; } for (int i=1;i<=n;i++) { int a; cin>>a; q[a]=i; } int l=min(p[1],q[1]),r=max(p[1],q[1]); long long ans=1LL*l*(l-1)/2+1LL*(n-r+1)*(n-r)/2+1LL*(r-l)*(r-l-1)/2+1; for (int i=2;i<=n;i++) { int l2=1,r2=n; if (p[i]>=l&&p[i]<=r||q[i]>=l&&q[i]<=r) {

    }
    else
    {
       if (p[i]<l)
       {
         l2=max(l2,p[i]+1);
       }
       if (q[i]<l)
       {
         l2=max(l2,q[i]+1);
       }
       if (p[i]>r)
       {
         r2=min(r2,p[i]-1);
       }
       if (q[i]>r)
       {
         r2=min(r2,q[i]-1);
       }
       ans+=1LL*(l-l2+1)*(r2-r+1);
    }
    l=min(l,min(p[i],q[i]));
    r=max(r,max(p[i],q[i]));
}
cout<<ans<<endl;
return 0;

}

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English Yuchang_Zhu 2023-02-13 15:15:59 2232 Initial revision (published)