Submission #1096495

# Submission time Handle Problem Language Result Execution time Memory
1096495 2024-10-04T15:50:26 Z coldbr3w Osumnjičeni (COCI21_osumnjiceni) C++17
110 / 110
856 ms 93764 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<long long, long long>
#define pb push_back
#define F first
#define S second  
#define all(x) (x).begin(), (x).end()

const ll N = 3e5 + 100;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll block = 350;
ll n,q;
ll l[N], r[N];
ll up[N][20];
struct segment_tree{
    ll n;
    vector<ll>st, lz;
    void init(ll _n){
        n = _n;
        st.clear(); st.resize(4 * n + 10, 0);
        lz.clear(); lz.resize(4 * n + 10, 0);
    }
    void down(ll id, ll l, ll r){
        st[id] += lz[id];
        if(l != r) lz[2 * id] += lz[id], lz[2 * id + 1] += lz[id];
        lz[id] = 0;
    }
    void update(ll id, ll l, ll r, ll left, ll right, ll val){
        down(id, l, r);
        if(l > right || r < left) return;
        if(left <= l && r <= right){
            lz[id] += val;
            down(id, l, r);
            return;
        }
        ll mid = (l + r) / 2;
        update(2 * id, l, mid, left, right, val);
        update(2 * id + 1, mid + 1, r, left, right, val);
        st[id] = max(st[2 * id], st[2 * id + 1]);
    }
    ll get(ll id, ll l, ll r, ll left, ll right){
        down(id, l, r);
        if(l > right || r < left) return 0;
        if(left <= l && r <= right) return st[id];
        ll mid = (l + r) / 2;
        return max(get(2 * id, l, mid, left, right), get(2 * id + 1, mid + 1, r, left, right));
    }
    void update(ll l, ll r, ll val){update(1,1,n,l,r,val);}
    ll get(ll l, ll r){return get(1,1,n,l,r);}
} st;
void to_thic_cau(){
    cin >> n;
    vector<ll>v;
    for(int i = 1; i <= n;i++){
        cin >> l[i] >> r[i];
        v.pb(l[i]); v.pb(r[i]);
    }
    map<ll,ll>mp;
    sort(all(v)); v.erase(unique(all(v)), v.end());
    for(int i = 0; i < v.size();i++) mp[v[i]] = i + 1;
    for(int i = 1; i <= n;i++) mp[v[i]] = i + 1;
    st.init(2 * n);
    ll j = n;
    for(int i = n; i >= 1;i--){
        l[i] = mp[l[i]], r[i] = mp[r[i]];
        st.update(l[i], r[i], 1);
        while(st.get(1, 2 * n) >= 2){
            st.update(l[j], r[j], -1);
            j--;
        }
        up[i][0] = j + 1;
    }
    for(int j = 1; j <= 19;j++){
        for(int i = 1; i <= n;i++) up[i][j] = up[up[i][j-1]][j-1];
    }
    cin >> q;
    while(q--){
        ll p,q; cin >> p >> q;
        ll res = 1;
        for(int i = 19; i >= 0;i--){
            if(up[p][i] <= q && up[p][i]){
                p = up[p][i];
                res += (1 << i);
            }
        }
        cout << res << "\n";
    }
}

signed main()   
{  
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll tc = 1;
    //cin >> tc;
    while(tc--) to_thic_cau();
}

Compilation message

