Submission #1031587

# Submission time Handle Problem Language Result Execution time Memory
1031587 2024-07-23T02:14:30 Z underwaterkillerwhale Snowball (JOI21_ho_t2) C++17
33 / 100
2500 ms 11488 KB
#include <bits/stdc++.h>
#define se              second
#define fs              first
#define mp              make_pair
#define pb              push_back
#define ll              long long
#define ii              pair<ll,ll>
#define ld              long double
#define SZ(v)           (int)v.size()
#define ALL(v)          v.begin(), v.end()
#define bit(msk, i)     ((msk >> i) & 1)
#define iter(id, v)     for(auto id : v)
#define rep(i,m,n)      for(int i=(m); i<=(n); i++)
#define reb(i,m,n)      for(int i=(m); i>=(n); i--)
using namespace std;

mt19937_64 rd(chrono :: steady_clock :: now().time_since_epoch().count());
ll Rand(ll l, ll r) { return uniform_int_distribution<ll> (l, r)(rd); }

const int N = 2e5 + 7;
const int Mod = 1e9 + 7;
const int szBL = 320;
const ll INF = 1e18;
const int BASE = 137;

int n, Q;
ll a[N];
ll qr[N];

struct fenwick_Treemx {
    ll fen[N];
    void update (int pos, ll val) {
        for (; pos <= Q; pos += pos & -pos) fen[pos] = max(fen[pos], val);
    }
    ll get (int pos) {
        ll res = 0;
        for (; pos > 0 ; pos -= pos & -pos) res = max(res, fen[pos]);
        return res;
    }
}fenmx;

struct fenwick_Treemn {
    ll fen[N];
    void update (int pos, ll val) {
        for (; pos <= Q; pos += pos & -pos) fen[pos] = min(fen[pos], val);
    }
    ll get (int pos) {
        ll res = 0;
        for (; pos > 0 ; pos -= pos & -pos) res = min(res, fen[pos]);
        return res;
    }
}fenmn;

void solution () {
    cin >> n >> Q;
    rep (i, 1, n) cin >> a[i];
    ll pre = 0;
    rep (i, 1, Q) {
        cin >> qr[i];
        pre += qr[i];
        fenmx.update (i, pre);
        fenmn.update (i, pre);
//        cout << pre <<"\n";
    }
//    cout << fenmn.get(Q) <<" aa\n";
//    return;
    a[n + 1] = INF;
    a[0] = -INF;
    rep (i, 1, n) {
        ll R; {
            ll lf = a[i], rt = INF;
            while (lf < rt) {
                ll X = lf + rt + 1 >> 1;
                int posR; {
                    int lf = 0, rt = Q;
                    while (lf < rt) {
                        int mid = lf + rt >> 1;
                        if (a[i] + fenmx.get(mid) >= X) rt = mid;
                        else lf = mid + 1;
                    }
                    if (a[i] + fenmx.get(rt) >= X) posR = rt;
                    else posR = -1;
                }
                if (posR == -1 || a[i + 1] + fenmn.get(posR) < X) rt = X - 1;
                else lf = X;
            }
            R = lf;
        }
        ll L; {
            ll lf = -INF, rt = a[i];
            while (lf < rt) {
                ll X = lf + rt >> 1;
                int posL; {
                    int lf = 0, rt = Q;
                    while (lf < rt) {
                        int mid = (lf + rt) / 2;
                        if (a[i] + fenmn.get(mid) <= X) rt = mid;
                        else lf = mid + 1;
                    }
                    if (a[i] + fenmn.get(rt) <= X) posL = rt;
                    else posL = -1;
                }
//                cout << i << " "<<X << " "<<a[i] + fenmn.get(Q) <<"\n";
                if (posL == -1 || a[i - 1] + fenmx.get(posL) > X) lf = X + 1;
                else rt = X;
            }
            L = lf;
        }
        cout << R - L<<"\n";
    }
}

#define file(name) freopen(name".inp", "r", stdin); \
freopen(name".out", "w", stdout);

int main () {
//    file("c");
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll num_Test = 1;
//    cin >> num_Test;
    while(num_Test--)
        solution();
}

Compilation message

Main.cpp: In function 'void solution()':
Main.cpp:73:32: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   73 |                 ll X = lf + rt + 1 >> 1;
      |                        ~~~~~~~~^~~
Main.cpp:77:38: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   77 |                         int mid = lf + rt >> 1;
      |                                   ~~~^~~~
Main.cpp:92:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   92 |                 ll X = lf + rt >> 1;
      |                        ~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 16 ms 608 KB Output is correct
5 Correct 17 ms 596 KB Output is correct
6 Correct 16 ms 600 KB Output is correct
7 Correct 16 ms 476 KB Output is correct
8 Correct 16 ms 600 KB Output is correct
9 Correct 16 ms 348 KB Output is correct
10 Correct 14 ms 576 KB Output is correct
11 Correct 14 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 2 ms 480 KB Output is correct
15 Correct 17 ms 604 KB Output is correct
16 Correct 17 ms 480 KB Output is correct
17 Correct 15 ms 604 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 15 ms 484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 16 ms 608 KB Output is correct
5 Correct 17 ms 596 KB Output is correct
6 Correct 16 ms 600 KB Output is correct
7 Correct 16 ms 476 KB Output is correct
8 Correct 16 ms 600 KB Output is correct
9 Correct 16 ms 348 KB Output is correct
10 Correct 14 ms 576 KB Output is correct
11 Correct 14 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 2 ms 480 KB Output is correct
15 Correct 17 ms 604 KB Output is correct
16 Correct 17 ms 480 KB Output is correct
17 Correct 15 ms 604 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 15 ms 484 KB Output is correct
20 Correct 24 ms 7260 KB Output is correct
21 Correct 22 ms 7004 KB Output is correct
22 Correct 25 ms 6740 KB Output is correct
23 Correct 60 ms 6748 KB Output is correct
24 Correct 430 ms 7032 KB Output is correct
25 Execution timed out 2537 ms 11488 KB Time limit exceeded
26 Halted 0 ms 0 KB -