T1

\(solution\)

求出第一个开始下降的位置,移动到连续的与它相同的数的最前面的一个数的位置,记录为\(p\)

\(p\)以前的位置的数与原数相同,\(p\)位置为原数-1,后面全部为9

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std; const int MAXN=200010; int n,a[MAXN],ans[MAXN];
char s[MAXN]; int main()
{
freopen("increase.in","r",stdin);
freopen("increase.out","w",stdout);
scanf("%s",s+1);
n=strlen(s+1);
for(int i=1;i<=n;++i)
a[i]=s[i]-'0';
int pos=n+1;
for(int i=1;i<n;++i)
if(a[i]>a[i+1]){
pos=i;
break;
}
if(pos<n)
while(pos>1&&a[pos-1]==a[pos]) --pos;
for(int i=1;i<=n;++i){
if(i<pos) ans[i]=a[i];
else if(i==pos) ans[i]=a[i]-1;
else ans[i]=9;
}
int i=1;
while(ans[i]==0&&i<n) ++i;
for(;i<=n;++i)
printf("%d",ans[i]);
puts("");
fclose(stdin); fclose(stdout);
return 0;
}

T2

\(solution\)

考虑每一对逆序对的贡献为$a[i] \times a[j] \times i \times (n-j+1) $

用树状数组维护满足a[i]>a[j]的$ \sum{ a[j] \times (n-j+1)} $即可

也可以在归并排序时记录一个后缀和处理

需要龟速乘法防止爆long long

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#define int long long
using namespace std; const int MAXN=100010;
const int MOD=1000000000007ll; inline int read(){
int x=0,f=1; char c=getchar();
while(c<'0'){ if(c=='-') f=-1; c=getchar(); }
while(c>='0') x=(x<<3)+(x<<1)+c-'0',c=getchar();
return x*f;
} inline int mul(int x,int y){
int s=0ll;
while(y){
if(y&1) s=(s+x)%MOD;
y>>=1ll;
x=(x+x)%MOD;
}
return s;
} int n,Ans;
struct Data{
int v,id,nv;
} a[MAXN]; inline bool cmp1(Data x,Data y){
return x.v<y.v;
} inline bool cmp2(Data x,Data y){
return x.id<y.id;
} int tree[MAXN];
inline int lowbit(int x){ return x&(-x); }
inline int query(int x){
int ans=0;
for(;x;x-=lowbit(x))
ans=(ans+tree[x])%MOD;
return ans;
}
inline void update(int x,int d){
for(;x<=n;x+=lowbit(x))
tree[x]=(tree[x]+d)%MOD;
} signed main()
{
freopen("multiplication.in","r",stdin);
freopen("multiplication.out","w",stdout);
scanf("%lld",&n);
if(n<=1000){
for(int i=1;i<=n;++i)
a[i].v=read();
int tmp1,tmp2;
for(int i=1;i<n;++i)
for(int j=i+1;j<=n;++j)
if(a[i].v>a[j].v){
tmp1=mul(a[i].v,a[j].v);
tmp2=mul(i,n-j+1);
Ans=(Ans+mul(tmp1,tmp2))%MOD;
}
printf("%lld\n",(Ans+MOD)%MOD);
}
else{
for(int i=1;i<=n;++i)
a[i].v=read(),a[i].id=i;
sort(a+1,a+1+n,cmp1);
int cnt=0; a[0].v=-1;
for(int i=1;i<=n;++i)
a[i].nv=(a[i].v==a[i-1].v)?cnt:++cnt;
sort(a+1,a+1+n,cmp2);
for(int i=n;i>=1;--i){
Ans=(Ans+mul(mul(a[i].v,i),query(a[i].nv-1)))%MOD;
int d=mul(a[i].v,n-i+1);
update(a[i].nv,d);
}
printf("%lld\n",(Ans+MOD)%MOD);
}
fclose(stdin); fclose(stdout);
return 0;
}
/*
5
3 2 1 5 4
125
6
1000 2 400 6 1 400
9
100000 23333 19260817 19491001 2897370649 1 32 114514 1919810
78834965239
*/

T3

\(solution1\)

先检查各个小正方形的面积和是否等于大正方形,

之后只要满足不重叠就可以了

扫描线线段树维护,在区间加入覆盖标记前判断是否已经被覆盖

\(solution2\)

先检查面积,再判重叠

考察一个图中的每一个点,不难发现,以每个点为原点,每个点的四个象限都必须有且只有一个矩形覆盖

于是对每个点维护四个标记,对于边、角特殊处理,每个矩形的对四个角上的点的对应象限打标记即可

