Submission #1085840

# Submission time Handle Problem Language Result Execution time Memory
1085840 2024-09-08T20:59:17 Z MrPavlito Snowball (JOI21_ho_t2) C++17
100 / 100
844 ms 16952 KB
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define sc second
#define endl "\n"
#define pii pair<int,int>

using namespace std;

const int MAXN = 1e5+5;
const int mod7 = 1e9+7;
const long long inf = 1e18;

signed main()
{
    ios_base::sync_with_stdio(false),cin.tie(0), cout.tie(0);
    int tt=1;
    //cin >> tt;
    while(tt--)
    {
        int n,q;
        cin >> n >> q;
        vector<int> niz(n);
        vector<int> maxdelta(q+1, 0);
        vector<int> mindelta(q+1, 0);
        vector<int> query(q);
        for(int i=0; i<n; i++)cin >> niz[i];
        int delta= 0;
        for(int i= 0; i<q; i++)
        {
            cin >> query[i];
            delta += query[i];
            mindelta[i+1] = min(mindelta[i], delta);
            maxdelta[i+1] = max(maxdelta[i], delta);
        }
        for(int i=1; i<=q; i++)mindelta[i]*=-1;
        vector<int> deltaR(n, 0);
        vector<int> deltaL(n, 0);
        deltaR[n-1] = maxdelta[q];
        deltaL[0] = mindelta[q];
        maxdelta.pb(inf);
        mindelta.pb(inf);
        for(int i=0; i<n-1; i++)
        {
            int l = 0;int r = niz[i+1] - niz[i];
            int rez = 0;
            while(l<=r)
            {
                int mid = l+r>>1;
                int index = lower_bound(all(maxdelta), mid) - maxdelta.begin();
                if(niz[i] + mid <= niz[i+1] - mindelta[index])
                {
                    l = mid+1;
                    rez = mid;
                }
                else r = mid-1;
            }
            deltaR[i] = rez;
        }
        for(int i=n-1; i>0; i--)
        {
            int l = 0;int r = niz[i] - niz[i-1];
            int rez = 0;
            while(l<=r)
            {
                int mid = l+r>>1;
                int index = lower_bound(all(mindelta), mid) - mindelta.begin();
                if(niz[i] - mid >= niz[i-1] + maxdelta[index])
                {
                    l = mid+1;
                    rez = mid;
                }
                else r = mid-1;
            }
            deltaL[i] = rez;
        }
        for(int i=0; i<n; i++)cout << deltaL[i] + deltaR[i] << endl;


    }
}

/*
1 4
1000000000000
1000000000000
-1000000000000
-1000000000000
-1000000000000
*/

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:52:28: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   52 |                 int mid = l+r>>1;
      |                           ~^~
Main.cpp:69:28: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   69 |                 int mid = l+r>>1;
      |                           ~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 5 ms 604 KB Output is correct
5 Correct 4 ms 604 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 3 ms 604 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 376 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 4 ms 464 KB Output is correct
16 Correct 4 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 5 ms 604 KB Output is correct
5 Correct 4 ms 604 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 3 ms 604 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 376 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 4 ms 464 KB Output is correct
16 Correct 4 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 552 KB Output is correct
20 Correct 24 ms 8784 KB Output is correct
21 Correct 19 ms 8540 KB Output is correct
22 Correct 19 ms 8432 KB Output is correct
23 Correct 25 ms 8284 KB Output is correct
24 Correct 97 ms 8800 KB Output is correct
25 Correct 810 ms 15160 KB Output is correct
26 Correct 790 ms 14932 KB Output is correct
27 Correct 763 ms 14940 KB Output is correct
28 Correct 751 ms 14904 KB Output is correct
29 Correct 708 ms 14676 KB Output is correct
30 Correct 219 ms 14420 KB Output is correct
31 Correct 59 ms 14396 KB Output is correct
32 Correct 47 ms 14416 KB Output is correct
33 Correct 54 ms 1988 KB Output is correct
34 Correct 636 ms 15440 KB Output is correct
35 Correct 708 ms 14932 KB Output is correct
36 Correct 844 ms 15168 KB Output is correct
37 Correct 763 ms 14928 KB Output is correct
38 Correct 782 ms 14772 KB Output is correct
39 Correct 742 ms 14932 KB Output is correct
40 Correct 177 ms 14928 KB Output is correct
41 Correct 23 ms 9368 KB Output is correct
42 Correct 149 ms 14420 KB Output is correct
43 Correct 157 ms 16664 KB Output is correct
44 Correct 21 ms 9340 KB Output is correct
45 Correct 355 ms 14912 KB Output is correct
46 Correct 178 ms 16660 KB Output is correct
47 Correct 159 ms 16920 KB Output is correct
48 Correct 185 ms 16952 KB Output is correct