AcWing
  • 首页
  • 课程
  • 题库
  • 更多
    • 竞赛
    • 题解
    • 分享
    • 问答
    • 应用
    • 校园
  • 关闭
    历史记录
    清除记录
    猜你想搜
    AcWing热点
  • App
  • 登录/注册

【题解】 Educational Codeforces Round 79 (Rated for Div. 2) C. Stack of Presents

作者: 作者的头像   Alier ,  2019-12-28 17:18:09 ,  所有人可见 ,  阅读 834


2


原题链接这里

C比B从各种意义上要简单一点,直接模拟就行……感觉我和圣诞老人都挺惨的hh

(我得改掉那种,没有足够的样例就发现不了自己漏洞的坏毛病,或者学会自己编corner case)

#include<iostream>
using namespace std;
const int N=100010;
int a[N],b;
int n,m,t;
long long sum;
int bottom,temp;

int main(){
    cin >> t;
    while(t--){
        cin >> n >> m; 
        sum = 0, bottom = -1; 
        for(int i = 1; i <= n; i++){
            cin >> temp; 
            a[temp] = i;
        }
        for(int i = 1; i <= m; i++){
            cin >> b; 
            if(a[b] > bottom){//当这个礼物比bottom还要下面,说明又要掏一遍底
                bottom = a[b];
                sum += (bottom-i)* 2;
                //除了i个已经送出去的(当前i当作已送出去),其他bottom之前的都要掏出来放回去
            }
        } 
        cout << sum + m << endl; //白掏的次数+送礼物的次数就是答案
    }
    return 0;
}

0 评论

App 内打开
你确定删除吗?
1024
x

© 2018-2025 AcWing 版权所有  |  京ICP备2021015969号-2
用户协议  |  隐私政策  |  常见问题  |  联系我们
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标 qq图标
请输入绑定的邮箱地址
请输入注册信息