当前位置:网站首页>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]){
}
边栏推荐
- Number theory template
- socket问题记录
- To understand the difference between Gram-positive and Gram-negative bacteria and the difference in pathogenicity
- 50 pieces of professional knowledge of Product Manager (IV) - from problem to ability improvement: amdgf model tool
- Debugging mipi-dsi screen based on stm32mp157
- Linux上oracle和mysql的启动,关闭,重启
- [Mobius inversion]
- 函数尽量不要通过变量指定操作类型
- 图像超分综述:超长文一网打尽图像超分的前世今生 (附核心代码)
- 剑指offer刷题(简单等级)
猜你喜欢

Allgero reports an error: program has encoded a problem and must exit The design will be saved as a . SAV file

Ubuntu18下登录mysql 5.7设置root密码

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

环网冗余式CAN/光纤转换器的CAN光端机在消防火灾联网报警系统中的应用

挖掘微生物暗物质——新思路

Can transparent cloud gateway caniot and candtu record can messages and send and receive can data remotely

Take you through the normalization flow of GaN
![洛谷P1073 [NOIP2009 提高组] 最优贸易(分层图+最短路)](/img/cb/046fe4b47898fd6db86edc8a267c34.png)
洛谷P1073 [NOIP2009 提高组] 最优贸易(分层图+最短路)

使用Adobe Acrobat Pro调整PDF页面为统一大小

自制坡道,可是真的很香
随机推荐
Electronics: Lesson 010 - Experiment 8: relay oscillator
27. remove elements
电子学:第011课——实验 10:晶体管开关
Import data into Matlab
线程+线程问题记录
Dietary intervention reduces cancer treatment-related symptoms and toxicity
ffmpeg+SDL2实现音频播放
Luogu p5994 [pa2014]kuglarz (XOR thinking +mst)
C disk drives, folders and file operations
C WinForm panel custom picture and text
Electronics: Lesson 012 - Experiment 11: light and sound
Est - il sûr d'ouvrir un compte d'actions maintenant via le lien d'ouverture de compte coiffé?
Pychart's wonderful setting: copy immediately after canceling the comment and bring #
C # set up FTP server and realize file uploading and downloading
Luogu p2839 [national training team]middle (two points + chairman tree + interval merging)
Matlab code format one click beautification artifact
CVPR 2022 Oral 2D图像秒变逼真3D物体
50. pow (x, n) - fast power
PHP array function Encyclopedia
[Video] ffplay uses MJPEG format to play USB camera