Submission #571245

# Submission time Handle Problem Language Result Execution time Memory
571245 2022-06-01T15:23:52 Z YouAreMyGalaxy Snowball (JOI21_ho_t2) C++17
100 / 100
124 ms 12976 KB
//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
#define Log2(x) 31 - __builtin_clz(x)
using namespace std;
const int N = 2e5;
const long long oo = 1e18 + 10;
long long x[N + 1], l[N + 1], r[N + 1], cur, MaxLeft = 0, MaxRight = 0;
int n, q, id[N + 1];
void read()
{
    cin >> n >> q;
    for (int i = 1; i <= n; ++ i)
    {
        cin >> x[i];
        id[i] = i;
        l[i] = -oo;
        r[i] = oo;
    }
    sort(id + 1, id + n, [&](const int &a, const int &b)
         {
             return x[a + 1] - x[a] < x[b + 1] - x[b];
         });
}
void solve()
{
    int i = 1;
    while(q--)
    {
        long long w;
        cin >> w;
        cur += w;
        MaxRight = max(MaxRight, cur);
        MaxLeft = min(MaxLeft, cur);
        for (; i < n && x[id[i] + 1] - x[id[i]] <= MaxRight - MaxLeft; ++ i)
        {
            int j = id[i];
            if (w > 0)
            {
                r[j] = x[j + 1] + MaxLeft - 1;
                l[j + 1] = x[j + 1] + MaxLeft;
            }
            else
            {
                l[j + 1] = x[j] + MaxRight;
                r[j] = x[j] + MaxRight - 1;
            }
        }
    }
    for (int i = 1; i <= n; ++ i)
    {
        //cerr << l[i] << ' ' << r[i] << '\n';
        long long L = (l[i] == -oo ? x[i] + MaxLeft : l[i]), R = (r[i] == oo ? x[i] + MaxRight - 1 : r[i]);
        //cerr << L << ' ' << R << '\n';
        cout << R - L + 1 << '\n';
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (fopen(TASK".INP", "r"))
    {
        freopen(TASK".INP", "r", stdin);
        //freopen(TASK".OUT", "w", stdout);
    }
    int t = 1;
    bool typetest = false;
    if (typetest)
    {
        cin >> t;
    }
    for (int __ = 1; __ <= t; ++ __)
    {
        //cout << "Case " << __ << ": ";
        read();
        solve();
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 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 2 ms 468 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 2 ms 464 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 408 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 2 ms 468 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 2 ms 464 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 408 KB Output is correct
20 Correct 30 ms 2372 KB Output is correct
21 Correct 28 ms 2248 KB Output is correct
22 Correct 25 ms 2028 KB Output is correct
23 Correct 21 ms 1924 KB Output is correct
24 Correct 39 ms 2588 KB Output is correct
25 Correct 102 ms 11088 KB Output is correct
26 Correct 99 ms 10964 KB Output is correct
27 Correct 100 ms 10632 KB Output is correct
28 Correct 95 ms 10828 KB Output is correct
29 Correct 83 ms 10316 KB Output is correct
30 Correct 69 ms 9632 KB Output is correct
31 Correct 69 ms 9084 KB Output is correct
32 Correct 86 ms 9320 KB Output is correct
33 Correct 10 ms 1492 KB Output is correct
34 Correct 93 ms 11420 KB Output is correct
35 Correct 124 ms 10824 KB Output is correct
36 Correct 113 ms 11048 KB Output is correct
37 Correct 93 ms 10768 KB Output is correct
38 Correct 88 ms 10608 KB Output is correct
39 Correct 108 ms 10776 KB Output is correct
40 Correct 84 ms 10852 KB Output is correct
41 Correct 42 ms 3016 KB Output is correct
42 Correct 90 ms 9300 KB Output is correct
43 Correct 85 ms 12560 KB Output is correct
44 Correct 33 ms 2912 KB Output is correct
45 Correct 93 ms 10768 KB Output is correct
46 Correct 96 ms 12692 KB Output is correct
47 Correct 92 ms 12944 KB Output is correct
48 Correct 100 ms 12976 KB Output is correct