E. Two Teams

E. Two Teams

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

There are nn students standing in a row. Two coaches are forming two teams — the first coach chooses the first team and the second coach chooses the second team.

The ii-th student has integer programming skill aiai. All programming skills are distinct and between 11 and nn, inclusive.

Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and kk closest students to the left of him and kk closest students to the right of him (if there are less than kk students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team).

Your problem is to determine which students will be taken into the first team and which students will be taken into the second team.

Input

The first line of the input contains two integers nn and kk (1≤k≤n≤2⋅1051≤k≤n≤2⋅105) — the number of students and the value determining the range of chosen students during each move, respectively.

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤n1≤ai≤n), where aiai is the programming skill of the ii-th student. It is guaranteed that all programming skills are distinct.

Output

Print a string of nn characters; ii-th character should be 1 if ii-th student joins the first team, or 2 otherwise.

Examples

input

Copy

5 2
2 4 5 3 1

output

Copy

11111

input

Copy

5 1
2 1 3 5 4

output

Copy

22111

input

Copy

7 1
7 2 1 3 5 4 6

output

Copy

1121122

input

Copy

5 1
2 4 5 3 1

output

Copy

21112

Note

In the first example the first coach chooses the student on a position 33, and the row becomes empty (all students join the first team).

In the second example the first coach chooses the student on position 44, and the row becomes [2,1][2,1] (students with programming skills [3,4,5][3,4,5] join the first team). Then the second coach chooses the student on position 11, and the row becomes empty (and students with programming skills [1,2][1,2] join the second team).

In the third example the first coach chooses the student on position 11, and the row becomes [1,3,5,4,6][1,3,5,4,6] (students with programming skills [2,7][2,7] join the first team). Then the second coach chooses the student on position 55, and the row becomes [1,3,5][1,3,5] (students with programming skills [4,6][4,6] join the second team). Then the first coach chooses the student on position 33, and the row becomes [1][1] (students with programming skills [3,5][3,5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 11 joins the second team).

In the fourth example the first coach chooses the student on position 33, and the row becomes [2,1][2,1] (students with programming skills [3,4,5][3,4,5] join the first team). Then the second coach chooses the student on position 11, and the row becomes empty (and students with programming skills [1,2][1,2] join the second team).

 

题意:

有n名学生站成一排。两位教练组成了两支球队 - 第一支教练选择了第一支球队,第二支教练选择了第二支球队。

第i名学生具有整数编程技能ai。所有编程技能都是不同的,介于1和n之间。

首先,第一位教练将选择所有没有进入任何团队的学生中具有最高编程技能的学生,以及在他左边的k个最近的学生和在他右边的k个最近的学生(如果有少于k个学生到向左或向右,将选择所有这些。所有被选中的学生都会离开队伍并加入第一队。其次,第二个教练将采取同样的行动(但他选择的所有学生都加入了第二个团队)。然后第一位教练将再次进行这样的行动,依此类推。这将重复直到该行变空(即,当每个学生成为某个团队时,该过程结束)。

你的问题是确定哪些学生将被带入第一队,哪些学生将被带入第二队。

方法:区间删除

#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
typedef long long LL;
const LL mod=1e9+7;
int num[200010],ans[200010];
int pos[200010];//标记位置
int L[200010],R[200010];//用于区间删除
int vis[200010];//标记
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&num[i]);
        vis[i]=0;
        ans[i]=num[i];//复制
        pos[num[i]]=i;//id
        L[i]=i-1;//连接
        R[i]=i+1;
    }
    sort(ans+1,ans+1+n);
    int in=1;
    for(int i=n;i>=1;i--)
    {
        int item=pos[ans[i]];
        if(vis[item]) continue;//标记
            vis[item]=in;
        int t=k;
        int l=L[item];
        while(t--&&l>=1){
            vis[l]=in;
            l--;
        }
        int r=R[item];
        t=k;
        while(t--&&r<=n){
            vis[r]=in;
            r=R[r];
        }
        L[r]=l;
        R[l]=r;//缩减去除中间区间
        if(in==1) in=2;
        else in=1;
    }

    for(int i=1;i<=n;i++)
        printf("%d",vis[i]);
    return 0;
}

 

 

