Submission #675781

# Submission time Handle Problem Language Result Execution time Memory
675781 2022-12-27T22:14:22 Z Victor Osumnjičeni (COCI21_osumnjiceni) C++17
60 / 110
1000 ms 410516 KB
// #pragma GCC target ("avx,avx2,fma")
// #pragma GCC optimize ("Ofast,inline") // O1 - O2 - O3 - Os - Ofast
// #pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define trav(a, x) for (auto &a : x)

#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pb push_back
#define debug(x) cout<<#x<<" = "<<x<<endl

#define umap unordered_map
#define uset unordered_set

typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;

const int INF = 1'000'000'007;

const int inf = 1e9;
struct Node {
	Node *l = 0, *r = 0;
	int lo, hi, mset = inf, madd = 0, val = inf;
	Node(int lo,int hi):lo(lo),hi(hi){} // Large interval of -inf
	Node(vi& v, int lo, int hi) : lo(lo), hi(hi) {
		if (lo + 1 < hi) {
			int mid = lo + (hi - lo)/2;
			l = new Node(v, lo, mid); r = new Node(v, mid, hi);
			val = min(l->val, r->val);
		}
		else val = v[lo];
	}
	int query(int L, int R) {
		if (R <= lo || hi <= L) return inf;
		if (L <= lo && hi <= R) return val;
		push();
		return min(l->query(L, R), r->query(L, R));
	}
	void set(int L, int R, int x) {
		if (R <= lo || hi <= L) return;
		if (L <= lo && hi <= R) mset = val = x, madd = 0;
		else {
			push(), l->set(L, R, x), r->set(L, R, x);
			val = min(l->val, r->val);
		}
	}
	void add(int L, int R, int x) {
		if (R <= lo || hi <= L) return;
		if (L <= lo && hi <= R) {
			if (mset != inf) mset += x;
			else madd += x;
			val += x;
		}
		else {
			push(), l->add(L, R, x), r->add(L, R, x);
			val = min(l->val, r->val);
		}
	}
	void push() {
		if (!l) {
			int mid = lo + (hi - lo)/2;
			l = new Node(lo, mid); r = new Node(mid, hi);
		}
		if (mset != inf)
			l->set(lo,hi,mset), r->set(lo,hi,mset), mset = inf;
		else if (madd)
			l->add(lo,hi,madd), r->add(lo,hi,madd), madd = 0;
	}
};

int jmp[18][200005];

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);

    int n,q;
    int heights[200005][2];
    cin>>n;
    rep(i,0,n) rep(j,0,2) cin>>heights[i][j];

    Node segtree(0,INF);
    int min_val=INF;
    per(i,0,n) {
        jmp[0][i]=segtree.query(heights[i][0],heights[i][1]+1);
        jmp[0][i]=min(jmp[0][i],min_val);
        min_val=jmp[0][i];
        //debug(jmp[0][i])<<endl;
        segtree.set(heights[i][0],heights[i][1]+1,i);
    }

    rep(j,1,18) rep(i,0,n) {
        if(jmp[j-1][i]>=inf) jmp[j][i]=inf;
        else jmp[j][i]=jmp[j-1][jmp[j-1][i]];
    }

    cin>>q;
    while(q--) {
        int lo,hi;
        cin>>lo>>hi;
        --lo;
        int cnt=1;
        //cout<<"lo = "<<lo<<" hi = "<<hi<<endl;
        per(j,0,18) {
            //cout<<"j = "<<j<<" lo = "<<lo<<" jmp = "<<jmp[j][lo]<<endl;
            if(jmp[j][lo]<hi) {
                cnt+=1<<j;
                lo=jmp[j][lo];
            }
        }
        cout<<cnt<<endl;
    }
    _Exit(0);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 977 ms 391920 KB Output is correct
