QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#268467#7043. Image Processing8BQube#TL 1ms7472kbC++202.1kb2023-11-28 17:45:462023-11-28 17:45:47

Judging History

你现在查看的是最新测评结果

  • [2023-11-28 17:45:47]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:7472kb
  • [2023-11-28 17:45:46]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define SZ(a) ((int)a.size())

const int INF = 2e9 + 1;
int mx[1000005][20], mn[1000005][20];
int dp[1000005];

int range(int l, int r) {
    //cerr << "range " << l << " " << r << "\n";
    //assert(l <= r);
    int lg = __lg(r - l + 1);
    int mx_val = max(mx[r][lg], mx[l + (1 << lg) - 1][lg]);
    int mn_val = min(mn[r][lg], mn[l + (1 << lg) - 1][lg]);
    return mx_val - mn_val;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int n, k, c0 = 0;
    cin >> n >> k;
    int L = __lg(n);
    vector<int> stk;
    fill_n(mx[0], L, -1);
    fill_n(mn[0], L, INF);
    for (int i = 1; i <= n; ++i) {
        int x;
        cin >> x, x ^= c0;
        mx[i][0] = mn[i][0] = x;
        for (int j = 1; j <= L && i >= (1 << j); ++j) {
            mx[i][j] = max(mx[i][j - 1], mx[i - (1 << (j - 1))][j - 1]);
            mn[i][j] = min(mn[i][j - 1], mn[i - (1 << (j - 1))][j - 1]);
            //cerr << "mx " << i << " " << j << " = " << mx[i][j] << "\n";
            //cerr << "mn " << i << " " << j << " = " << mn[i][j] << "\n";
        }

        auto check = [&](int mid) {
            int lft = i;
            for (int j = L; j >= 0; --j)
                if (lft >= (1 << j) && range(lft - (1 << j) + 1, i) <= mid)
                    lft -= 1 << j;
            //cerr << i << " " << "check " << mid << " -> " << lft << "\n";
            auto lb = lower_bound(ALL(stk), lft);
            return lb != stk.end() && dp[*lb] <= mid;
        };

        if (i >= k) {
            if (i - k >= k || i == k) {
                while (!stk.empty() && dp[stk.back()] >= dp[i - k])
                    stk.pop_back();
                stk.pb(i - k);
            }
            int l = 0, r = INF;
            while (r - l > 1) {
                int mid = l + ((r - l) >> 1);
                if (check(mid)) r = mid;
                else l = mid;
            }
            dp[i] = r;
        }
        cout << (c0 = dp[i]) << "\n";
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 7472kb

input:

5 2
50 110 190 120 34

output:

0
60
80
90
80

result:

ok 5 number(s): "0 60 80 90 80"

Test #2:

score: -100
Time Limit Exceeded

input:

1000000 7
740760744 128949015 864430306 803157027 867410355 348411907 788815333 62537628 989888355 897434632 893725957 385915358 116671606 91645858 585889989 81062060 177182250 543069056 107482294 981936827 433021299 764779421 730485811 37353026 476269126 318260875 564753383 841579792 652031776 3016...

output:

0
0
0
0
0
0
738461340
738461340
738461340
738461340
738461340
861209643
861209643
738461340
739549417
739549417
739549417
783969241
783969241
783969241
738461340
904097193
904097193
910753514
910753514
910753514
910753514
910753514
904097193
904097193
904097193
904097193
904097193
904097193
90409719...

result: