Submission #560469

# Submission time Handle Problem Language Result Execution time Memory
560469 2022-05-11T13:38:10 Z tamthegod Snowball (JOI21_ho_t2) C++14
100 / 100
1245 ms 9880 KB
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<string.h>
#include<cmath>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<cstdio>
#include<bitset>
#include<chrono>
#include<random>
#include<ext/rope>
/* ordered_set
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
*/
#define int long long
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 1e6 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
int n, q, a[maxN];
int _max[maxN], _min[maxN];
int l[maxN], r[maxN];
void ReadInput()
{
    cin >> n >> q;
    for(int i=1; i<=n; i++) cin >> a[i];
    a[0] = -oo;
    a[n + 1] = oo;
}
bool chk1(int i, int val)
{
    int j = lower_bound(_min + 1, _min + q + 1, val) - _min;
    if(j == q + 1) return false;
    return a[i - 1] + _max[j] <= a[i] - val;
}
bool chk2(int i, int val)
{
    int j = lower_bound(_max + 1, _max + q + 1, val) - _max;
    if(j == q + 1) return false;
    return a[i + 1] - _min[j] >= a[i] + val;
}
void Solve()
{
    ll s = 0;
    for(int i=1; i<=q; i++)
    {
        int x;
        cin >> x;
        s += x;
        _max[i] = max(s, _max[i - 1]);
        _min[i] = max(-s, _min[i - 1]);
    }
    for(int i=1; i<=n; i++)
    {
        int low = 1, high = oo, mid;
        while(low <= high) /// Find l
        {
            mid = (low + high) / 2;
            if(chk1(i, mid)) low = mid + 1;
            else high = mid - 1;
        }
        l[i] = high;
        low = 1, high = oo, mid;
        while(low <= high) /// Find r
        {
            mid = (low + high) / 2;
            if(chk2(i, mid)) low = mid + 1;
            else high = mid - 1;
        }
        r[i] = high;
    }
    for(int i=1; i<=n; i++) cout << r[i] + l[i] << " ";
}
int32_t main()
{
    //freopen("x.inp", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ReadInput();
    Solve();
}

Compilation message

Main.cpp: In function 'void Solve()':
Main.cpp:80:32: warning: right operand of comma operator has no effect [-Wunused-value]
   80 |         low = 1, high = oo, mid;
      |                                ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 10 ms 468 KB Output is correct
5 Correct 10 ms 416 KB Output is correct
6 Correct 9 ms 340 KB Output is correct
7 Correct 6 ms 340 KB Output is correct
8 Correct 6 ms 432 KB Output is correct
9 Correct 6 ms 340 KB Output is correct
10 Correct 6 ms 440 KB Output is correct
11 Correct 7 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 8 ms 340 KB Output is correct
16 Correct 9 ms 340 KB Output is correct
17 Correct 5 ms 440 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 4 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 10 ms 468 KB Output is correct
5 Correct 10 ms 416 KB Output is correct
6 Correct 9 ms 340 KB Output is correct
7 Correct 6 ms 340 KB Output is correct
8 Correct 6 ms 432 KB Output is correct
9 Correct 6 ms 340 KB Output is correct
10 Correct 6 ms 440 KB Output is correct
11 Correct 7 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 8 ms 340 KB Output is correct
16 Correct 9 ms 340 KB Output is correct
17 Correct 5 ms 440 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 4 ms 340 KB Output is correct
20 Correct 27 ms 3376 KB Output is correct
21 Correct 29 ms 3500 KB Output is correct
22 Correct 27 ms 3416 KB Output is correct
23 Correct 35 ms 3452 KB Output is correct
24 Correct 156 ms 4048 KB Output is correct
25 Correct 1245 ms 9780 KB Output is correct
26 Correct 1220 ms 9800 KB Output is correct
27 Correct 1229 ms 9524 KB Output is correct
28 Correct 1165 ms 9456 KB Output is correct
29 Correct 1126 ms 9348 KB Output is correct
30 Correct 817 ms 8928 KB Output is correct
31 Correct 647 ms 8588 KB Output is correct
32 Correct 642 ms 8544 KB Output is correct
33 Correct 93 ms 1236 KB Output is correct
34 Correct 1168 ms 9660 KB Output is correct
35 Correct 1169 ms 9488 KB Output is correct
36 Correct 1171 ms 9732 KB Output is correct
37 Correct 1071 ms 9796 KB Output is correct
38 Correct 1038 ms 9692 KB Output is correct
39 Correct 1020 ms 9588 KB Output is correct
40 Correct 743 ms 9672 KB Output is correct
41 Correct 25 ms 3412 KB Output is correct
42 Correct 544 ms 8524 KB Output is correct
43 Correct 668 ms 9800 KB Output is correct
44 Correct 26 ms 3404 KB Output is correct
45 Correct 631 ms 9584 KB Output is correct
46 Correct 606 ms 9872 KB Output is correct
47 Correct 674 ms 9828 KB Output is correct
48 Correct 591 ms 9880 KB Output is correct