# Codeforces Round #703 (Div. 2) A-E 题解

Shifting Stacks

#include<cstdio>
#include<cstring>
#include<vector>
#include<cstring>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<iostream>
using namespace std;

#define dbg(x) cout << #x << " = " << (x) <<endl;
#define dbg2(x,y) cout << #x << " = " << (x) << " " << #y << " = " << (y) <<endl;
#define dbg3(x,y,z) cout << #x << " = " << (x) << " " << #y << " = " << (y) <<" " << #z << " = " << z <<endl;
#define ll long long
#define fi first
#define se second
#define pb push_back

const int MAX_N = 105;
ll arr[MAX_N];

int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,x;
ll sum = 0;
scanf("%d",&n);
int ck = n*(n-1)/2;
for(int i = 1;i<=n;++i)
{
scanf("%lld",&arr[i]);
}
bool flag = true;
for(int i = 1;i<=n;++i)
{
if(sum+arr[i]<(i-1))
{
flag = false;
break;
}
sum+=arr[i]-(i-1);
}
if(flag) printf("YES\n");
else printf("NO\n");
}

return 0;
}



Eastern Exhibition

#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;

#define debug(x) cout << #x << " = " << (x) <<endl;
#define ll long long
const int MAX_N = 200025;

ll arr[MAX_N],brr[MAX_N];

int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
for(int i = 1;i<=n;++i)
{
scanf("%lld",&arr[i]);scanf("%lld",&brr[i]);
}
sort(arr+1,arr+1+n);
sort(brr+1,brr+1+n);
if(n%2==0)
{
printf("%lld\n",(arr[n/2+1]-arr[n/2]+1)*(brr[n/2+1]-brr[n/2]+1));
}
else
{
printf("1\n");
}
}
return 0;
}



Guessing the Greatest

2 2 ^ 20 20 次方 > 1 e 6 1e6 所以我们自然想到二分

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
using namespace std;

#define dbg(x) cout << #x << " = "  << (x) << endl;

int Find(int l,int r)
{
int x;
printf("? %d %d\n\n",l,r);
fflush(stdout);
scanf("%d",&x);
return x;
}

int main()
{
bool flag = false;
int n,ans;
scanf("%d",&n);
int xb = Find(1,n);
if(xb<n&&Find(xb,n)==xb)
{
int l = xb+1, r = n;
while(l<=r)
{
int mid = l+r>>1;
int now_xb = Find(xb,mid);
if(now_xb==xb)
{
flag = true;
ans = mid;
r = mid - 1;
}
else
{
l = mid + 1;
}
}
if(flag)
{
printf("! %d\n",ans);
fflush(stdout);
}
}
if(xb>1&&!flag)
{
int l = 1,r = xb-1;
while(l<=r)
{
int mid = l+r>>1;
int now_xb = Find(mid,xb);
if(now_xb==xb)
{
flag = true;
ans = mid;
l = mid + 1;
}
else
{
r = mid - 1;
}
}
if(flag)
{
printf("! %d\n",ans);
fflush(stdout);
}
}

return 0;
}



Max Median

#include<cstdio>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cstring>
#include<set>
#include<cmath>
#include<stack>
using namespace std;
const int MAX_N = 200025;
int arr[MAX_N],brr[MAX_N],sum[MAX_N],minn[MAX_N];
map<int,int> mp;
#define dbg(x) cout << #x << " = " << (x) << endl;
#define dbg2(x,y) cout << #x << " = " << (x) << " " << #y << " = " << (y) << endl;
#define dbg3(x,y,z) cout << #x << " = " << (x) << " " << #y << " = " << (y) << " " << #z << " = " << (z) << endl;

int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i = 1;i<=n;++i)
{
scanf("%d",&arr[i]);
}
minn[0] = 0x3f3f3f3f;
sum[0] = 0;
int l = 1, r = n;
while(l<=r)
{
bool flag = false;
mp.clear();
mp[0] = 0;
int mid = l + r >>1;
for(int i = 1;i<=n;++i)
{
brr[i] = (arr[i]>=mid)?1:-1;
sum[i] = sum[i-1]+brr[i];
if(mp.find(sum[i])==mp.end()) mp[sum[i]] = i;
minn[i] = min(minn[i-1],sum[i]);
}
for(int i = m;i<=n;++i)
{
if(sum[i]>0) flag = true;
if(i>m&&((sum[i]-minn[i-m])>0)) flag = true;
}
if(flag) l = mid + 1;
else r = mid - 1;
}
printf("%d\n",r);

return 0;
}



Paired Payment

(was+w) 后续用大跟堆最短路所求即可

#include<cstdio>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cstring>
#include<set>
#include<cmath>
#include<stack>
#include<queue>
using namespace std;
const int MAX_N = 200025;
const int MAX_M = 200000*51+5;
const int INF = 1e9+7;

#define ll long long
#define dbg(x) cout << #x << " = " << (x) << endl;
#define dbg2(x,y) cout << #x << " = " << (x) << " " << #y << " = " << (y) << endl;
#define dbg3(x,y,z) cout << #x << " = " << (x) << " " << #y << " = " << (y) << " " << #z << " = " << (z) << endl;

vector<pair<int,int> > vt[MAX_M];
priority_queue<pair<int,int> > q;
int dp[MAX_M];

{
vt[u*51].push_back(make_pair(v*51+w,0)); // middle point
for(int was = 1;was<=50;++was)
{
vt[u*51+was].push_back(make_pair(v*51,(was+w)*(was+w))); // end point
}
}

int main()
{
int n,m,u,v,w;
scanf("%d%d",&n,&m);
for(int i = 1;i<=n*51;++i)
{
dp[i] = INF;
}

for(int i = 1;i<=m;++i)
{
scanf("%d%d%d",&u,&v,&w);
u--,v--;
}

dp[0] = 0;
q.push(make_pair(-dp[0],0));

while(!q.empty())
{
pair<int,int> top = q.top();
q.pop();
for(auto v:vt[top.second])
{
if(dp[v.first]>-top.first+v.second)
{
dp[v.first] = -top.first+v.second;
q.push(make_pair(-dp[v.first],v.first));
}
}
}

for(int i=0;i<n;++i)
{
if(dp[i*51]==INF) dp[i*51] = -1;
i==n?printf("%d\n",dp[i*51]):printf("%d ",dp[i*51]);
}
return 0;
}


• 点赞
• 评论
• 分享
x

海报分享

扫一扫，分享海报

• 收藏
• 打赏

打赏

ljq真的不能再吃了

你的鼓励将是我创作的最大动力

C币 余额
2C币 4C币 6C币 10C币 20C币 50C币
• 举报
• 一键三连

点赞Mark关注该博主, 随时了解TA的最新博文

02-19 1174
09-26 53