# 步骤2: 定义团队列表和计算函数 teams = ["武汉", "成都", "武汉泰盈", "武汉迪科", "成都金慧", "成都勤为", "成都泰盈"] # 辅助函数:筛选数据行数 def filter_count(df, team, type_condition=None, call_duration_gt=None, hit_model_included=False): """计算符合条件的数据行数""" condition = df['组织'].str.contains(team) if type_condition is not None: condition &= df['类型'].isin([type_condition] if isinstance(type_condition, int) else type_condition) if call_duration_gt is not None: # 转换通话时长列为秒(假设列名为"通话时长",格式"00:00:00") df['通话时长_秒'] = pd.to_timedelta(df['通话时长']).dt.total_seconds() condition &= df['通话时长_秒'] > call_duration_gt if hit_model_included: condition &= df['命中模型'].str.contains("百宝箱还款金-产介250901", na=False) return df[condition].shape[0] # 计算每个团队的数据 results = {} for team in teams: # 非成功单数据(用于基础计算) non_success_total = filter_count(df_source, team, type_condition=0) non_success_hit = filter_count(df_source, team, type_condition=0, hit_model_included=True) non_success_hit_rate = non_success_hit / non_success_total if non_success_total > 0 else 0 # 2分钟数据(通话时长>120秒) two_min_total = filter_count(df_source, team, type_condition=0, call_duration_gt=120) two_min_hit = filter_count(df_source, team, type_condition=0, call_duration_gt=120, hit_model_included=True) two_min_hit_rate = two_min_hit / two_min_total if two_min_total > 0 else 0 # 3分钟数据(通话时长>180秒) three_min_total = filter_count(df_source, team, type_condition=0, call_duration_gt=180) three_min_hit = filter_count(df_source, team, type_condition=0, call_duration_gt=180, hit_model_included=True) three_min_hit_rate = three_min_hit / three_min_total if three_min_total > 0 else 0 # 成功单数据 success_total = filter_count(df_source, team, type_condition=[1, 5]) # 类型=1或5 success_hit = filter_count(df_source, team, type_condition=[1, 5], hit_model_included=True) success_hit_rate = success_hit / success_total if success_total > 0 else 0 # 人均数据 # 人数:唯一座席姓名计数(假设列名为"座席姓名") agent_count = df_source[df_source['组织'].str.contains(team)]['座席姓名'].nunique() # 人均通话量 = 人数 / 非成功单总量 per_capita_call = non_success_total / agent_count if non_success_total > 0 else 0 # 存储结果 results[team] = { 'non_success_total': non_success_total, 'non_success_hit': non_success_hit, 'non_success_hit_rate': non_success_hit_rate, 'two_min_total': two_min_total, 'two_min_hit': two_min_hit, 'two_min_hit_rate': two_min_hit_rate, 'three_min_total': three_min_total, 'three_min_hit': three_min_hit, 'three_min_hit_rate': three_min_hit_rate, 'success_total': success_total, 'success_hit': success_hit, 'success_hit_rate': success_hit_rate, 'agent_count': agent_count, 'per_capita_call': per_capita_call, } # 步骤3: 创建新Excel和工作表 wb = openpyxl.Workbook() ws = wb.active ws.title = "还款金命中结果" # 步骤4: 构建表结构 ws.merge_cells('A1:B1') ws['A1'] = datetime.now().strftime('%Y%m%d') ws['A1'].alignment = Alignment(horizontal='center', vertical='center') ws.merge_cells('C1:E1') ws['C1'] = "非成功单通话时长>2分钟" ws['C1'].alignment = Alignment(horizontal='center', vertical='center') ws.merge_cells('F1:H1') ws['F1'] = "非成功单通话时长>3分钟" ws['F1'].alignment = Alignment(horizontal='center', vertical='center') ws.merge_cells('I1:K1') ws['I1'] = "成功单" ws['I1'].alignment = Alignment(horizontal='center', vertical='center') ws.merge_cells('L1:M1') ws['L1'] = "人均" ws['L1'].alignment = Alignment(horizontal='center', vertical='center') ws['A2'] = "执行情况" ws['A2'].alignment = Alignment(horizontal='center', vertical='center') ws.merge_cells('A3:A4') ws['A3'] = "地区" ws['A3'].alignment = Alignment(horizontal='center', vertical='center') ws.merge_cells('A5:A9') ws['A5'] = "团队" ws['A5'].alignment = Alignment(horizontal='center', vertical='center') # 列头定义(跳过A列直接写入B列) headers = ["名称", "武汉", "成都", "武汉泰盈", "武汉迪科", "成都金慧", "成都勤为", "成都泰盈"] # B到I列 for row_idx, header in enumerate(headers, start=2): # start=2 表示从第2行开始 ws.cell(row=row_idx, column=2, value=header) # column=2 表示固定B列 # 数据行写入(从第3行开始,跳过A列) data_rows = [ # 每行数据从B列开始写入(索引1开始) ["总量"] + [results[team]['two_min_total'] for team in teams], ["命中量"] + [results[team]['two_min_hit'] for team in teams], ["命中率"] + [f"{results[team]['two_min_hit_rate']:.2%}" for team in teams], ["总量"] + [results[team]['three_min_total'] for team in teams], ["命中量"] + [results[team]['three_min_hit'] for team in teams], ["命中率"] + [f"{results[team]['three_min_hit_rate']:.2%}" for team in teams], ["总量"] + [results[team]['success_total'] for team in teams], ["命中量"] + [results[team]['success_hit'] for team in teams], ["命中率"] + [f"{results[team]['success_hit_rate']:.2%}" for team in teams], ["人数"] + [results[team]['agent_count'] for team in teams], ["人均通话量"] + [f"{results[team]['per_capita_call']:.2f}" for team in teams] ] #横向填充 #start_row = 3 #for row_idx, row_data in enumerate(data_rows, start=start_row): # for col_idx, value in enumerate(row_data, start=2): # 从B列开始 # ws.cell(row=row_idx, column=col_idx, value=value) start_row = 2 for col_idx, row_data in enumerate(data_rows, start=3): # 从C列(3)开始 for row_offset, value in enumerate(row_data): # 固定列号,行号递增 ws.cell(row=start_row + row_offset, column=col_idx, value=value) wb.save(dest_path) print(f"文件已保存至: {dest_path}")整体数据处理代码是这样,我应该怎么添加
09-29
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值