Submission #1090553

# Submission time Handle Problem Language Result Execution time Memory
1090553 2024-09-18T12:44:50 Z gyg Martian DNA (BOI18_dna) C++17
0 / 100
1256 ms 11604 KB
#pragma GCC optimize("Ofast", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
#define arr array
#define pii pair<int, int>
const int MX_N = 2e5 + 5;

int n;
arr<int, MX_N> vl, rq;

arr<int, MX_N> scr;
set<pii> ord;
void upd(int i, int x) {
    ord.erase({scr[i], i});
    scr[i] += x;
    ord.insert({scr[i], i});
}
bool chck(int sz) {
    for (int i = 1; i <= n; i++) scr[i] = -rq[i];
    ord.clear();
    for (int i = 1; i <= sz; i++) scr[i]++;
    for (int i = 1; i <= n; i++) ord.insert({scr[i], i});
    if (ord.begin()->first >= 0) return true;
    
    for (int i = sz + 1; i <= n; i++) {
        upd(vl[i], 1), upd(vl[i - sz], -1);
        if (ord.begin()->first >= 0) return true;
    }
    return false;
}

int bn_srch() {
    int lw = 1, hgh = n;
    while (lw != hgh) {
        // cout << lw << " " << hgh << endl;
        int md = (lw + hgh) / 2;
        if (chck(md)) hgh = md;
        else lw = md + 1;
    }
    return ((chck(lw)) ? lw : -1);
}

int main() {
    // freopen("mrt.in", "r", stdin);
    cin.sync_with_stdio(false), cin.tie(0);
    int tmp1, tmp2; cin >> n >> tmp1 >> tmp2;
    for (int i = 1; i <= n; i++) { cin >> vl[i]; vl[i]++; }
    for (int i = 1; i <= tmp2; i++) { int x; cin >> x; cin >> rq[x + 1]; }

    if (!chck(n)) { cout << "impossible" << endl; exit(0); }

    int ans = bn_srch();
    cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 11200 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1256 ms 11604 KB Output isn't correct
2 Halted 0 ms 0 KB -