Submission #1095818

# Submission time Handle Problem Language Result Execution time Memory
1095818 2024-10-03T09:02:23 Z vladilius Gift Exchange (JOI24_ho_t4) C++17
50 / 100
2500 ms 13796 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
#define ins insert
#define arr3 array<int, 3>

struct ST{
    vector<pii> t;
    int n;
    ST(int ns){
        n = ns;
        t.resize(4 * n);
    }
    void upd(int v, int tl, int tr, int& p, int& x){
        if (tl == tr){
            t[v] = {x, tl};
            return;
        }
        int tm = (tl + tr) / 2, vv = 2 * v;
        if (p <= tm){
            upd(vv, tl, tm, p, x);
        }
        else {
            upd(vv + 1, tm + 1, tr, p, x);
        }
        t[v] = max(t[vv], t[vv + 1]);
    }
    void upd(int p, int x){
        upd(1, 1, n, p, x);
    }
    pii get(int v, int tl, int tr, int& l, int& r){
        if (l > tr || r < tl) return {0, 0};
        if (l <= tl && tr <= r) return t[v];
        int tm = (tl + tr) / 2, vv = 2 * v;
        return max(get(vv, tl, tm, l, r), get(vv + 1, tm + 1, tr, l, r));
    }
    pii get(int l, int r){
        return get(1, 1, n, l, r);
    }
};
 
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n; cin>>n;
    vector<int> a(n + 1), b(n + 1);
    for (int i = 1; i <= n; i++) cin>>a[i];
    for (int i = 1; i <= n; i++) cin>>b[i];
    
    int q; cin>>q;
    while (q--){
        int l, r; cin>>l>>r;
        vector<arr3> st;
        for (int i = l; i <= r; i++){
            st.pb({b[i], a[i], i});
        }
        sort(st.begin(), st.end());
        vector<pii> x;
        for (int i = 0; i < (int) st.size(); i++){
            x.pb({st[i][1], i + 1});
        }
        sort(x.begin(), x.end());
        ST T(n);
        vector<int> p(n + 1), xx;
        for (int i = 0; i < x.size(); i++){
            T.upd(i + 1, x[i].ss);
            p[x[i].ss - 1] = i + 1;
            xx.pb(x[i].ff);
        }
        vector<int> :: iterator it;
        set<pii> st1;
        for (int i = 0; i < st.size(); i++) st1.insert({st[i][1], i});
        bool ind = 1;
        for (int j = st.size() - 1; j >= 0; j--){
            it = lower_bound(xx.begin(), xx.end(), st[j][0]);
            int ii = (int) (it - xx.begin()) + 1;
            pii mx = max(T.get(ii, p[j] - 1), T.get(p[j] + 1, n));
            if (!mx.ff){
                bool k = (st1.find({st[j][1], j}) != st1.end());
                if (k) st1.erase({st[j][1], j});
                
                if (st1.empty()){
                    ind = 0;
                    break;
                }
                
                auto f = prev(st1.end());
                if ((*f).ff < st[j][0]){
                    ind = 0;
                    break;
                }
                T.upd(p[(*f).ss], 0);
                st1.erase(f);
                
                if (k) st1.insert({st[j][1], j});
                continue;
            }
            T.upd(mx.ss, 0);
            int t = x[mx.ss - 1].ss - 1;
            st1.erase({st[t][1], t});
            
            T.upd(p[j], 0);
        }
        
        cout<<((ind) ? "Yes" : "No")<<"\n";
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:71:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |         for (int i = 0; i < x.size(); i++){
      |                         ~~^~~~~~~~~~
Main.cpp:78:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |         for (int i = 0; i < st.size(); i++) st1.insert({st[i][1], i});
      |                         ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 452 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 452 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 604 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 166 ms 13072 KB Output is correct
5 Correct 173 ms 13000 KB Output is correct
6 Correct 165 ms 13000 KB Output is correct
7 Correct 162 ms 13000 KB Output is correct
8 Correct 160 ms 13028 KB Output is correct
9 Correct 171 ms 12980 KB Output is correct
10 Correct 65 ms 13000 KB Output is correct
11 Correct 66 ms 13000 KB Output is correct
12 Correct 160 ms 12992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 452 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 604 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 166 ms 13072 KB Output is correct
38 Correct 173 ms 13000 KB Output is correct
39 Correct 165 ms 13000 KB Output is correct
40 Correct 162 ms 13000 KB Output is correct
41 Correct 160 ms 13028 KB Output is correct
42 Correct 171 ms 12980 KB Output is correct
43 Correct 65 ms 13000 KB Output is correct
44 Correct 66 ms 13000 KB Output is correct
45 Correct 160 ms 12992 KB Output is correct
46 Correct 416 ms 8440 KB Output is correct
47 Correct 327 ms 10172 KB Output is correct
48 Correct 103 ms 6876 KB Output is correct
49 Correct 235 ms 10544 KB Output is correct
50 Correct 206 ms 12092 KB Output is correct
51 Correct 275 ms 12304 KB Output is correct
52 Correct 13 ms 4620 KB Output is correct
53 Correct 41 ms 9144 KB Output is correct
54 Correct 440 ms 13564 KB Output is correct
55 Correct 1257 ms 13796 KB Output is correct
56 Correct 122 ms 13032 KB Output is correct
57 Correct 439 ms 12496 KB Output is correct
58 Correct 174 ms 13276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Execution timed out 2503 ms 10876 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Execution timed out 2503 ms 10876 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 452 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 604 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 166 ms 13072 KB Output is correct
38 Correct 173 ms 13000 KB Output is correct
39 Correct 165 ms 13000 KB Output is correct
40 Correct 162 ms 13000 KB Output is correct
41 Correct 160 ms 13028 KB Output is correct
42 Correct 171 ms 12980 KB Output is correct
43 Correct 65 ms 13000 KB Output is correct
44 Correct 66 ms 13000 KB Output is correct
45 Correct 160 ms 12992 KB Output is correct
46 Correct 416 ms 8440 KB Output is correct
47 Correct 327 ms 10172 KB Output is correct
48 Correct 103 ms 6876 KB Output is correct
49 Correct 235 ms 10544 KB Output is correct
50 Correct 206 ms 12092 KB Output is correct
51 Correct 275 ms 12304 KB Output is correct
52 Correct 13 ms 4620 KB Output is correct
53 Correct 41 ms 9144 KB Output is correct
54 Correct 440 ms 13564 KB Output is correct
55 Correct 1257 ms 13796 KB Output is correct
56 Correct 122 ms 13032 KB Output is correct
57 Correct 439 ms 12496 KB Output is correct
58 Correct 174 ms 13276 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Execution timed out 2503 ms 10876 KB Time limit exceeded
63 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 452 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 604 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 166 ms 13072 KB Output is correct
38 Correct 173 ms 13000 KB Output is correct
39 Correct 165 ms 13000 KB Output is correct
40 Correct 162 ms 13000 KB Output is correct
41 Correct 160 ms 13028 KB Output is correct
42 Correct 171 ms 12980 KB Output is correct
43 Correct 65 ms 13000 KB Output is correct
44 Correct 66 ms 13000 KB Output is correct
45 Correct 160 ms 12992 KB Output is correct
46 Correct 416 ms 8440 KB Output is correct
47 Correct 327 ms 10172 KB Output is correct
48 Correct 103 ms 6876 KB Output is correct
49 Correct 235 ms 10544 KB Output is correct
50 Correct 206 ms 12092 KB Output is correct
51 Correct 275 ms 12304 KB Output is correct
52 Correct 13 ms 4620 KB Output is correct
53 Correct 41 ms 9144 KB Output is correct
54 Correct 440 ms 13564 KB Output is correct
55 Correct 1257 ms 13796 KB Output is correct
56 Correct 122 ms 13032 KB Output is correct
57 Correct 439 ms 12496 KB Output is correct
58 Correct 174 ms 13276 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Execution timed out 2503 ms 10876 KB Time limit exceeded
63 Halted 0 ms 0 KB -