Submission #1098648

# Submission time Handle Problem Language Result Execution time Memory
1098648 2024-10-09T16:20:36 Z flyingkite Osumnjičeni (COCI21_osumnjiceni) C++17
60 / 110
1000 ms 93756 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 744 ms 87832 KB Output is correct
2 Correct 750 ms 86420 KB Output is correct
3 Correct 737 ms 86756 KB Output is correct
4 Correct 814 ms 87740 KB Output is correct
5 Correct 770 ms 91840 KB Output is correct
6 Correct 229 ms 60608 KB Output is correct
7 Correct 202 ms 61932 KB Output is correct
8 Correct 183 ms 62428 KB Output is correct
9 Correct 195 ms 63800 KB Output is correct
10 Correct 206 ms 61692 KB Output is correct
11 Correct 496 ms 89264 KB Output is correct
12 Correct 424 ms 83824 KB Output is correct
13 Correct 475 ms 83704 KB Output is correct
14 Correct 635 ms 89416 KB Output is correct
15 Correct 581 ms 86904 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 224 ms 64792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 2652 KB Output is correct
2 Correct 15 ms 2648 KB Output is correct
3 Correct 10 ms 2652 KB Output is correct
4 Correct 11 ms 2760 KB Output is correct
5 Correct 9 ms 2396 KB Output is correct
6 Correct 7 ms 2188 KB Output is correct
7 Correct 6 ms 2136 KB Output is correct
8 Correct 8 ms 2164 KB Output is correct
9 Correct 6 ms 2156 KB Output is correct
10 Correct 8 ms 2140 KB Output is correct
11 Correct 8 ms 2652 KB Output is correct
12 Correct 11 ms 2652 KB Output is correct
13 Correct 7 ms 2648 KB Output is correct
14 Correct 8 ms 2648 KB Output is correct
15 Correct 12 ms 2904 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 5 ms 2256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 2652 KB Output is correct
2 Correct 15 ms 2648 KB Output is correct
3 Correct 10 ms 2652 KB Output is correct
4 Correct 11 ms 2760 KB Output is correct
5 Correct 9 ms 2396 KB Output is correct
6 Correct 7 ms 2188 KB Output is correct
7 Correct 6 ms 2136 KB Output is correct
8 Correct 8 ms 2164 KB Output is correct
9 Correct 6 ms 2156 KB Output is correct
10 Correct 8 ms 2140 KB Output is correct
11 Correct 8 ms 2652 KB Output is correct
12 Correct 11 ms 2652 KB Output is correct
13 Correct 7 ms 2648 KB Output is correct
14 Correct 8 ms 2648 KB Output is correct
15 Correct 12 ms 2904 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 5 ms 2256 KB Output is correct
18 Correct 66 ms 5212 KB Output is correct
19 Correct 66 ms 4852 KB Output is correct
20 Correct 63 ms 5396 KB Output is correct
21 Correct 55 ms 4948 KB Output is correct
22 Correct 59 ms 4948 KB Output is correct
23 Correct 52 ms 4628 KB Output is correct
24 Correct 53 ms 4692 KB Output is correct
25 Correct 52 ms 4816 KB Output is correct
26 Correct 65 ms 4724 KB Output is correct
27 Correct 48 ms 4468 KB Output is correct
28 Correct 55 ms 4688 KB Output is correct
29 Correct 35 ms 4708 KB Output is correct
30 Correct 35 ms 4708 KB Output is correct
31 Correct 36 ms 4692 KB Output is correct
32 Correct 37 ms 4688 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 52 ms 4336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 785 ms 91744 KB Output is correct
2 Correct 783 ms 89836 KB Output is correct
3 Correct 635 ms 83724 KB Output is correct
4 Correct 700 ms 82876 KB Output is correct
5 Correct 724 ms 85568 KB Output is correct
6 Correct 195 ms 61100 KB Output is correct
7 Correct 177 ms 60604 KB Output is correct
8 Correct 177 ms 61108 KB Output is correct
9 Correct 180 ms 60624 KB Output is correct
10 Correct 179 ms 65532 KB Output is correct
11 Correct 440 ms 82964 KB Output is correct
12 Correct 477 ms 91072 KB Output is correct
13 Correct 453 ms 83108 KB Output is correct
14 Correct 498 ms 85436 KB Output is correct
15 Correct 648 ms 90560 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 199 ms 62316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 744 ms 87832 KB Output is correct
2 Correct 750 ms 86420 KB Output is correct
3 Correct 737 ms 86756 KB Output is correct
4 Correct 814 ms 87740 KB Output is correct
5 Correct 770 ms 91840 KB Output is correct
6 Correct 229 ms 60608 KB Output is correct
7 Correct 202 ms 61932 KB Output is correct
8 Correct 183 ms 62428 KB Output is correct
9 Correct 195 ms 63800 KB Output is correct
10 Correct 206 ms 61692 KB Output is correct
11 Correct 496 ms 89264 KB Output is correct
12 Correct 424 ms 83824 KB Output is correct
13 Correct 475 ms 83704 KB Output is correct
14 Correct 635 ms 89416 KB Output is correct
15 Correct 581 ms 86904 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 224 ms 64792 KB Output is correct
18 Correct 12 ms 2652 KB Output is correct
19 Correct 15 ms 2648 KB Output is correct
20 Correct 10 ms 2652 KB Output is correct
21 Correct 11 ms 2760 KB Output is correct
22 Correct 9 ms 2396 KB Output is correct
23 Correct 7 ms 2188 KB Output is correct
24 Correct 6 ms 2136 KB Output is correct
25 Correct 8 ms 2164 KB Output is correct
26 Correct 6 ms 2156 KB Output is correct
27 Correct 8 ms 2140 KB Output is correct
28 Correct 8 ms 2652 KB Output is correct
29 Correct 11 ms 2652 KB Output is correct
30 Correct 7 ms 2648 KB Output is correct
31 Correct 8 ms 2648 KB Output is correct
32 Correct 12 ms 2904 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 5 ms 2256 KB Output is correct
35 Correct 66 ms 5212 KB Output is correct
36 Correct 66 ms 4852 KB Output is correct
37 Correct 63 ms 5396 KB Output is correct
38 Correct 55 ms 4948 KB Output is correct
39 Correct 59 ms 4948 KB Output is correct
40 Correct 52 ms 4628 KB Output is correct
41 Correct 53 ms 4692 KB Output is correct
42 Correct 52 ms 4816 KB Output is correct
43 Correct 65 ms 4724 KB Output is correct
44 Correct 48 ms 4468 KB Output is correct
45 Correct 55 ms 4688 KB Output is correct
46 Correct 35 ms 4708 KB Output is correct
47 Correct 35 ms 4708 KB Output is correct
48 Correct 36 ms 4692 KB Output is correct
49 Correct 37 ms 4688 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 52 ms 4336 KB Output is correct
52 Correct 785 ms 91744 KB Output is correct
53 Correct 783 ms 89836 KB Output is correct
54 Correct 635 ms 83724 KB Output is correct
55 Correct 700 ms 82876 KB Output is correct
56 Correct 724 ms 85568 KB Output is correct
57 Correct 195 ms 61100 KB Output is correct
58 Correct 177 ms 60604 KB Output is correct
59 Correct 177 ms 61108 KB Output is correct
60 Correct 180 ms 60624 KB Output is correct
61 Correct 179 ms 65532 KB Output is correct
62 Correct 440 ms 82964 KB Output is correct
63 Correct 477 ms 91072 KB Output is correct
64 Correct 453 ms 83108 KB Output is correct
65 Correct 498 ms 85436 KB Output is correct
66 Correct 648 ms 90560 KB Output is correct
67 Correct 0 ms 348 KB Output is correct
68 Correct 199 ms 62316 KB Output is correct
69 Correct 985 ms 88924 KB Output is correct
70 Execution timed out 1006 ms 93756 KB Time limit exceeded
71 Halted 0 ms 0 KB -