当前位置:网站首页>The first game of 2021 ICPC online game
The first game of 2021 ICPC online game
2022-06-25 08:05:00 【Mfy's little brother 1】
A Busiest Computing Nodes
The question :
Yes k Time slice number is 0 To k-1, Yes n A mission , For each task i( from 0 Numbered starting ), From i%k After the first time slice starts, find the first free time slice to run , To k-1 The next one is 0.
Line segment tree + Two points
Two points to find the position closest to the left
#include<bits/stdc++.h>
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
const int INF=0x3f3f3f3f;
int k,n,h,m=1,mn[maxn<<2],prf[maxn],he[maxn];
void update(int rt,int l,int r,int x,int val){
if(l==r){
mn[rt]=val;
return;
}
int mid=(l+r)>>1;
if(x<=mid)update(lson,x,val);
else update(rson,x,val);
mn[rt]=min(mn[rt<<1],mn[rt<<1|1]);
}
int query(int rt,int l,int r,int x,int y){
if(x<=l&&r<=y)return mn[rt];
int mid=(l+r)>>1,ans=INF;
if(x<=mid)ans=min(ans,query(lson,x,y));
if(y>mid)ans=min(ans,query(rson,x,y));
return ans;
}
int main(){
scanf("%d%d",&k,&n);
for(int i=0,x,y;i<n;i++){
scanf("%d%d",&x,&y);
if(i<k){
update(1,0,k-1,i,x+y);he[i]++;
continue;
}
if(mn[1]>x)continue;
int d=i%k,l,r,ans;
int you=query(1,0,k-1,d,k-1);
if(you<=x)
l=d,r=k-1;
else
l=0,r=d-1;
while(l<=r){
int mid=(l+r)>>1;
if(query(1,0,k-1,l,mid)<=x)ans=mid,r=mid-1;
else l=mid+1;
}
update(1,0,k-1,ans,x+y),he[ans]++,m=max(m,he[ans]);
}
for(int i=0;i<k;i++)
if(he[i]==m)prf[++h]=i;
for(int i=1;i<=h;i++){
if(i!=1)printf(" ");
printf("%d",prf[i]);
}
}
D. Edge of Taixuan
The question :
One 1 To n Numbered drawing , For each [L,R] Any two points in the have a weight of w i w_i wi The edge of , Now give m Yes [ L i , R i ] [L_i,R_i] [Li,Ri], After deleting some edges , The remaining edges form the minimum spanning tree .
Ideas :
Line segment tree + thinking
hold m individual [ L i , R i ] [L_i,R_i] [Li,Ri] according to w i w_i wi Descending order , The back side turns the front side ( Section ) Cover
#include<bits/stdc++.h>
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
using ll=long long;
using namespace std;
const int maxn=1e5+5;
const int INF=0x3f3f3f3f;
int t,n,m,c,mn[maxn<<2],lazy[maxn<<2];
struct node{
int l,r,w;
}e[maxn];
bool cmp(node a,node b){
return a.w>b.w;
}
void pushdown(int rt){
if(lazy[rt]){
mn[rt<<1]=mn[rt];
mn[rt<<1|1]=mn[rt];
lazy[rt<<1]=lazy[rt];
lazy[rt<<1|1]=lazy[rt];
lazy[rt]=0;
}
}
void update(int rt,int l,int r,int x,int y,int val){
if(x<=l&&r<=y){
mn[rt]=val;
lazy[rt]=val;
return;
}
int mid=(l+r)>>1;
pushdown(rt);
if(x<=mid)update(lson,x,y,val);
if(y>mid)update(rson,x,y,val);
}
int query(int rt,int l,int r,int x){
if(l==r)return mn[rt];
int mid=(l+r)>>1;
pushdown(rt);
if(x<=mid)return query(lson,x);
else return query(rson,x);
}
int main(){
scanf("%d",&t);
while(t--){
ll he=0,sum=0,f=0;
scanf("%d%d",&n,&m);
memset(mn,INF,sizeof(mn));
memset(lazy,0,sizeof(lazy));
for(int i=1;i<=m;i++){
scanf("%d%d%d",&e[i].l,&e[i].r,&e[i].w);
he+=1ll*e[i].w*(e[i].r-e[i].l+1)*(e[i].r-e[i].l)/2;
}
sort(e+1,e+1+m,cmp);
for(int i=1;i<=m;i++)
update(1,1,n-1,e[i].l,e[i].r-1,e[i].w);
for(int i=1;i<n;i++){
int h=query(1,1,n-1,i);
if(h==INF)f=1;
sum+=h;
}
printf("Case #%d: ",++c);
if(f)printf("Gotta prepare a lesson");
else printf("%lld",he-sum);
if(t)printf("\n");
}
}
H. Mesh Analysis
Handwriting discretization
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e6+5;
struct node{
int id,code,x,y,z;
}e[maxn];
int n,m,t,k,p[maxn],a[maxn],b[maxn];
vector<int>gap[maxn];
map<int,int>mp1,mp2;
set<int>s1,s2;
int main(){
scanf("%d%d",&n,&m);
for(int i=1,s;i<=n;i++){
double x,y,z;
scanf("%d%lf%lf%lf",&s,&x,&y,&z);
}
for(int i=1,id,code,x,y,z;i<=m;i++){
scanf("%d%d%d%d",&id,&code,&x,&y);
e[i]={
id,code,x,y,0};
a[++k]=id,a[++k]=x,a[++k]=y;
if(code==203){
scanf("%d",&z);
e[i].z=z;
a[++k]=z;
}
}
scanf("%d",&t);
for(int i=1;i<=t;i++){
scanf("%d",&p[i]);
a[++k]=p[i];
}
for(int i=1;i<=k;i++)b[i]=a[i];
sort(b+1,b+1+k);
int d=1;
for(int i=2;i<=k;i++){
if(b[i]!=b[i-1])b[++d]=b[i];
}
for(int i=1;i<=k;i++){
int s=lower_bound(b+1,b+1+d,a[i])-b;
mp1[a[i]]=s;
mp2[s]=a[i];
}
for(int i=1;i<=m;i++){
int a=mp1[e[i].x],b=mp1[e[i].y],c=mp1[e[i].z];
gap[a].push_back(b);
gap[b].push_back(a);
if(e[i].code==203){
gap[a].push_back(c);
gap[b].push_back(c);
gap[c].push_back(a);
gap[c].push_back(b);
}
}
for(int i=1;i<=t;i++){
s1.clear(),s2.clear();
int q=p[i],dui=mp1[q];
printf("%d\n",q);
if(dui==0){
printf("[][]");
}
else{
for(int i=0;i<gap[dui].size();i++){
s1.insert(mp2[gap[dui][i]]);
}
int f=0;
printf("[");
for(auto x:s1){
if(f)printf(",");
printf("%d",x);
f=1;
}
printf("]\n");
for(int j=1;j<=m;j++){
if(e[j].x==p[i]||e[j].y==p[i]||e[j].z==p[i])s2.insert(e[j].id);
}
f=0;
printf("[");
for(auto x:s2){
if(f)printf(",");
printf("%d",x);
f=1;
}
printf("]");
}
if(i!=t)printf("\n");
}
}
map+set
map<int,set<int>>mp;
mp[123].insert()
for(auto &x:mp[123]){
}
边栏推荐
- Cifar-10 dataset application: quick start data enhancement method mixup significantly improves image recognition accuracy
- Opencv daily function structure analysis and shape descriptor (8) Fitline function fitting line
- 2265. number of nodes with statistical value equal to the average value of subtree
- Vscode is good, but I won't use it again
- 三台西门子消防主机FC18配套CAN光端机进行光纤冗余环网组网测试
- 【补题】2021牛客暑期多校训练营4-n
- 【莫比乌斯反演】
- Force buckle 272 Closest binary search tree value II recursion
- 27. remove elements
- 【补题】2021牛客暑期多校训练营9-n
猜你喜欢

