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. zookeeper-监控与优化-《每日五分钟搞定大数据》

    本文的命令和配置都是基于zookeeper-3.4.6版本.优化很多时候都是基于监控的,所以把这两个内容写在了一起,慢慢消化. 监控 简单地说,监控无非就是获取服务的一些指标,再根据实际业务情况给这些 ...

  2. COMCMS_CORE 起步篇,如何运行和部署

    前言:关于最近开源后,不少朋友问,怎么我下载下来,运行不了.或者怎么没有左边菜单.货不对板?还是我吃了数据? 感言:开源不容易,更不容易的是,明明毫无保留,还这么大误会,真是泪奔..... 好了.步入 ...

  3. React中嵌套组件与被嵌套组件的通信

    前言 在React项目的开发中经常会遇到这样一个场景:嵌套组件与被嵌套组件的通信. 比如Tab组件啊,或者下拉框组件. 场景 这里应用一个最简单的Tab组件来呈现这个场景. import React, ...

  4. Division and Union CodeForces - 1101C (排序后处理)

    There are nn segments [li,ri][li,ri] for 1≤i≤n1≤i≤n. You should divide all segments into two non-emp ...

  5. Python里面如何拷贝一个对象

    1.赋值(=),就是创建了对象的一个新的引用,修改其中任意一个变量都会影响到另一个. In [168]: a Out[168]: [1, 2, 3] In [169]: b=a In [170]: a ...

  6. PAT L2-023 图着色问题

    https://pintia.cn/problem-sets/994805046380707840/problems/994805057298481152 图着色问题是一个著名的NP完全问题.给定无向 ...

  7. Oracle RMAN备份与还原注意事项

    1 备份文件管理 如果要删除之前的备份,不要手动去目录下删除,应该在rman命令模式下使用删除命令,否则虽然在磁盘上把物理备份文件删除了,但是使用备份查看命令会一直看到已经删除的备份文件 list b ...

  8. Mission Impossible 6

    题目:Mission Impossible 6 题目链接:http://hihocoder.com/problemset/problem/1228 题目大意: 大概就是让我们写一个代码模拟文本编辑器的 ...

  9. 如何让pl/sql developer记住密码,实现快速登录

    前两天,有同事使用plsql的时候,切换数据库的时候需要不断的重复输入密码,这样太麻烦了. 下面,我这里说下如何的实现plsql不需要输入密码就能快速登录的方法: 1.一开始登录,首先像往常那样输入密 ...

  10. css特殊样式

    span{ color: blue; border:1px solid black;}.extra span{ color: inherit;} 清除原有样式 text-decoration: non ...