A:显然从大到小排序后贪心放在第一个能放的位置即可。并查集维护。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 300010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,m,a[N],b[N],id[N],fa[N<<1];
ll ans;
bool cmp(const int&x,const int&y)
{
return a[x]>a[y];
}
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read(),m=read();
for (int i=1;i<=n;i++) id[i]=i,a[i]=read();
sort(id+1,id+n+1,cmp);
for (int i=m+1;i<=m+n+1;i++) fa[i]=i;
for (int i=1;i<=n;i++)
{
b[id[i]]=find(max(m+1,id[i]));
ans+=1ll*a[id[i]]*(b[id[i]]-id[i]);
fa[b[id[i]]]=find(b[id[i]]+1);
}
cout<<ans<<endl;
for (int i=1;i<=n;i++) printf("%d ",b[i]);
return 0;
//NOTICE LONG LONG!!!!!
}

  B:对前后缀处理出答案,two pointers即可。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 200010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,m,k;
ll pre[N],suf[N],cost[N];
bool flag[N];
struct data
{
int t,x,y,c;
bool operator <(const data&a) const
{
return t<a.t;
}
}a[N];
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read(),m=read(),k=read();
for (int i=1;i<=m;i++)
{
int t=read(),x=read(),y=read(),c=read();
a[i].t=t,a[i].x=x,a[i].y=y,a[i].c=c;
}
sort(a+1,a+m+1);
memset(pre,42,sizeof(pre));int cnt=0;
memset(cost,42,sizeof(cost));
memset(flag,0,sizeof(flag));
for (int i=1;i<=m;i++)
{
pre[i]=pre[i-1];
if (a[i].y==0)
{
if (!flag[a[i].x])
{
cnt++;
cost[a[i].x]=a[i].c;
flag[a[i].x]=1;
if (cnt==n)
{
pre[i]=0;
for (int j=1;j<=n;j++) pre[i]+=cost[j];
}
}
else
if (a[i].c<cost[a[i].x])
{
if (cnt==n) pre[i]-=cost[a[i].x]-a[i].c;
cost[a[i].x]=a[i].c;
}
}
}
memset(suf,42,sizeof(suf));cnt=0;
memset(cost,42,sizeof(cost));
memset(flag,0,sizeof(flag));
for (int i=m;i>=1;i--)
{
suf[i]=suf[i+1];
if (a[i].x==0)
{
if (!flag[a[i].y])
{
cnt++;flag[a[i].y]=1;
cost[a[i].y]=a[i].c;
if (cnt==n)
{
suf[i]=0;
for (int j=1;j<=n;j++) suf[i]+=cost[j];
}
}
else
if (a[i].c<cost[a[i].y])
{
if (cnt==n) suf[i]-=cost[a[i].y]-a[i].c;
cost[a[i].y]=a[i].c;
}
}
}
int x=0;ll ans=pre[0];
for (int i=1;i<=m;i++)
{
while (a[i].t-a[x+1].t>k) x++;
if (x) ans=min(ans,pre[x]+suf[i]);
}
if (ans==pre[0]) cout<<-1;
else cout<<ans;
return 0;
//NOTICE LONG LONG!!!!!
}

  C:根据查询矩形边界将平面分成九块,讨论两端点位置即可,主席树支持查询矩形内点的个数。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 200010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,q,a[N],root[N],cnt;
struct data{int l,r,x;
}tree[N<<6];
void ins(int &k,int l,int r,int x)
{
tree[++cnt]=tree[k];k=cnt;tree[k].x++;
if (l==r) return;
int mid=l+r>>1;
if (x<=mid) ins(tree[k].l,l,mid,x);
else ins(tree[k].r,mid+1,r,x);
}
int Query(int x,int y,int l,int r,int p,int q)
{
if (!y) return 0;
if (l==p&&r==q) return tree[y].x-tree[x].x;
int mid=l+r>>1;
if (q<=mid) return Query(tree[x].l,tree[y].l,l,mid,p,q);
else if (p>mid) return Query(tree[x].r,tree[y].r,mid+1,r,p,q);
else return Query(tree[x].l,tree[y].l,l,mid,p,mid)+Query(tree[x].r,tree[y].r,mid+1,r,mid+1,q);
}
int query(int l,int r,int x,int y)
{
if (l>r||x>y) return 0;
return Query(root[l-1],root[r],1,n,x,y);
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read(),q=read();
for (int i=1;i<=n;i++)
{
root[i]=root[i-1];
a[i]=read();
ins(root[i],1,n,a[i]);
}
for (int _=1;_<=q;_++)
{
int l=read(),d=read(),r=read(),u=read();
int x=query(l,r,d,u),f=query(l,r,1,d-1),g=query(l,r,u+1,n);
int v=query(1,l-1,d,n),w=query(1,l-1,1,u);
ll ans=0;
ans+=1ll*f*v;
ans+=1ll*g*w;
ans+=1ll*x*(l-1);
ans+=1ll*(r-l+1)*(r-l)/2;
ans-=1ll*f*(f-1)/2;
ans-=1ll*g*(g-1)/2;
ans+=1ll*query(r+1,n,1,d-1)*(x+g+v);
ans+=1ll*query(r+1,n,u+1,n)*(x+f+w);
ans+=1ll*query(r+1,n,d,u)*r;
printf("%I64d\n",ans);
}
return 0;
//NOTICE LONG LONG!!!!!
}

  D:显然每天要么不用优惠,要么就尽量用优惠。并且显然如果某天可以优惠到免费,使用优惠不会更劣。所以直接f[i][j]表示前i天剩余优惠为j时的最小代价,瞎转移即可,由上面的性质j不会超过21。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 300010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,a[N],f[N][32];
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read();
for (int i=1;i<=n;i++) a[i]=read()/100;
memset(f,42,sizeof(f));f[0][0]=0;
for (int i=1;i<=n;i++)
{
for (int j=0;j<=30;j++)
if (j>=a[i]/10) f[i][j]=f[i-1][j-a[i]/10]+a[i];
for (int j=0;j<=30-a[i];j++)
f[i][j]=min(f[i][j],f[i-1][j+a[i]]);
for (int j=0;j<=a[i];j++) f[i][0]=min(f[i][0],f[i-1][j]+a[i]-j);
}
int ans=1000000000;
for (int i=0;i<=30;i++) ans=min(ans,f[n][i]);
cout<<100ll*ans;
return 0;
//NOTICE LONG LONG!!!!!
}

  