Electronics: Lesson 012 - Experiment 13: barbecue LED

Vscode is good, but I won't use it again

三台西门子消防主机FC18配套CAN光端机进行光纤冗余环网组网测试

产品经理专业知识50篇(四)-从问题到能力提升:AMDGF模型工具

初体验完全托管型图数据库 Amazon Neptune

Introduction to the main functions of the can & canfd comprehensive test and analysis software lkmaster of the new usbcan card can analyzer

Electronics: Lesson 010 - Experiment 8: relay oscillator

Ubuntu18下登录mysql 5.7设置root密码

Matlab code format one click beautification artifact

Allgero reports an error: program has encoded a problem and must exit The design will be saved as a . SAV file
随机推荐
50. pow (x, n) - fast power
Startup, shutdown and restart of Oracle and MySQL on Linux
Matlab代码格式一键美化神器
Can transparent cloud gateway caniot and candtu record can messages and send and receive can data remotely
Electronics: Lesson 012 - Experiment 11: light and sound
Is it safe to open an account through the haircut account opening link now?
Linux上oracle和mysql的启动,关闭,重启
Niuke: flight route (layered map + shortest path)
Analysis and utilization of Microsoft Office Word remote command execution vulnerability (cve-2022-30190)
Application of can optical transceiver of ring network redundant can/ optical fiber converter in fire alarm system
TCP 加速小记
协议和服务的区别?
Looking for b-end product manager after years? I almost ruined myself
TCP的那点玩意儿
[Video] ffplay uses MJPEG format to play USB camera
【补题】2021牛客暑期多校训练营1-3
MySQL interview - the response of executing SQL is relatively slow, and the troubleshooting ideas.
【补题】2021牛客暑期多校训练营4-n
Use the frame statistics function of the message and waveform recording analyzer royalscope to troubleshoot the accidental faults of the CAN bus
CAN总线工作状况和信号质量“体检”