Submission #516960

# Submission time Handle Problem Language Result Execution time Memory
516960 2022-01-22T09:24:26 Z kevinxiehk Just Long Neckties (JOI20_ho_t1) C++17
100 / 100
134 ms 23412 KB
#include <bits/stdc++.h>
#define mp make_pair
#define pb emplace_back
#define fi first
#define se second
#define int long long
#define ick cout<<"ickbmi32.9\n"
using namespace std;
bool isprime(int k) {
    for(int i = 2; i <= sqrt(k); i++) if(k % i == 0) return false; 
    return true;    
}
int bm(int a, int b, int mod) {
    if(b == 0) return 1; 
    int t = bm(a, b / 2, mod); 
    t = t * t % mod; 
    return (b % 2 == 1 ? t * a % mod : t);
}
int inv(int a, int mod) {return bm(a, mod - 2, mod);}
int ans[200005], aans[200005];
signed main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    pair<int, int> arr[n + 5];
    for(int i = 0; i <= n; i++) cin >> arr[i].fi, arr[i].se = i;
    int a[n + 5];
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    sort(arr, arr + n + 1);
    vector<pair<int, pair<int, int>>> tm; // val, id, l/r
    for(int i = 0; i < n; i++) {
        tm.pb(mp(-max(arr[i].fi - a[i], 0LL), mp(i + 1, 0)));
        tm.pb(mp(-max(arr[i + 1].fi - a[i], 0LL), mp(i, 1)));
    }    
    sort(tm.begin(), tm.end());
    int lpt = 0, rpt = n;
    for(auto x: tm) {
        if(x.se.se == 0) {
            while(rpt >= x.se.fi) {
                ans[rpt] = max(ans[rpt], -x.fi);
                rpt--;
            }
        }
        else {
            while(lpt <= x.se.fi) {
                ans[lpt] = max(ans[lpt], -x.fi);
                lpt++;
            }
        }
    }
    for(int i = 0; i <= n; i++) aans[arr[i].se] = ans[i];
    for(int i = 0; i <= n; i++) cout << aans[i] << (i == n ? '\n' : ' ');
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 320 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 320 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 324 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 2 ms 588 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 1 ms 588 KB Output is correct
18 Correct 2 ms 588 KB Output is correct
19 Correct 1 ms 584 KB Output is correct
20 Correct 1 ms 592 KB Output is correct
21 Correct 2 ms 584 KB Output is correct
22 Correct 1 ms 588 KB Output is correct
23 Correct 1 ms 496 KB Output is correct
24 Correct 1 ms 568 KB Output is correct
25 Correct 1 ms 576 KB Output is correct
26 Correct 1 ms 588 KB Output is correct
27 Correct 2 ms 588 KB Output is correct
28 Correct 1 ms 588 KB Output is correct
29 Correct 2 ms 588 KB Output is correct
30 Correct 1 ms 568 KB Output is correct
31 Correct 1 ms 580 KB Output is correct
32 Correct 1 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 320 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 324 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 2 ms 588 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 1 ms 588 KB Output is correct
18 Correct 2 ms 588 KB Output is correct
19 Correct 1 ms 584 KB Output is correct
20 Correct 1 ms 592 KB Output is correct
21 Correct 2 ms 584 KB Output is correct
22 Correct 1 ms 588 KB Output is correct
23 Correct 1 ms 496 KB Output is correct
24 Correct 1 ms 568 KB Output is correct
25 Correct 1 ms 576 KB Output is correct
26 Correct 1 ms 588 KB Output is correct
27 Correct 2 ms 588 KB Output is correct
28 Correct 1 ms 588 KB Output is correct
29 Correct 2 ms 588 KB Output is correct
30 Correct 1 ms 568 KB Output is correct
31 Correct 1 ms 580 KB Output is correct
32 Correct 1 ms 632 KB Output is correct
33 Correct 129 ms 22028 KB Output is correct
34 Correct 118 ms 22888 KB Output is correct
35 Correct 134 ms 22148 KB Output is correct
36 Correct 128 ms 22684 KB Output is correct
37 Correct 128 ms 23412 KB Output is correct
38 Correct 116 ms 23124 KB Output is correct
39 Correct 128 ms 22012 KB Output is correct
40 Correct 130 ms 21908 KB Output is correct
41 Correct 126 ms 22372 KB Output is correct
42 Correct 128 ms 22100 KB Output is correct
43 Correct 120 ms 21940 KB Output is correct
44 Correct 105 ms 21396 KB Output is correct
45 Correct 112 ms 21664 KB Output is correct
46 Correct 106 ms 21472 KB Output is correct
47 Correct 109 ms 22068 KB Output is correct
48 Correct 110 ms 22072 KB Output is correct
49 Correct 130 ms 22712 KB Output is correct
50 Correct 134 ms 22676 KB Output is correct
51 Correct 122 ms 22700 KB Output is correct
52 Correct 127 ms 22636 KB Output is correct
53 Correct 129 ms 22632 KB Output is correct