Codeforces Round #433 Div. 1的更多相关文章

  1. Codeforces Round #433 (Div. 2)【A、B、C、D题】

    题目链接:Codeforces Round #433 (Div. 2) codeforces 854 A. Fraction[水] 题意:已知分子与分母的和,求分子小于分母的 最大的最简分数. #in ...

  2. Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises)

    A. Fraction 题目链接:http://codeforces.com/contest/854/problem/A 题目意思:给出一个数n,求两个数a+b=n,且a/b不可约分,如果存在多组满足 ...

  3. codeforces 853b//Jury Meeting// Codeforces Round #433 (Div. 1)

    题意:几个人要去一个城市k天,现给出各航班的日期和花费,让这n个人能相会k天的最小花费? 用数组arr1[i]记录在第i天人到齐的最小花费.arr2[i]记录第i天之后才有人开始走的最小花费.然后取a ...

  4. Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) D. Jury Meeting(双指针模拟)

    D. Jury Meeting time limit per test 1 second memory limit per test 512 megabytes input standard inpu ...

  5. Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) D

    Country of Metropolia is holding Olympiad of Metrpolises soon. It mean that all jury members of the ...

  6. Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) C

    Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are n ...

  7. Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) B

    Maxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house has n apartme ...

  8. Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) A

    Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned tha ...

  9. 【Codeforces Round #433 (Div. 1) B】Jury Meeting

    [链接]h在这里写链接 [题意] 有n个人,它们都要在某一时刻开始,全都到达0位置,然后维持最少k个时间单位,然后再全都回到原来的位置; 第i个人初始的位置是i. 且一共有m班航班. 每一班航班,要么 ...

随机推荐

  1. ASP.NET Core MVC之ViewComponents(视图组件)知多少?

    前言 大概一个来星期未更新博客了,久违了各位,关于SQL Server性能优化会和ASP.NET Core MVC穿插来讲,如果你希望我分享哪些内容可以在评论下方提出来,我会筛选并看看技术文档来对你的 ...

  2. python读取/创建XML文件

    Python中定义了很多处理XML的函数,如xml.dom,它会在处理文件之前,将根据xml文件构建的树状数据存在内存.还有xml.sax,它实现了SAX API,这个模块牺牲了便捷性,换取了速度和减 ...

  3. RuntimeError: Model class apps.users.models.User doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

    报错代码: File "/home/bsodgm/Desktop/Django_projection/mall/apps/users/views.py", line 9, in & ...

  4. Leetcode 686 Repeated String Match

    Given two strings A and B, find the minimum number of times A has to be repeated such that B is a su ...

  5. 爱奇艺2017秋招笔试(C++智能设备方向)

    虽然有方向,但是好像题目都是随机题库抽取. 选择题都很基础...挖坑,待更新 编程: 一. 奇异数: 如果一个数字满足以下条件,我们就称它为奇异数: 1.   这个数字至少有两位 2. 这个数的最低两 ...

  6. Contest1692 - 2019寒假集训第三十一场 UPC 11075 Problem D 小P的国际象棋

    非常简单的单点修改+区间加+区间查询.我用的是最近刚学的区间修改版本树状数组.  直接维护即可,注意修改后的单点值已经不是a[i],或者b[i],要通过区间查询求单点.不然是错的. 区间修改版本树状数 ...

  7. NET操作RabbitMQ组件EasyNetQ

    NET操作RabbitMQ组件EasyNetQ使用中文简版文档. 本文出自EasyNetQ官方文档,内容为自己理解加翻译.文档地址:https://github.com/EasyNetQ/EasyNe ...

  8. 为github添加ssh key

    用git关联github上的远程仓库前需要先为github添加ssh key 一.检查本机是否生成ssh key 本地查找.ssh文件,其中id_rsa.pub中的内容就是ssh key 二.为git ...

  9. Jmeter监控服务器笔记

    Jmeter监控服务器-CPU,Memory,Disk,Network性能指标 本文主要说一下如何通过JMeter插件来监控服务器CPU.内存.磁盘.网络等相关资源. 一.下载 首先进入网址https ...

  10. vue嵌套路由

    父组件  (注:to="/Flow/moban_a"这里不是文件加路径,是父组件路由+子组件路由) 路由配置