Submission #572430

# Submission time Handle Problem Language Result Execution time Memory
572430 2022-06-04T11:23:39 Z Huy Just Long Neckties (JOI20_ho_t1) C++17
100 / 100
172 ms 23736 KB
#include<bits/stdc++.h>
#define int long long
#define pii pair<ll,ll>
#define fi first
#define se second

using namespace std;
using ll = long long;
using ldb = long double;
const int N = (int)1e8;
const int maxN = (int)2e5 + 5;
const int mod = 1e9 + 7;
const ll infty = 1e18;

void InputFile()
{
    //freopen("scrivener.inp","r",stdin);
    //freopen("scrivener.out","w",stdout);
    freopen("test.out","r",stdin);
}

void FastInput()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

int n,m;
int id[maxN];
int a[maxN];
int b[maxN];
int su[maxN][2];
/// 0 : i - 1
/// 1 : i

bool FA(int i,int j)
{
    return a[i] < a[j];
}

struct SegmentTree
{
    int ST[4*maxN];
    void Build(int id,int l,int r,int t)
    {
        if(l == r)
        {
            ST[id] = su[l][t];
            return;
        }
        int mid = (l + r) / 2;
        Build(id * 2,l,mid,t);
        Build(id * 2 + 1,mid + 1,r,t);
        ST[id] = max(ST[id*2],ST[id*2+1]);
    }
    int Get(int id,int l,int r,int u,int v)
    {
        if(u > v) return 0;
        if(v < l || u > r) return 0;
        if(u <= l && r <= v)
        {
            return ST[id];
        }
        int mid = (l + r) / 2;
        return max(Get(id*2,l,mid,u,v),Get(id*2+1,mid+1,r,u,v));
    }
};

SegmentTree SgT[2];

int res[maxN];

void Read()
{
    cin >> n;
    for(int i = 1;i <= n + 1;i++)
    {
        cin >> a[i];
        id[i] = i;
    }
    for(int i = 1;i <= n;i++)
        cin >> b[i];

    sort(id + 1,id + n + 2,FA);
    sort(b + 1,b + n + 1);
    for(int i = 1;i <= n + 1;i++)
    {
        su[i][0] = max(0LL,a[id[i]] - b[i-1]);
        su[i][1] = max(0LL,a[id[i]] - b[i]);
    }
    SgT[0].Build(1,1,n+1,0);
    SgT[1].Build(1,1,n+1,1);
    for(int i = 1;i <= n + 1;i++)
    {
        res[id[i]] = max(SgT[1].Get(1,1,n+1,1,i-1),SgT[0].Get(1,1,n+1,i+1,n+1));
    }
    for(int i = 1;i <= n + 1;i++)
    {
        cout << res[i] <<' ';
    }
}

void Solve()
{

}

void Debug()
{
    //Main_sub();
    //Naive();
}


int32_t main()
{
    FastInput();
    //InputFile();
    //int sub_type;
    //cin >> sub_type;
    //Sieve();
    int test;
    //cin >> test;
    test = 1;
    while(test--)
        //for(int prc = 1; prc <= test; prc++)
    {
        Read();
        Solve();
        //Debug();
    }
}

/*
4 1
1 1 1 1
1 2
2 3
3 4
*/

Compilation message

ho_t1.cpp: In function 'void InputFile()':
ho_t1.cpp:19:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     freopen("test.out","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 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 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 2 ms 464 KB Output is correct
21 Correct 2 ms 468 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 2 ms 520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 2 ms 464 KB Output is correct
21 Correct 2 ms 468 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 2 ms 520 KB Output is correct
33 Correct 167 ms 22640 KB Output is correct
34 Correct 136 ms 23284 KB Output is correct
35 Correct 145 ms 22744 KB Output is correct
36 Correct 141 ms 23284 KB Output is correct
37 Correct 135 ms 23736 KB Output is correct
38 Correct 172 ms 23480 KB Output is correct
39 Correct 132 ms 22488 KB Output is correct
40 Correct 147 ms 22484 KB Output is correct
41 Correct 133 ms 22672 KB Output is correct
42 Correct 139 ms 22640 KB Output is correct
43 Correct 134 ms 22424 KB Output is correct
44 Correct 142 ms 22040 KB Output is correct
45 Correct 159 ms 22108 KB Output is correct
46 Correct 144 ms 22040 KB Output is correct
47 Correct 110 ms 22360 KB Output is correct
48 Correct 128 ms 22468 KB Output is correct
49 Correct 136 ms 22940 KB Output is correct
50 Correct 142 ms 22956 KB Output is correct
51 Correct 137 ms 22860 KB Output is correct
52 Correct 133 ms 22968 KB Output is correct
53 Correct 140 ms 22960 KB Output is correct