AtCoder Beginner Contest 196 E - Filters

原题链接

进行N次迭代的f操作前,把x看成f(x) = x,对应图像是一条完全的斜线
t = 1的操作:斜线上下平移
t = 2的操作:斜线左端点沿着斜线向右上方平移,mind向上平移
t = 3的操作:斜线右端点沿着斜线向左下方平移,maxd向下平移
期间记录偏移量

AC代码

#include <iostream>

using namespace std;

const int N = 200010;

typedef long long LL;

int n, m;
LL a, t, x;
LL maxd = 1e15, mind = -1e15, base = 0;

int main() {
    cin >> n;
    for (int i = 1; i <= n; i ++) {
        cin >> a >> t;
        if (t == 1) {
            mind += a;
            maxd += a;
            base += a;
        }
        else if (t == 2) {  //函数图像上<a的地方都变成a:若mind < a,斜线左端点沿着斜线朝右上角移动,mind想上平移
            mind = max(mind, a);
            maxd = max(maxd, a);
        }
        else {      //函数图像上>a的地方都变成a:若maxd > a,斜线又端点沿斜线着朝右上角移动,maxd想下平移
            mind = min(mind, a);
            maxd = min(maxd, a);
        }
    }
    cin >> m;
    for (int i = 1; i <= m; i ++) {
        cin >> x;
        x += base;  //x先加上偏移量,相当于进行了所有t = 1的操作
        if (x >= maxd)  cout << maxd << endl;
        else if (x <= mind) cout << mind << endl;
        else cout << x << endl;
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值