简化:内部的一个点只能成为2个或4个矩形的顶点,直接记录判断即可

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm> using namespace std; #define INF 2147483647
#define maxn 100010 int n,rectangles[maxn][4]; struct point
{
int x,y,d;
point(){}
point(int a,int b,int c)
{
x=a;y=b;d=c;
}
}p[maxn<<2],q[maxn<<2]; bool operator<(const point &a,const point &b)
{
if (a.x!=b.x) return a.x<b.x;
return a.y<b.y;
} bool cmp(const point &a,const point &b)
{
if (a.y!=b.y) return a.y<b.y;
return a.x<b.x;
} struct line
{
int x,y,l,r,d;
line(){}
line(int a,int b,int c,int e)
{
x=a;y=a;l=b;r=c;d=e;
}
}vert[maxn<<2],hori[maxn<<2]; bool operator<(const line &a,const line &b)
{
if (a.x!=b.x) return a.x<b.x;
if (a.l!=b.l) return a.l<b.l;
return a.r<b.r;
} bool isRectangleCover() {
int minx=INF,maxx=-INF,miny=INF,maxy=-INF;
for (int a=0;a<n;a++)
{
minx = min(minx,rectangles[a][0]);
maxx = max(maxx,rectangles[a][2]);
miny = min(miny,rectangles[a][1]);
maxy = max(maxy,rectangles[a][3]);
}
long long s=(0ll+maxx-minx)*(0ll+maxy-miny);
for (int a=0;a<n;a++)
s -= (0ll+rectangles[a][2]-rectangles[a][0])*(0ll+rectangles[a][3]-rectangles[a][1]);
if (s) return false;
int m=0,n1=0,n2=0;
for (int a=0;a<n;a++)
{
p[++m]=point(rectangles[a][0],rectangles[a][1],1);
p[++m]=point(rectangles[a][2],rectangles[a][1],2);
p[++m]=point(rectangles[a][2],rectangles[a][3],4);
p[++m]=point(rectangles[a][0],rectangles[a][3],8);
vert[++n1]=line(rectangles[a][1],rectangles[a][0],rectangles[a][2],3);
vert[++n1]=line(rectangles[a][3],rectangles[a][0],rectangles[a][2],12);
hori[++n2]=line(rectangles[a][0],rectangles[a][1],rectangles[a][3],9);
hori[++n2]=line(rectangles[a][2],rectangles[a][1],rectangles[a][3],6);
}
sort(p+1,p+m+1);
sort(vert+1,vert+n1+1);
sort(hori+1,hori+n2+1);
int k=0;
for (int a=1;a<=m;)
{
int b=a+1,s=p[a].d,x=p[a].x,y=p[a].y;
while (b<=m && p[b].x==x && p[b].y==y)
{
if (s&p[b].d) return false;
s|=p[b].d;
b++;
} int news=0;
if (x==minx) news|=6;
if (x==maxx) news|=9;
if (y==miny) news|=12;
if (y==maxy) news|=3;
if (news&s) return false;
s|=news;
q[++k] = point(x,y,s); a=b;
}
sort(q+1,q+k+1);
for (int a=1;a<=n2;a++)
{
int x=hori[a].x,y1=hori[a].l,y2=hori[a].r,s=hori[a].d;
int l=0,r=k;
while (l+1!=r)
{
int m=(l+r)>>1;
if (q[m].x>x || (q[m].x==x && q[m].y>y1)) r=m;
else l=m;
}
while (r<=k && q[r].x==x && q[r].y<y2)
{
if (q[r].d&s) return false;
q[r].d|=s;
r++;
}
} sort(q+1,q+k+1,cmp);
for (int a=1;a<=n1;a++)
{
int y=vert[a].y,x1=vert[a].l,x2=vert[a].r,s=vert[a].d;
int l=0,r=k;
while (l+1!=r)
{
int m=(l+r)>>1;
if (q[m].y>y || (q[m].y==y && q[m].x>x1)) r=m;
else l=m;
}
while (r<=k && q[r].y==y && q[r].x<x2)
{
if (q[r].d&s) return false;
q[r].d|=s;
r++;
}
}
return true; /*int l=0,r=n1;
while (l+1!=r)
{
int m=(l+r)>>1;
if (vert[m].y >= y) r=m;
else l=m;
}
while (r<=n1 && vert[r].y==y)
{
if (x>vert[r].l && x<vert[r].r)
{
if (s&vert[r].d) return false;
s|=vert[r].d;
}
r++;
}
l=0,r=n2;
while (l+1!=r)
{
int m=(l+r)>>1;
if (hori[m].x >= x) r=m;
else l=m;
}
while (r<=n1 && hori[r].x==x)
{
if (y>hori[r].l && y<hori[r].r)
{
if (s&hori[r].d) return false;
s|=hori[r].d;
}
r++;
}
if (s!=15) return false;*/
return true;
} int main()
{
int t;
scanf("%d",&t);
for (;t--;)
{
scanf("%d",&n);
for (int a=0;a<n;a++)
for (int b=0;b<4;b++)
scanf("%d",&rectangles[a][b]);
if (isRectangleCover()) printf("Perfect\n");
else printf("Guguwansui\n");
} return 0;
}