2 Correct 875 ms 390724 KB Output is correct
3 Correct 848 ms 391704 KB Output is correct
4 Correct 843 ms 395656 KB Output is correct
5 Correct 887 ms 410516 KB Output is correct
6 Correct 107 ms 18252 KB Output is correct
7 Correct 114 ms 18500 KB Output is correct
8 Correct 121 ms 18652 KB Output is correct
9 Correct 122 ms 19008 KB Output is correct
10 Correct 122 ms 18364 KB Output is correct
11 Correct 459 ms 212528 KB Output is correct
12 Correct 443 ms 199848 KB Output is correct
13 Correct 458 ms 199292 KB Output is correct
14 Correct 482 ms 212936 KB Output is correct
15 Correct 488 ms 206804 KB Output is correct
16 Correct 1 ms 1876 KB Output is correct
17 Correct 122 ms 19272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 16796 KB Output is correct
2 Correct 31 ms 16044 KB Output is correct
3 Correct 31 ms 16204 KB Output is correct
4 Correct 39 ms 16768 KB Output is correct
5 Correct 31 ms 15948 KB Output is correct
6 Correct 12 ms 2492 KB Output is correct
7 Correct 15 ms 2476 KB Output is correct
8 Correct 15 ms 2548 KB Output is correct
9 Correct 14 ms 2476 KB Output is correct
10 Correct 13 ms 2408 KB Output is correct
11 Correct 20 ms 7288 KB Output is correct
12 Correct 18 ms 7036 KB Output is correct
13 Correct 22 ms 6996 KB Output is correct
14 Correct 17 ms 7292 KB Output is correct
15 Correct 18 ms 7268 KB Output is correct
16 Correct 1 ms 1876 KB Output is correct
17 Correct 13 ms 2388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 16796 KB Output is correct
2 Correct 31 ms 16044 KB Output is correct
3 Correct 31 ms 16204 KB Output is correct
4 Correct 39 ms 16768 KB Output is correct
5 Correct 31 ms 15948 KB Output is correct
6 Correct 12 ms 2492 KB Output is correct
7 Correct 15 ms 2476 KB Output is correct
8 Correct 15 ms 2548 KB Output is correct
9 Correct 14 ms 2476 KB Output is correct
10 Correct 13 ms 2408 KB Output is correct
11 Correct 20 ms 7288 KB Output is correct
12 Correct 18 ms 7036 KB Output is correct
13 Correct 22 ms 6996 KB Output is correct
14 Correct 17 ms 7292 KB Output is correct
15 Correct 18 ms 7268 KB Output is correct
16 Correct 1 ms 1876 KB Output is correct
17 Correct 13 ms 2388 KB Output is correct
18 Correct 338 ms 19428 KB Output is correct
19 Correct 308 ms 18672 KB Output is correct
20 Correct 338 ms 19796 KB Output is correct
21 Correct 316 ms 18696 KB Output is correct
22 Correct 312 ms 18384 KB Output is correct
23 Correct 278 ms 4832 KB Output is correct
24 Correct 320 ms 4936 KB Output is correct
25 Correct 313 ms 5080 KB Output is correct
26 Correct 302 ms 5008 KB Output is correct
27 Correct 264 ms 4856 KB Output is correct
28 Correct 252 ms 9048 KB Output is correct
29 Correct 273 ms 9164 KB Output is correct
30 Correct 306 ms 9140 KB Output is correct
31 Correct 258 ms 9036 KB Output is correct
32 Correct 255 ms 9484 KB Output is correct
33 Correct 1 ms 1876 KB Output is correct
34 Correct 273 ms 4812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 925 ms 407352 KB Output is correct
2 Correct 916 ms 404108 KB Output is correct
3 Correct 897 ms 379888 KB Output is correct
4 Correct 867 ms 376584 KB Output is correct
5 Correct 930 ms 386820 KB Output is correct
6 Correct 140 ms 18356 KB Output is correct
7 Correct 138 ms 18104 KB Output is correct
8 Correct 129 ms 18364 KB Output is correct
9 Correct 122 ms 18128 KB Output is correct
10 Correct 127 ms 19404 KB Output is correct
11 Correct 445 ms 197996 KB Output is correct
12 Correct 586 ms 216964 KB Output is correct
13 Correct 449 ms 197892 KB Output is correct
14 Correct 492 ms 204064 KB Output is correct
15 Correct 493 ms 216004 KB Output is correct
16 Correct 1 ms 1876 KB Output is correct
17 Correct 137 ms 18496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 977 ms 391920 KB Output is correct
2 Correct 875 ms 390724 KB Output is correct
3 Correct 848 ms 391704 KB Output is correct
4 Correct 843 ms 395656 KB Output is correct
5 Correct 887 ms 410516 KB Output is correct
6 Correct 107 ms 18252 KB Output is correct
7 Correct 114 ms 18500 KB Output is correct
8 Correct 121 ms 18652 KB Output is correct
9 Correct 122 ms 19008 KB Output is correct
10 Correct 122 ms 18364 KB Output is correct
11 Correct 459 ms 212528 KB Output is correct
12 Correct 443 ms 199848 KB Output is correct
13 Correct 458 ms 199292 KB Output is correct
14 Correct 482 ms 212936 KB Output is correct
15 Correct 488 ms 206804 KB Output is correct
16 Correct 1 ms 1876 KB Output is correct
17 Correct 122 ms 19272 KB Output is correct
18 Correct 32 ms 16796 KB Output is correct
19 Correct 31 ms 16044 KB Output is correct
20 Correct 31 ms 16204 KB Output is correct
21 Correct 39 ms 16768 KB Output is correct
22 Correct 31 ms 15948 KB Output is correct
23 Correct 12 ms 2492 KB Output is correct
24 Correct 15 ms 2476 KB Output is correct
25 Correct 15 ms 2548 KB Output is correct
26 Correct 14 ms 2476 KB Output is correct
27 Correct 13 ms 2408 KB Output is correct
28 Correct 20 ms 7288 KB Output is correct
29 Correct 18 ms 7036 KB Output is correct
30 Correct 22 ms 6996 KB Output is correct
31 Correct 17 ms 7292 KB Output is correct
32 Correct 18 ms 7268 KB Output is correct
33 Correct 1 ms 1876 KB Output is correct
34 Correct 13 ms 2388 KB Output is correct
35 Correct 338 ms 19428 KB Output is correct
36 Correct 308 ms 18672 KB Output is correct
37 Correct 338 ms 19796 KB Output is correct
38 Correct 316 ms 18696 KB Output is correct
39 Correct 312 ms 18384 KB Output is correct
40 Correct 278 ms 4832 KB Output is correct
41 Correct 320 ms 4936 KB Output is correct
42 Correct 313 ms 5080 KB Output is correct
43 Correct 302 ms 5008 KB Output is correct
44 Correct 264 ms 4856 KB Output is correct
45 Correct 252 ms 9048 KB Output is correct
46 Correct 273 ms 9164 KB Output is correct
47 Correct 306 ms 9140 KB Output is correct
48 Correct 258 ms 9036 KB Output is correct
49 Correct 255 ms 9484 KB Output is correct
50 Correct 1 ms 1876 KB Output is correct
51 Correct 273 ms 4812 KB Output is correct
52 Correct 925 ms 407352 KB Output is correct
53 Correct 916 ms 404108 KB Output is correct
54 Correct 897 ms 379888 KB Output is correct
55 Correct 867 ms 376584 KB Output is correct
56 Correct 930 ms 386820 KB Output is correct
57 Correct 140 ms 18356 KB Output is correct
58 Correct 138 ms 18104 KB Output is correct
59 Correct 129 ms 18364 KB Output is correct
60 Correct 122 ms 18128 KB Output is correct
61 Correct 127 ms 19404 KB Output is correct
62 Correct 445 ms 197996 KB Output is correct
63 Correct 586 ms 216964 KB Output is correct
64 Correct 449 ms 197892 KB Output is correct
65 Correct 492 ms 204064 KB Output is correct
66 Correct 493 ms 216004 KB Output is correct
67 Correct 1 ms 1876 KB Output is correct
68 Correct 137 ms 18496 KB Output is correct
69 Execution timed out 1095 ms 387760 KB Time limit exceeded
70 Halted 0 ms 0 KB -