QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#820792#8923. За связь без перебоевtopfloorboss0 213ms37600kbC++202.1kb2024-12-19 02:10:102024-12-19 02:10:11

Judging History

This is the latest submission verdict.

  • [2024-12-19 02:10:11]
  • Judged
  • Verdict: 0
  • Time: 213ms
  • Memory: 37600kb
  • [2024-12-19 02:10:10]
  • 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 - tl) + (R - tl) * (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();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

input:

1 0
0

output:

0

result:

ok answer is '0'

Test #2:

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

input:

1 1
0

output:

0

result:

ok answer is '0'

Test #3:

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

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:

166549

result:

wrong answer expected '161651', found '166549'

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: 53ms
memory: 34392kb

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: 84ms
memory: 34308kb

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: 81ms
memory: 34524kb

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: 56ms
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: 58ms
memory: 34348kb

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:

166666666476502450

result:

wrong answer expected '166661666666500670', found '166666666476502450'

Subtask #6:

score: 0
Skipped

Dependency #5:

0%

Subtask #7:

score: 0
Wrong Answer

Test #74:

score: 14
Accepted
time: 156ms
memory: 37532kb

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: 213ms
memory: 37600kb

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:

1379746426468

result:

wrong answer expected '1299816828060', found '1379746426468'

Subtask #8:

score: 0
Skipped

Dependency #1:

0%