2019qbxtCSP-S2 模拟题1的更多相关文章

  1. 全国信息学奥林匹克联赛 ( NOIP2014) 复赛 模拟题 Day1 长乐一中

    题目名称 正确答案  序列问题 长途旅行 英文名称 answer sequence travel 输入文件名 answer.in sequence.in travel.in 输出文件名 answer. ...

  2. URAL 2046 A - The First Day at School 模拟题

    A - The First Day at SchoolTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudg ...

  3. hdu 5641 King's Phone(暴力模拟题)

    Problem Description In a military parade, the King sees lots of new things, including an Andriod Pho ...

  4. ACdreamoj(1105)模拟题

    题意:射一次激光最多能够攻击到几个敌人(因为激光非常强大,能够在击中敌人后穿过它,而瑶瑶自己的坦克因为有特殊装置,所以不会被激光击中.激光也会直接穿过它) . 表示此处为空地 * 表示此处为障碍(激光 ...

  5. poj 1008:Maya Calendar(模拟题,玛雅日历转换)

    Maya Calendar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 64795   Accepted: 19978 D ...

  6. poj 1888 Crossword Answers 模拟题

    Crossword Answers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 869   Accepted: 405 D ...

  7. CodeForces - 427B (模拟题)

    Prison Transfer Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Sub ...

  8. sdut 2162:The Android University ACM Team Selection Contest(第二届山东省省赛原题,模拟题)

    The Android University ACM Team Selection Contest Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里 ...

  9. UVALive 4222 Dance 模拟题

    Dance 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&pag ...

  10. cdoj 25 点球大战(penalty) 模拟题

    点球大战(penalty) Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/2 ...

随机推荐

  1. POJ 1061 青蛙的约会 题解

    青蛙的约会 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 139755   Accepted: 31803 Descript ...

  2. python 属性描述符

    import numbers class IntField: # 一个类只要实现了这个魔法函数,那么它就是属性描述符 #数据描述符 def __get__(self, instance, owner) ...

  3. Web应急:门罗币恶意挖矿

    门罗币(Monero 或 XMR),它是一个非常注重于隐私.匿名性和不可跟踪的加密数字货币.只需在网页中配置好js脚本,打开网页就可以挖矿,是一种非常简单的挖矿方式,而通过这种恶意挖矿获取数字货币是黑 ...

  4. uni-app如何解决在for循环里调用异步请求获取数据顺序混乱问题?

    总结/朱季谦 先前有一次做uni-app的js接口对接时,遇到过这样的情况,在for循环里,调用一个异步请求时,返回来的值顺序是乱的,因此,在以下的代码里,push到数组里的值,每次的顺序可能都是不一 ...

  5. 2019-11-29-WPF-如何在绑定失败异常

    原文:2019-11-29-WPF-如何在绑定失败异常 title author date CreateTime categories WPF 如何在绑定失败异常 lindexi 2019-11-29 ...

  6. Windows下Redis集群安装与部署

    1.下载 Redis-x64-3.2.100.zip 安装程序 官网下载地址:http://redis.io/download GitHub下载地址:https://github.com/micros ...

  7. mvc5中webapi的路由

    1.Global.asax中路由的注册 public class WebApiApplication : System.Web.HttpApplication { protected void App ...

  8. redis的主从复制,哨兵值守

    环境: 主服务器:192.168.10.10    Centos 7  redis-5.0.4 从服务器:192.168.10.129  Centos 7  redis-5.0.4 从服务器:192. ...

  9. 设计模式之(十二)享元模式(Flyweight)

    享元模式思想 就以小时候导锅来说吧(导锅是我家乡的方言,就是用细沙把一个模型锅的形状拓下来,然后把铝水倒进模型中,就导好一个锅了.小时候很喜欢看的,可惜现在看不到了.上个图片回忆下)了解了这个过程后就 ...

  10. iOS7的十个更“佳”:简洁直观更受青睐

    转自:http://www.25pp.com/news/news_27792.html iOS7自发布以来一直是褒贬不一,虽然苹果还只是发布了第二个测试版,但普通用户早已经在纠结到底该不该升级iOS7 ...