Submission #1098665

# Submission time Handle Problem Language Result Execution time Memory
1098665 2024-10-09T16:26:29 Z flyingkite Osumnjičeni (COCI21_osumnjiceni) C++17
110 / 110
619 ms 56264 KB
#include <bits/stdc++.h>
using namespace std;
 
#define ll int
#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 = 1e9;
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<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 504 ms 51204 KB Output is correct
2 Correct 503 ms 50668 KB Output is correct
3 Correct 476 ms 50692 KB Output is correct
4 Correct 528 ms 51260 KB Output is correct
5 Correct 554 ms 53704 KB Output is correct
6 Correct 208 ms 31940 KB Output is correct
7 Correct 166 ms 32464 KB Output is correct
8 Correct 162 ms 32708 KB Output is correct
9 Correct 187 ms 33280 KB Output is correct
10 Correct 152 ms 32436 KB Output is correct
11 Correct 363 ms 52068 KB Output is correct
12 Correct 331 ms 48788 KB Output is correct
13 Correct 322 ms 48784 KB Output is correct
14 Correct 355 ms 52168 KB Output is correct
15 Correct 350 ms 50940 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 189 ms 33872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1880 KB Output is correct
2 Correct 8 ms 1628 KB Output is correct
3 Correct 11 ms 1780 KB Output is correct
4 Correct 8 ms 1628 KB Output is correct
5 Correct 9 ms 1804 KB Output is correct
6 Correct 5 ms 1372 KB Output is correct
7 Correct 5 ms 1224 KB Output is correct
8 Correct 4 ms 1372 KB Output is correct
9 Correct 4 ms 1372 KB Output is correct
10 Correct 4 ms 1368 KB Output is correct
11 Correct 5 ms 1628 KB Output is correct
12 Correct 5 ms 1628 KB Output is correct
13 Correct 5 ms 1628 KB Output is correct
14 Correct 7 ms 1628 KB Output is correct
15 Correct 6 ms 1628 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 4 ms 1368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1880 KB Output is correct
2 Correct 8 ms 1628 KB Output is correct
3 Correct 11 ms 1780 KB Output is correct
4 Correct 8 ms 1628 KB Output is correct
5 Correct 9 ms 1804 KB Output is correct
6 Correct 5 ms 1372 KB Output is correct
7 Correct 5 ms 1224 KB Output is correct
8 Correct 4 ms 1372 KB Output is correct
9 Correct 4 ms 1372 KB Output is correct
10 Correct 4 ms 1368 KB Output is correct
11 Correct 5 ms 1628 KB Output is correct
12 Correct 5 ms 1628 KB Output is correct
13 Correct 5 ms 1628 KB Output is correct
14 Correct 7 ms 1628 KB Output is correct
15 Correct 6 ms 1628 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 4 ms 1368 KB Output is correct
18 Correct 57 ms 4144 KB Output is correct
19 Correct 51 ms 3976 KB Output is correct
20 Correct 57 ms 4176 KB Output is correct
21 Correct 51 ms 4208 KB Output is correct
22 Correct 57 ms 4176 KB Output is correct
23 Correct 49 ms 3620 KB Output is correct
24 Correct 53 ms 3784 KB Output is correct
25 Correct 66 ms 3672 KB Output is correct
26 Correct 51 ms 3816 KB Output is correct
27 Correct 50 ms 3784 KB Output is correct
28 Correct 35 ms 3732 KB Output is correct
29 Correct 38 ms 3664 KB Output is correct
30 Correct 41 ms 3604 KB Output is correct
31 Correct 37 ms 3660 KB Output is correct
32 Correct 37 ms 3744 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 38 ms 3712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 536 ms 53760 KB Output is correct
2 Correct 559 ms 52560 KB Output is correct
3 Correct 521 ms 49020 KB Output is correct
4 Correct 487 ms 48580 KB Output is correct
5 Correct 536 ms 49996 KB Output is correct
6 Correct 185 ms 32176 KB Output is correct
7 Correct 151 ms 31936 KB Output is correct
8 Correct 181 ms 32144 KB Output is correct
9 Correct 187 ms 31800 KB Output is correct
10 Correct 177 ms 34176 KB Output is correct
11 Correct 340 ms 48512 KB Output is correct
12 Correct 375 ms 53416 KB Output is correct
13 Correct 317 ms 48328 KB Output is correct
14 Correct 356 ms 50172 KB Output is correct
15 Correct 386 ms 52936 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 183 ms 32452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 504 ms 51204 KB Output is correct
2 Correct 503 ms 50668 KB Output is correct
3 Correct 476 ms 50692 KB Output is correct
4 Correct 528 ms 51260 KB Output is correct
5 Correct 554 ms 53704 KB Output is correct
6 Correct 208 ms 31940 KB Output is correct
7 Correct 166 ms 32464 KB Output is correct
8 Correct 162 ms 32708 KB Output is correct
9 Correct 187 ms 33280 KB Output is correct
10 Correct 152 ms 32436 KB Output is correct
11 Correct 363 ms 52068 KB Output is correct
12 Correct 331 ms 48788 KB Output is correct
13 Correct 322 ms 48784 KB Output is correct
14 Correct 355 ms 52168 KB Output is correct
15 Correct 350 ms 50940 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 189 ms 33872 KB Output is correct
18 Correct 9 ms 1880 KB Output is correct
19 Correct 8 ms 1628 KB Output is correct
20 Correct 11 ms 1780 KB Output is correct
21 Correct 8 ms 1628 KB Output is correct
22 Correct 9 ms 1804 KB Output is correct
23 Correct 5 ms 1372 KB Output is correct
24 Correct 5 ms 1224 KB Output is correct
25 Correct 4 ms 1372 KB Output is correct
26 Correct 4 ms 1372 KB Output is correct
27 Correct 4 ms 1368 KB Output is correct
28 Correct 5 ms 1628 KB Output is correct
29 Correct 5 ms 1628 KB Output is correct
30 Correct 5 ms 1628 KB Output is correct
31 Correct 7 ms 1628 KB Output is correct
32 Correct 6 ms 1628 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 4 ms 1368 KB Output is correct
35 Correct 57 ms 4144 KB Output is correct
36 Correct 51 ms 3976 KB Output is correct
37 Correct 57 ms 4176 KB Output is correct
38 Correct 51 ms 4208 KB Output is correct
39 Correct 57 ms 4176 KB Output is correct
40 Correct 49 ms 3620 KB Output is correct
41 Correct 53 ms 3784 KB Output is correct
42 Correct 66 ms 3672 KB Output is correct
43 Correct 51 ms 3816 KB Output is correct
44 Correct 50 ms 3784 KB Output is correct
45 Correct 35 ms 3732 KB Output is correct
46 Correct 38 ms 3664 KB Output is correct
47 Correct 41 ms 3604 KB Output is correct
48 Correct 37 ms 3660 KB Output is correct
49 Correct 37 ms 3744 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 38 ms 3712 KB Output is correct
52 Correct 536 ms 53760 KB Output is correct
53 Correct 559 ms 52560 KB Output is correct
54 Correct 521 ms 49020 KB Output is correct
55 Correct 487 ms 48580 KB Output is correct
56 Correct 536 ms 49996 KB Output is correct
57 Correct 185 ms 32176 KB Output is correct
58 Correct 151 ms 31936 KB Output is correct
59 Correct 181 ms 32144 KB Output is correct
60 Correct 187 ms 31800 KB Output is correct
61 Correct 177 ms 34176 KB Output is correct
62 Correct 340 ms 48512 KB Output is correct
63 Correct 375 ms 53416 KB Output is correct
64 Correct 317 ms 48328 KB Output is correct
65 Correct 356 ms 50172 KB Output is correct
66 Correct 386 ms 52936 KB Output is correct
67 Correct 0 ms 348 KB Output is correct
68 Correct 183 ms 32452 KB Output is correct
69 Correct 587 ms 52932 KB Output is correct
70 Correct 619 ms 55760 KB Output is correct
71 Correct 530 ms 52508 KB Output is correct
72 Correct 565 ms 55268 KB Output is correct
73 Correct 570 ms 54464 KB Output is correct
74 Correct 265 ms 38852 KB Output is correct
75 Correct 242 ms 36292 KB Output is correct
76 Correct 291 ms 39112 KB Output is correct
77 Correct 272 ms 35940 KB Output is correct
78 Correct 260 ms 36708 KB Output is correct
79 Correct 367 ms 56264 KB Output is correct
80 Correct 350 ms 51984 KB Output is correct
81 Correct 351 ms 51708 KB Output is correct
82 Correct 411 ms 54556 KB Output is correct
83 Correct 368 ms 52168 KB Output is correct
84 Correct 1 ms 344 KB Output is correct
85 Correct 235 ms 36264 KB Output is correct