QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#820794#8923. За связь без перебоевtopfloorboss0 216ms37408kbC++202.1kb2024-12-19 02:19:092024-12-19 02:19:11

Judging History

This is the latest submission verdict.

  • [2024-12-19 02:19:11]
  • Judged
  • Verdict: 0
  • Time: 216ms
  • Memory: 37408kb
  • [2024-12-19 02:19:09]
  • Submitted

answer

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <random>
#include <cassert>

using namespace std;

#define int long long
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

typedef long long ll;
typedef long double ld;


void solve() {
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    vector<int> r(n);
    r[n - 1] = n - 1 + a[n - 1];
    set<pair<int, int>> cur;
    cur.insert({-(n - 1 + a[n - 1]), n - 1 - a[n - 1]});
    for (int i = n - 2; i >= 0; --i) {
        cur.insert({-(i + a[i]), i - a[i]});
        while ((*cur.begin()).second > i) cur.erase(cur.begin());
        r[i] = -(*cur.begin()).first;
    }
    for (auto &e : r) e = min(e, n - 1);
    int ans = 0;
    vector<int> dp(n + 1);
    for (int i = n - 1; i >= 0; --i) {
        dp[i] = dp[r[i] + 1] + n - 1 - r[i];
    }
    for (auto e : dp) ans += e;
    vector<int> pdp(n + 2);
    for (int i = 0; i <= n; ++i) pdp[i + 1] = pdp[i] + dp[i];
    int tans = ans;
    for (int i = n - 1; i >= 0; --i) {
        int tr = min(n - 1, i + x);
        int tl = max((int)0, i - x);
        if (r[tl] >= tr) continue;
        int L = tl, R = tr + 1;
        while (R - L > 1) {
            int M = (L + R) / 2;
            if (r[M] < tr) L = M;
            else R = M;
        }
        int tans2 = tans - (pdp[R] - pdp[tl]) + dp[tr] * (R - tr) + (R - tr) * (n - 1 - tr);
        // cout << i << ' ' << tans2 << '\n';
        ans = min(ans, tans2);
    }
    cout << ans << '\n';
}

signed main() {
    int tc = 1;
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
#endif
    // cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 7
Accepted
time: 0ms
memory: 3564kb

input:

1 0
0

output:

0

result:

ok answer is '0'

Test #2:

score: 7
Accepted
time: 0ms
memory: 3608kb

input:

1 1
0

output:

0

result:

ok answer is '0'

Test #3:

score: 0
Wrong Answer
time: 0ms
memory: 3552kb

input:

100 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

output:

156849

result:

wrong answer expected '161651', found '156849'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Wrong Answer

Test #39:

score: 12
Accepted
time: 54ms
memory: 34236kb

input:

1000000 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

166666666666500000

result:

ok answer is '166666666666500000'

Test #40:

score: 12
Accepted
time: 71ms
memory: 34300kb

input:

1000000 0
1 0 0 0 0 0 0 0 1 1 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 0 0 0 0 1 0 1 1 1 1 0 1 1 0 1 1 1 0 0 1 0 1 1 0 1 0 0 0 0 1 0 1 0 1 1 0 1 0 1 0 0 0 1 1 0 0 1 1 0 0 1 0 0 1 0 1 1 0 1 1 1 0 0 1 1 1 1 1 0 0 1 0 0 1 0 1 0 1 0 0 1 0 0 0 1 1 0 1 1 1 0 1 1 0 0 1 1 1 0 0 1 0 0 1 0 0 1 1 0 1 0 0 0 1 0 0 0 1 1 0 ...

output:

76913617667970500

result:

ok answer is '76913617667970500'

Test #41:

score: 0
Wrong Answer
time: 78ms
memory: 34212kb

input:

1000000 0
3 1 4 0 0 1 0 3 0 0 1 3 3 3 2 1 3 1 3 4 4 3 2 3 4 3 1 1 2 1 3 2 4 0 4 2 4 0 2 4 2 1 2 4 0 0 1 3 4 2 3 0 4 4 3 0 0 0 2 3 1 3 0 4 1 3 0 0 1 2 4 1 2 3 1 1 1 3 0 2 3 3 4 1 3 3 2 0 4 2 1 3 2 3 4 3 4 0 2 4 3 4 1 2 4 0 1 1 3 4 1 1 2 3 3 4 4 1 4 4 1 4 0 2 4 2 0 4 4 3 0 2 2 3 2 1 3 1 4 3 4 4 2 3 0 ...

output:

24646869912205632

result:

wrong answer expected '24531987461587312', found '24646869912205632'

Subtask #5:

score: 0
Wrong Answer

Test #53:

score: 5
Accepted
time: 59ms
memory: 34312kb

input:

1000000 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

166666666666500000

result:

ok answer is '166666666666500000'

Test #54:

score: 0
Wrong Answer
time: 64ms
memory: 34228kb

input:

1000000 10
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

166656666866498670

result:

wrong answer expected '166661666666500670', found '166656666866498670'

Subtask #6:

score: 0
Skipped

Dependency #5:

0%

Subtask #7:

score: 0
Wrong Answer

Test #74:

score: 14
Accepted
time: 162ms
memory: 37388kb

input:

1000000 0
50003 50006 50006 50003 50005 50010 50006 50007 50002 50000 50005 50003 50002 50005 50000 50008 50010 50008 50007 50000 50003 50001 50008 50005 50002 50005 50006 50001 50002 50009 50006 50007 50010 50008 50000 50005 50006 50006 50003 50001 50000 50008 50000 50003 50008 50009 50006 50000 50...

output:

1424723569101

result:

ok answer is '1424723569101'

Test #75:

score: 0
Wrong Answer
time: 216ms
memory: 37408kb

input:

1000000 100000
50006 50002 50007 50009 50002 50006 50008 50009 50001 50010 50005 50001 50000 50010 50009 50007 50010 50001 50000 50009 50008 50002 50004 50010 50001 50000 50001 50008 50006 50007 50001 50000 50004 50007 50009 50008 50001 50005 50006 50001 50003 50009 50001 50001 50004 50009 50008 500...

output:

659847026551

result:

wrong answer expected '1299816828060', found '659847026551'

Subtask #8:

score: 0
Skipped

Dependency #1:

0%