2019-2020 ICPC Asia Hong Kong Regional Contest
题解:
https://files.cnblogs.com/files/clrs97/19HKEditorial-V1.zip
Code:(Part)
A. Axis of Symmetry
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const int N=100010,inf=1000000010;
int Case,n,cl,ce,cp,i,j,k,xmi,xma,ymi,yma,ama,ami,sma,smi;vector<vector<int> >ans;
struct Rect{int xl,xr,yl,yr;}rect[N];
struct Line{
int x1,y1,x2,y2;
Line(){}
Line(int _x1,int _y1,int _x2,int _y2){
x1=_x1,y1=_y1,x2=_x2,y2=_y2;
fix();
}
void fix(){
if(x1>x2)swap(x1,x2),swap(y1,y2);
if(x1==x2&&y1>y2)swap(y1,y2);
}
}a[N<<2],b[N<<2];
inline bool cmpl(const Line&a,const Line&b){
if(a.x1!=b.x1)return a.x1<b.x1;
if(a.y1!=b.y1)return a.y1<b.y1;
if(a.x2!=b.x2)return a.x2<b.x2;
return a.y2<b.y2;
}
struct E{int x,y,t;E(){}E(int _x,int _y,int _t){x=_x,y=_y,t=_t;}}e[N<<2];
struct P{int l,r;P(){}P(int _l,int _r){l=_l,r=_r;}}pool[N];
inline bool cmpe(const E&a,const E&b){
if(a.x!=b.x)return a.x<b.x;
return a.y<b.y;
}
inline void solve(int l,int r){
int i,j,s=0,L=-inf,R=-inf;
for(cp=0,i=l;i<=r;i=j){
if(s==1)R=e[i].y;
else{
if(L<R)pool[++cp]=P(L,R);
L=e[i].y;
}
for(j=i;j<=r&&e[i].y==e[j].y;j++)s+=e[j].t;
}
if(L<R)pool[++cp]=P(L,R);
}
inline void umin(int&a,int b){a>b?(a=b):0;}
inline void umax(int&a,int b){a<b?(a=b):0;}
inline void check(ll A,ll B,ll C){
int i,d=A*A+B*B;ll x,y,X,Y;
for(i=1;i<=cl;i++){
x=a[i].x1,y=a[i].y1;
X=2*A*(A*x+B*y-C),Y=2*B*(A*x+B*y-C);
if(X%d||Y%d)return;
b[i].x1=x-X/d,b[i].y1=y-Y/d;
x=a[i].x2,y=a[i].y2;
X=2*A*(A*x+B*y-C),Y=2*B*(A*x+B*y-C);
if(X%d||Y%d)return;
b[i].x2=x-X/d,b[i].y2=y-Y/d;
b[i].fix();
}
sort(b+1,b+cl+1,cmpl);
for(i=1;i<=cl;i++){
if(a[i].x1!=b[i].x1)return;
if(a[i].y1!=b[i].y1)return;
if(a[i].x2!=b[i].x2)return;
if(a[i].y2!=b[i].y2)return;
}
if(C%2==0)C/=2;else A*=2,B*=2;
vector<int>v;
v.push_back(A);
v.push_back(B);
v.push_back(C);
ans.push_back(v);
}
inline void up(int x,int y){
umax(xma,x);
umin(xmi,x);
umax(yma,y);
umin(ymi,y);
umax(ama,x+y);
umin(ami,x+y);
umax(sma,x-y);
umin(smi,x-y);
}
int main(){
scanf("%d",&Case);
while(Case--){
scanf("%d",&n);
cl=0;
xma=yma=ama=sma=-inf;
xmi=ymi=ami=smi=inf;
for(i=1;i<=n;i++){
scanf("%d%d%d%d",&rect[i].xl,&rect[i].yl,&rect[i].xr,&rect[i].yr);
rect[i].xl*=2;
rect[i].yl*=2;
rect[i].xr*=2;
rect[i].yr*=2;
up(rect[i].xl,rect[i].yl);
up(rect[i].xl,rect[i].yr);
up(rect[i].xr,rect[i].yl);
up(rect[i].xr,rect[i].yr);
}
ce=0;
for(i=1;i<=n;i++){
e[++ce]=E(rect[i].xl,rect[i].yl,1);
e[++ce]=E(rect[i].xl,rect[i].yr,-1);
e[++ce]=E(rect[i].xr,rect[i].yl,1);
e[++ce]=E(rect[i].xr,rect[i].yr,-1);
}
sort(e+1,e+ce+1,cmpe);
for(i=1;i<=ce;i=j){
for(j=i;j<=ce&&e[i].x==e[j].x;j++);
solve(i,j-1);
for(k=1;k<=cp;k++)a[++cl]=Line(e[i].x,pool[k].l,e[i].x,pool[k].r);
}
ce=0;
for(i=1;i<=n;i++){
e[++ce]=E(rect[i].yl,rect[i].xl,1);
e[++ce]=E(rect[i].yl,rect[i].xr,-1);
e[++ce]=E(rect[i].yr,rect[i].xl,1);
e[++ce]=E(rect[i].yr,rect[i].xr,-1);
}
sort(e+1,e+ce+1,cmpe);
for(i=1;i<=ce;i=j){
for(j=i;j<=ce&&e[i].x==e[j].x;j++);
solve(i,j-1);
for(k=1;k<=cp;k++)a[++cl]=Line(pool[k].l,e[i].x,pool[k].r,e[i].x);
}
sort(a+1,a+cl+1,cmpl);
ans.clear();
check(1,1,(ami+ama)/2);
check(1,0,(xmi+xma)/2);
check(1,-1,(smi+sma)/2);
check(0,1,(ymi+yma)/2);
printf("%d\n",(int)ans.size());
sort(ans.begin(),ans.end());
reverse(ans.begin(),ans.end());
for(i=0;i<ans.size();i++)for(j=0;j<3;j++){
if(i||j)putchar(' ');
printf("%d",ans[i][j]);
}
puts("");
}
}
B. Binary Tree
#include<cstdio>
int Case,n,i,x,y;
int main(){
scanf("%d",&Case);
while(Case--){
scanf("%d",&n);
for(i=1;i<n;i++)scanf("%d%d",&x,&y);
puts(n&1?"Alice":"Bob");
}
}
D. Defining Labels
#include<cstdio>
int Case,k,x;
void print(int x){
if(x>k)print((x-1)/k);
x%=k;
if(!x)x=k;
printf("%d",x+9-k);
}
int main(){
scanf("%d",&Case);
while(Case--){
scanf("%d%d",&k,&x);
print(x);
puts("");
}
}
G. Game Design
#include<cstdio>
const int N=100010;
int k,tot,i,f[N],c[N],g[N];
int solve(int k,int o){
int x=++tot;
f[x]=o;
if(k<=2){
int y=++tot;
f[y]=x;
c[y]=1;
g[x]=1;
c[x]=3-k;
return g[x]=1;
}
g[x]=solve(k/2,x)+solve(2,x);
c[x]=g[x]+(k%2==0);
return g[x];
}
int main(){
scanf("%d",&k);
solve(k,0);
printf("%d\n",tot);
for(i=2;i<=tot;i++)printf("%d%c",f[i],i<tot?' ':'\n');
for(i=1;i<=tot;i++)printf("%d%c",c[i],i<tot?' ':'\n');
}
H. Hold the Line
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=500010,M=1000010,K=2100005,inf=~0U>>1;
int Case,n,m,i,j,op,x,y,z,pool[M],cp,e[M][4],val[N],ap[N];
int pos[M],st[K],en[K],q[11000005],cq,cnt[M];
int g[N],nxt[M],ans[M],L,H,T,ANS,TMP;
void build(int x,int a,int b){
st[x]=cq+1;
en[x]=cq;
cq+=cnt[b]-cnt[a-1];
if(a==b){
pos[a]=x;
return;
}
int mid=(a+b)>>1;
build(x<<1,a,mid),build(x<<1|1,mid+1,b);
}
inline void ins(int x){
int y=ap[x];
if(y>m)return;
for(int o=pos[val[x]];o;o>>=1){
int S=st[o],T=en[o];
while(S<=T&&ap[q[T]]>=y)T--;
q[++T]=x;
en[o]=T;
}
}
inline bool check(int x){
int l=st[x],r=en[x],mid;
while(l<=r){
mid=(l+r)>>1;
if(q[mid]>=L&&ap[q[mid]]<=T)return 1;
if(q[mid]<L)l=mid+1;else r=mid-1;
}
return 0;
}
void askl(int x,int a,int b){
if(TMP||st[x]>en[x])return;
if(b<=H){
if(!check(x))return;
if(a==b){
TMP=a;
return;
}
}
int mid=(a+b)>>1;
if(H>mid)askl(x<<1|1,mid+1,b);
askl(x<<1,a,mid);
}
void askr(int x,int a,int b){
if(TMP||st[x]>en[x])return;
if(H<=a){
if(!check(x))return;
if(a==b){
TMP=a;
return;
}
}
int mid=(a+b)>>1;
if(H<=mid)askr(x<<1,a,mid);
askr(x<<1|1,mid+1,b);
}
inline void query(int x){
L=e[x][1];
H=e[x][3];
T=x;
ANS=inf;
TMP=0;
askl(1,1,cp);
if(TMP)ANS=pool[H]-pool[TMP];
TMP=0;
askr(1,1,cp);
if(TMP)ANS=min(ANS,pool[TMP]-pool[H]);
ans[x]=ANS<inf?ANS:-1;
}
int main(){
scanf("%d",&Case);
while(Case--){
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)ap[i]=m+1,g[i]=0;
for(i=1;i<=m;i++){
scanf("%d%d",&op,&x);
if(op==0)scanf("%d",&z);else scanf("%d%d",&y,&z);
e[i][0]=op;
e[i][1]=x;
e[i][2]=y;
e[i][3]=z;
pool[i]=z;
}
sort(pool+1,pool+m+1);
for(cp=0,i=1;i<=m;i++)if(pool[i]>pool[i-1])pool[++cp]=pool[i];
for(i=1;i<=cp;i++)cnt[i]=0;
for(i=1;i<=m;i++){
e[i][3]=lower_bound(pool+1,pool+cp+1,e[i][3])-pool;
x=e[i][1];
y=e[i][2];
z=e[i][3];
if(e[i][0]==0){
val[x]=z;
ap[x]=i;
cnt[z]++;
}else{
nxt[i]=g[y];
g[y]=i;
}
}
for(i=1;i<=cp;i++)cnt[i]+=cnt[i-1];
cq=0;
build(1,1,cp);
for(i=1;i<=n;i++){
ins(i);
for(j=g[i];j;j=nxt[j])query(j);
}
for(i=1;i<=m;i++)if(e[i][0]==1)printf("%d\n",ans[i]);
}
}
I. Incoming Asteroids
#include<cstdio>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
typedef pair<ll,P>PI;
const int N=200010,M=200010;
int n,m,tot,cnt,op,i,x,y,pool[M],cp;
int num[M],e[M][3],goal[M],ver[M];ll base[M][3];bool del[M];
priority_queue<PI,vector<PI>,greater<PI> >f[N];ll tag[N];
inline void deploy(int x){
if(del[x])return;
int deg=num[x];
ll now=0;
for(int i=0;i<deg;i++)now+=tag[e[x][i]]-base[x][i];
if(now>=goal[x]){
del[x]=1;
pool[++cp]=x;
return;
}
goal[x]-=now;
ver[x]=++cnt;
int o=(goal[x]+deg-1)/deg;
for(int i=0;i<deg;i++){
int y=e[x][i];
base[x][i]=tag[y];
f[y].push(PI(tag[y]+o,P(x,cnt)));
}
}
inline void maketag(int x,int y){
tag[x]+=y;
while(!f[x].empty()){
PI t=f[x].top();
if(t.first>tag[x])return;
f[x].pop();
if(t.second.second==ver[t.second.first])deploy(t.second.first);
}
}
int main(){
scanf("%d%d",&n,&m);
while(m--){
scanf("%d",&op);
if(op==1){
tot++;
scanf("%d%d",&goal[tot],&num[tot]);
goal[tot]^=cp;
for(i=0;i<num[tot];i++){
scanf("%d",&e[tot][i]);
e[tot][i]^=cp;
base[tot][i]=tag[e[tot][i]];
}
deploy(tot);
}else{
scanf("%d%d",&x,&y);
x^=cp,y^=cp;
cp=0;
maketag(x,y);
printf("%d",cp);
sort(pool+1,pool+cp+1);
for(i=1;i<=cp;i++)printf(" %d",pool[i]);
puts("");
}
}
}
J. Junior Mathematician
#include<cstdio>
#include<cstring>
const int N=5105,M=65,P=1000000007;
int Case,m,n,i,j,k,o,x,no,tmp,ret,f[N][M][M][2],p[N];char a[N],b[N];
inline void up(int&a,int b){a=a+b<P?a+b:a+b-P;}
inline int solve(char*a,int r){
n=strlen(a);
for(i=0;i<n;i++)a[i]-='0';
for(p[0]=i=1;i<=n;i++)p[i]=10*p[i-1]%m;
for(i=1;i<=n;i++)for(j=0;j<m;j++)for(k=0;k<m;k++)for(o=0;o<2;o++)f[i][j][k][o]=0;
f[0][0][0][1]=1;
for(i=0;i<n;i++)for(j=0;j<m;j++)for(k=0;k<m;k++)for(o=0;o<2;o++){
tmp=f[i][j][k][o];
if(!tmp)continue;
for(x=0;x<10;x++){
if(o){
if(x>a[i])break;
no=x==a[i];
}else no=0;
up(f[i+1][((j+x*(k-p[n-i-1]))%m+m)%m][(k+x)%m][no],tmp);
}
}
for(ret=j=0;j<m;j++)for(k=0;k<=r;k++)up(ret,f[n][0][j][k]);
return ret;
}
int main(){
scanf("%d",&Case);
while(Case--){
scanf("%s%s%d",a,b,&m);
printf("%d\n",(solve(b,1)-solve(a,0)+P)%P);
}
}
K. Key Project
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const int N=805,inf=1000000010;
int n,m,i,x,y,ca[N],cb[N],ata[N],atb[N],va[N],vb[N];
int d[N],fl[N],fr[N];
vector<int>a[N],b[N];
long long ans;
inline void fix(int x){
if(ata[x]>=ca[x])va[x]=inf;else va[x]=a[x][ata[x]];
if(atb[x]>=cb[x])vb[x]=inf;else vb[x]=b[x][atb[x]];
}
inline void aug(){
int i,best=inf,A,B,o,tmp;
//A->B
for(tmp=inf,i=1;i<=n;i++){
//i as A
if(va[i]<tmp){
tmp=va[i];
o=i;
}
//i as B
if(tmp+vb[i]<best){
best=tmp+vb[i];
A=o;
B=i;
}
//move right
if(tmp<inf&&i<n){
if(fr[i])tmp-=d[i];
else tmp+=d[i];
}
}
//B<-A
for(tmp=inf,i=n;i;i--){
//i as A
if(va[i]<tmp){
tmp=va[i];
o=i;
}
//i as B
if(tmp+vb[i]<best){
best=tmp+vb[i];
A=o;
B=i;
}
//move right
if(tmp<inf&&i>1){
if(fl[i-1])tmp-=d[i-1];
else tmp+=d[i-1];
}
}
ans+=best;
printf("%lld\n",ans);
ata[A]++,atb[B]++;
fix(A),fix(B);
if(A<B)for(i=A;i<B;i++){
if(fr[i])fr[i]--;
else fl[i]++;
}
if(A>B)for(i=B;i<A;i++){
if(fl[i])fl[i]--;
else fr[i]++;
}
}
//f>0 means it is -
int main(){
scanf("%d%d",&n,&m);
for(i=1;i<n;i++)scanf("%d",&d[i]);//1e6
for(i=1;i<=m;i++)scanf("%d%d",&x,&y),a[x].push_back(y);//1e8
for(i=1;i<=m;i++)scanf("%d%d",&x,&y),b[x].push_back(y);//1e8
for(i=1;i<=n;i++){
sort(a[i].begin(),a[i].end());
sort(b[i].begin(),b[i].end());
ca[i]=a[i].size();
cb[i]=b[i].size();
fix(i);
}
while(m--)aug();
}
2019-2020 ICPC Asia Hong Kong Regional Contest的更多相关文章
- 2019-2020 ICPC Asia Hong Kong Regional Contest J. Junior Mathematician 题解(数位dp)
题目链接 题目大意 要你在[l,r]中找到有多少个数满足\(x\equiv f(x)(mod\; m)\) \(f(x)=\sum_{i=1}^{k-1} \sum_{j=i+1}^{k}d(x,i) ...
- Asia Hong Kong Regional Contest 2019
A. Axis of Symmetry B. Binary Tree n 的奇偶性决定胜负. C. Constructing Ranches 路径上点权之和大于,极大值两倍,这是路径上点能拼出多边形的 ...
- Asia Hong Kong Regional Contest 2016
A. Colourful Graph 可以在$2n$步之内实现交换任意两个点的颜色,然后就可以构造出方案. #include <bits/stdc++.h> using namespace ...
- 2020.5.16-ICPC Central Europe Regional Contest 2019
A. ABB #include <bits/stdc++.h> using namespace std; #define PB push_back #define ZERO (1e-10) ...
- 2020.5.4-ICPC Pacific Northwest Regional Contest 2019
A. Radio Prize All boring tree-shaped lands are alike, while all exciting tree-shaped lands are exci ...
- 2019 ACM/ICPC Asia Regional shanxia D Miku and Generals (二分图黑白染色+01背包)
Miku is matchless in the world!” As everyone knows, Nakano Miku is interested in Japanese generals, ...
- 2020 ICPC Asia Taipei-Hsinchu Regional Problem H Optimization for UltraNet (二分,最小生成树,dsu计数)
题意:给你一张图,要你去边,使其成为一个边数为\(n-1\)的树,同时要求树的最小边权最大,如果最小边权最大的情况有多种,那么要求总边权最小.求生成树后的所有简单路径上的最小边权和. 题解:刚开始想写 ...
- 2020 ICPC Asia Taipei-Hsinchu Regional Problem B Make Numbers (dfs搜索)
题意:给你四个数字,你可以用这四个数字凑出四个1位数,一个2位数和两个1位数,或一个3位数和一个1位数,你可以用你凑出的数字进行\(+,-,x\)运算(所有运算符号至少出现一次),问你一共能得到多少个 ...
- ICPC 2019-2020 North-Western Russia Regional Contest
目录 Contest Info Solutions Problem A. Accurate Movement Problem B. Bad Treap Problem E. Equidistant P ...
随机推荐
- Python连载32-多线程其他属性以及继承Thread类
一.线程常用属性 1.threading.currentThread:返回当前线程变量 2.threading.enumerate:返回一个包含正在运行的线程的list,正在运行的线程指的是线程启动后 ...
- 卡尔曼滤波C++代码
#include <ros/ros.h> #include <string> #include <stdlib.h> #include <iostream&g ...
- 阿里云CentOS7.x安装nodejs及pm2
对之前文章的修订 您将了解 CentOS下如何安装nodejs CentOS下如何安装NVM CentOS下如何安装git CentOS下如何安装pm2 适用对象 本文档介绍如何在阿里云CentOS系 ...
- linux软链接
这是linux中一个非常重要的命令,他的功能是为某一个文件在另一个位置建立一个同步的链接,这个命令最常用的参数是-s, 具体用法是: ln -s 源文件 目标文件 当我们需要在不同的目录,用到相同的文 ...
- jQuery 源码分析(二) 入口模块
jQuery返回的对象本质上是一个JavaScript对象,而入口模块则可以保存对应的节点的引用,然后供其它模块操作 我们创建jQuery对象时可以给jQuery传递各种不同的选择器,如下: fals ...
- 一些优秀的 Entity Framework 开源项目
增加全局过滤的项目(比如:IsDeleted 字段):https://github.com/zzzprojects/EntityFramework.DynamicFilters 谢谢浏览!
- Gitlab 备份还原/迁移
Gitlab 备份还原 备份数据:通过命令进行备份操作 gitlab-rake gitlab:backup:create ... [DISABLED] Creating backup archive: ...
- JVM的监控工具之jvisual
VisualVM(All-in-One Java Trouble shootingTool)是到目前为止随JDK发布的功能最强大的运行监视和故障处理程序,并且可以预见在未来一段时间内都是官方主力发展的 ...
- LocalDB 从2017更换到2014后一直显示连接不正确解决方案
问题描述:LocalDB 版本混装后出现默认实例创建不成功 无法连接到 (LocalDB)\MSSQLLocalDB. ------------------------------其他信息: 在与 S ...
- kali渗透综合靶机(十二)--SickOs1.2靶机
kali渗透综合靶机(十二)--SickOs1.2靶机 靶机下载地址:https://www.vulnhub.com/entry/sickos-12,144/ 一.主机发现 1.netdiscover ...