Main.cpp: In function 'void to_thic_cau()':
Main.cpp:63:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |     for(int i = 0; i < v.size();i++) mp[v[i]] = i + 1;
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 672 ms 87740 KB Output is correct
2 Correct 610 ms 86640 KB Output is correct
3 Correct 562 ms 86660 KB Output is correct
4 Correct 575 ms 87740 KB Output is correct
5 Correct 607 ms 91580 KB Output is correct
6 Correct 181 ms 60856 KB Output is correct
7 Correct 177 ms 61632 KB Output is correct
8 Correct 192 ms 62396 KB Output is correct
9 Correct 187 ms 63936 KB Output is correct
10 Correct 180 ms 61632 KB Output is correct
11 Correct 449 ms 89188 KB Output is correct
12 Correct 401 ms 83904 KB Output is correct
13 Correct 399 ms 83644 KB Output is correct
14 Correct 477 ms 89276 KB Output is correct
15 Correct 470 ms 86964 KB Output is correct
16 Correct 0 ms 600 KB Output is correct
17 Correct 191 ms 64760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 2648 KB Output is correct
2 Correct 9 ms 2680 KB Output is correct
3 Correct 9 ms 2636 KB Output is correct
4 Correct 9 ms 2696 KB Output is correct
5 Correct 9 ms 2420 KB Output is correct
6 Correct 5 ms 2228 KB Output is correct
7 Correct 5 ms 2140 KB Output is correct
8 Correct 5 ms 2168 KB Output is correct
9 Correct 5 ms 2140 KB Output is correct
10 Correct 5 ms 2220 KB Output is correct
11 Correct 6 ms 2652 KB Output is correct
12 Correct 8 ms 2652 KB Output is correct
13 Correct 6 ms 2648 KB Output is correct
14 Correct 9 ms 2652 KB Output is correct
15 Correct 7 ms 2652 KB Output is correct
16 Correct 0 ms 460 KB Output is correct
17 Correct 4 ms 2140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 2648 KB Output is correct
2 Correct 9 ms 2680 KB Output is correct
3 Correct 9 ms 2636 KB Output is correct
4 Correct 9 ms 2696 KB Output is correct
5 Correct 9 ms 2420 KB Output is correct
6 Correct 5 ms 2228 KB Output is correct
7 Correct 5 ms 2140 KB Output is correct
8 Correct 5 ms 2168 KB Output is correct
9 Correct 5 ms 2140 KB Output is correct
10 Correct 5 ms 2220 KB Output is correct
11 Correct 6 ms 2652 KB Output is correct
12 Correct 8 ms 2652 KB Output is correct
13 Correct 6 ms 2648 KB Output is correct
14 Correct 9 ms 2652 KB Output is correct
15 Correct 7 ms 2652 KB Output is correct
16 Correct 0 ms 460 KB Output is correct
17 Correct 4 ms 2140 KB Output is correct
18 Correct 59 ms 5200 KB Output is correct
19 Correct 53 ms 4948 KB Output is correct
20 Correct 59 ms 5460 KB Output is correct
21 Correct 55 ms 4944 KB Output is correct
22 Correct 56 ms 5144 KB Output is correct
23 Correct 50 ms 4504 KB Output is correct
24 Correct 58 ms 4688 KB Output is correct
25 Correct 52 ms 4692 KB Output is correct
26 Correct 53 ms 4724 KB Output is correct
27 Correct 54 ms 4500 KB Output is correct
28 Correct 37 ms 4692 KB Output is correct
29 Correct 37 ms 4688 KB Output is correct
30 Correct 37 ms 4692 KB Output is correct
31 Correct 39 ms 4660 KB Output is correct
32 Correct 37 ms 4752 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 39 ms 4540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 665 ms 91840 KB Output is correct
2 Correct 678 ms 89828 KB Output is correct
3 Correct 588 ms 83844 KB Output is correct
4 Correct 592 ms 82876 KB Output is correct
5 Correct 562 ms 85436 KB Output is correct
6 Correct 182 ms 61116 KB Output is correct
7 Correct 161 ms 60612 KB Output is correct
8 Correct 169 ms 61152 KB Output is correct
9 Correct 184 ms 60604 KB Output is correct
10 Correct 176 ms 65428 KB Output is correct
11 Correct 368 ms 83020 KB Output is correct
12 Correct 423 ms 91296 KB Output is correct
13 Correct 498 ms 82984 KB Output is correct
14 Correct 440 ms 85436 KB Output is correct
15 Correct 509 ms 90676 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 211 ms 62072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 672 ms 87740 KB Output is correct
2 Correct 610 ms 86640 KB Output is correct
3 Correct 562 ms 86660 KB Output is correct
4 Correct 575 ms 87740 KB Output is correct
5 Correct 607 ms 91580 KB Output is correct
6 Correct 181 ms 60856 KB Output is correct
7 Correct 177 ms 61632 KB Output is correct
8 Correct 192 ms 62396 KB Output is correct
9 Correct 187 ms 63936 KB Output is correct
10 Correct 180 ms 61632 KB Output is correct
11 Correct 449 ms 89188 KB Output is correct
12 Correct 401 ms 83904 KB Output is correct
13 Correct 399 ms 83644 KB Output is correct
14 Correct 477 ms 89276 KB Output is correct
15 Correct 470 ms 86964 KB Output is correct
16 Correct 0 ms 600 KB Output is correct
17 Correct 191 ms 64760 KB Output is correct
18 Correct 9 ms 2648 KB Output is correct
19 Correct 9 ms 2680 KB Output is correct
20 Correct 9 ms 2636 KB Output is correct
21 Correct 9 ms 2696 KB Output is correct
22 Correct 9 ms 2420 KB Output is correct
23 Correct 5 ms 2228 KB Output is correct
24 Correct 5 ms 2140 KB Output is correct
25 Correct 5 ms 2168 KB Output is correct
26 Correct 5 ms 2140 KB Output is correct
27 Correct 5 ms 2220 KB Output is correct
28 Correct 6 ms 2652 KB Output is correct
29 Correct 8 ms 2652 KB Output is correct
30 Correct 6 ms 2648 KB Output is correct
31 Correct 9 ms 2652 KB Output is correct
32 Correct 7 ms 2652 KB Output is correct
33 Correct 0 ms 460 KB Output is correct
34 Correct 4 ms 2140 KB Output is correct
35 Correct 59 ms 5200 KB Output is correct
36 Correct 53 ms 4948 KB Output is correct
37 Correct 59 ms 5460 KB Output is correct
38 Correct 55 ms 4944 KB Output is correct
39 Correct 56 ms 5144 KB Output is correct
40 Correct 50 ms 4504 KB Output is correct
41 Correct 58 ms 4688 KB Output is correct
42 Correct 52 ms 4692 KB Output is correct
43 Correct 53 ms 4724 KB Output is correct
44 Correct 54 ms 4500 KB Output is correct
45 Correct 37 ms 4692 KB Output is correct
46 Correct 37 ms 4688 KB Output is correct
47 Correct 37 ms 4692 KB Output is correct
48 Correct 39 ms 4660 KB Output is correct
49 Correct 37 ms 4752 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 39 ms 4540 KB Output is correct
52 Correct 665 ms 91840 KB Output is correct
53 Correct 678 ms 89828 KB Output is correct
54 Correct 588 ms 83844 KB Output is correct
55 Correct 592 ms 82876 KB Output is correct
56 Correct 562 ms 85436 KB Output is correct
57 Correct 182 ms 61116 KB Output is correct
58 Correct 161 ms 60612 KB Output is correct
59 Correct 169 ms 61152 KB Output is correct
60 Correct 184 ms 60604 KB Output is correct
61 Correct 176 ms 65428 KB Output is correct
62 Correct 368 ms 83020 KB Output is correct
63 Correct 423 ms 91296 KB Output is correct
64 Correct 498 ms 82984 KB Output is correct
65 Correct 440 ms 85436 KB Output is correct
66 Correct 509 ms 90676 KB Output is correct
67 Correct 1 ms 344 KB Output is correct
68 Correct 211 ms 62072 KB Output is correct
69 Correct 856 ms 88888 KB Output is correct
70 Correct 775 ms 93764 KB Output is correct
71 Correct 640 ms 86464 KB Output is correct
72 Correct 665 ms 91136 KB Output is correct
73 Correct 653 ms 89696 KB Output is correct
74 Correct 326 ms 69704 KB Output is correct
75 Correct 280 ms 64856 KB Output is correct
76 Correct 345 ms 70336 KB Output is correct
77 Correct 268 ms 64704 KB Output is correct
78 Correct 308 ms 65524 KB Output is correct
79 Correct 483 ms 93408 KB Output is correct
80 Correct 448 ms 86724 KB Output is correct
81 Correct 382 ms 85948 KB Output is correct
82 Correct 477 ms 90808 KB Output is correct
83 Correct 445 ms 86780 KB Output is correct
84 Correct 0 ms 344 KB Output is correct
85 Correct 255 ms 64704 KB Output is correct