2021“MINIEYE杯”中国大学生算法设计超级联赛(2) I love max and multiply HDU-6971 SOSDP

I love max and multiply
在这里插入图片描述

solution

/*SiberianSquirrel*//*CuteKiloFish*/
#include <bits/stdc++.h>
using namespace std;
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (1ll * a * b / gcd(a, b))
#define Polynomial vector<int>
#define Inv(x) quick_pow(x, mod - 2)
#define DEBUG(x, y) cout << x << ": " << y << '\n';
#define mem(a, x) memset(a, x, sizeof a)
using ld = long double;
using ll = long long;
using ull = unsigned long long;
using i16 = short;
//using ill = __int128;
using ill = __int64;
const ld pi = acos(-1.0);
const ll mod = 998244353, mod_g = 3, img = 86583718;
//const ll mod = 100003;
inline int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); }
    while(ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
    return x * f;
}
inline ill print(ill x) {
    if(x < 0) { putchar('-'); x =- x; }
    if(x > 9) print(x / 10);
    putchar(x % 10 + '0');
}
ll quick_pow(ll ans, ll p, ll res = 1) {
    for(; p; p >>= 1, ans = ans * ans % mod) if(p & 1) res = res * ans % mod;
    return res % mod;
}

const int bit = 19;
const int mx = 1 << bit | 1;
ll A[mx], F[mx], B[mx];
ll maxx[2][mx], minn[2][mx];

void solve() {
    int o; cin >> o; while(o--) {
        int n; cin >> n;
        for (int i = 0; i < n; ++ i) {
            cin >> A[i];
            maxx[0][i] = minn[0][i] = A[i];
        }
        for (int i = 0; i < n; ++ i) {
            cin >> B[i];
            maxx[1][i] = minn[1][i] = B[i];
        }

        for(int j = mx; j >= 0; -- j) {
            for(int i = 0; i < bit; ++ i) {
                if((j | (1 << i)) >= n) continue;
                maxx[0][j] = max(maxx[0][j], maxx[0][j | (1 << i)]);
                maxx[1][j] = max(maxx[1][j], maxx[1][j | (1 << i)]);
                minn[0][j] = min(minn[0][j], minn[0][j | (1 << i)]);
                minn[1][j] = min(minn[1][j], minn[1][j | (1 << i)]);
            }
        }
        ll maxxx = -2e18, res = 0;
        for(int i = n - 1; i >= 0; -- i) {
            maxxx = max(maxxx, maxx[0][i] * maxx[1][i]);
            maxxx = max(maxxx, maxx[0][i] * minn[1][i]);
            maxxx = max(maxxx, minn[0][i] * maxx[1][i]);
            maxxx = max(maxxx, minn[0][i] * minn[1][i]);
            res = (res + maxxx) % mod;
            while(res < 0) res += mod;
        }
        cout << res << '\n';
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifdef ACM_LOCAL
    freopen("input", "r", stdin);
//    freopen("output", "w", stdout);
    signed test_index_for_debug = 1;
    char acm_local_for_debug = 0;
    do {
        if (acm_local_for_debug == '$') exit(0);
        if (test_index_for_debug > 20)
            throw runtime_error("Check the stdin!!!");
        auto start_clock_for_debug = clock();
        solve();
        auto end_clock_for_debug = clock();
        cout << "Test " << test_index_for_debug << " successful" << endl;
        cerr << "Test " << test_index_for_debug++ << " Run Time: "
             << double(end_clock_for_debug - start_clock_for_debug) / CLOCKS_PER_SEC << "s" << endl;
        cout << "--------------------------------------------------" << endl;
    } while (cin >> acm_local_for_debug && cin.putback(acm_local_for_debug));
#else
    solve();
#endif
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值