Submission #675794

# Submission time Handle Problem Language Result Execution time Memory
675794 2022-12-27T22:41:17 Z Victor Osumnjičeni (COCI21_osumnjiceni) C++17
60 / 110
1000 ms 409556 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, 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;
		else {
			push(), l->set(L, R, x), r->set(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;
	}
};

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;

	//set<int> unique_heights;
    rep(i,0,n) rep(j,0,2) cin>>heights[i][j];//,unique_heights.insert(heights[i][j]);
	//umap<int,int> compress;
	//int cnt=0;
	//trav(height,unique_heights) compress[height]=cnt++;
	//rep(i,0,n) rep(j,0,2) heights[i][j]=compress[heights[i][j]];
	

    Node segtree(0,INF);
	int min_val=n;
    per(i,0,n) {
        jmp[0][i]=segtree.query(heights[i][0],heights[i][1]+1);
        if(i+1!=n) jmp[0][i]=min(jmp[0][i],jmp[0][i+1]);
        //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;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:90:6: warning: unused variable 'min_val' [-Wunused-variable]
   90 |  int min_val=n;
      |      ^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 840 ms 391928 KB Output is correct
2 Correct 850 ms 389940 KB Output is correct
3 Correct 845 ms 390884 KB Output is correct
4 Correct 868 ms 394776 KB Output is correct
5 Correct 886 ms 409556 KB Output is correct
6 Correct 91 ms 17320 KB Output is correct
7 Correct 97 ms 17548 KB Output is correct
8 Correct 97 ms 17752 KB Output is correct
9 Correct 99 ms 18004 KB Output is correct
10 Correct 100 ms 17532 KB Output is correct
11 Correct 546 ms 212012 KB Output is correct
12 Correct 431 ms 199424 KB Output is correct
13 Correct 423 ms 199020 KB Output is correct
14 Correct 481 ms 212588 KB Output is correct
15 Correct 454 ms 206300 KB Output is correct
16 Correct 1 ms 1876 KB Output is correct
17 Correct 103 ms 18232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 16816 KB Output is correct
2 Correct 29 ms 16072 KB Output is correct
3 Correct 30 ms 16284 KB Output is correct
4 Correct 30 ms 16792 KB Output is correct
5 Correct 30 ms 15992 KB Output is correct
6 Correct 10 ms 2432 KB Output is correct
7 Correct 11 ms 2408 KB Output is correct
8 Correct 11 ms 2388 KB Output is correct
9 Correct 13 ms 2388 KB Output is correct
10 Correct 10 ms 2388 KB Output is correct
11 Correct 19 ms 7252 KB Output is correct
12 Correct 19 ms 6996 KB Output is correct
13 Correct 16 ms 7000 KB Output is correct
14 Correct 18 ms 7300 KB Output is correct
15 Correct 17 ms 7380 KB Output is correct
16 Correct 1 ms 1876 KB Output is correct
17 Correct 10 ms 2464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 16816 KB Output is correct
2 Correct 29 ms 16072 KB Output is correct
3 Correct 30 ms 16284 KB Output is correct
4 Correct 30 ms 16792 KB Output is correct
5 Correct 30 ms 15992 KB Output is correct
6 Correct 10 ms 2432 KB Output is correct
7 Correct 11 ms 2408 KB Output is correct
8 Correct 11 ms 2388 KB Output is correct
9 Correct 13 ms 2388 KB Output is correct
10 Correct 10 ms 2388 KB Output is correct
11 Correct 19 ms 7252 KB Output is correct
12 Correct 19 ms 6996 KB Output is correct
13 Correct 16 ms 7000 KB Output is correct
14 Correct 18 ms 7300 KB Output is correct
15 Correct 17 ms 7380 KB Output is correct
16 Correct 1 ms 1876 KB Output is correct
17 Correct 10 ms 2464 KB Output is correct
18 Correct 303 ms 19468 KB Output is correct
19 Correct 284 ms 18680 KB Output is correct
20 Correct 311 ms 19852 KB Output is correct
21 Correct 306 ms 18608 KB Output is correct
22 Correct 333 ms 18624 KB Output is correct
23 Correct 274 ms 4940 KB Output is correct
24 Correct 281 ms 5068 KB Output is correct
25 Correct 281 ms 5048 KB Output is correct
26 Correct 290 ms 5004 KB Output is correct
27 Correct 259 ms 5188 KB Output is correct
28 Correct 256 ms 9056 KB Output is correct
29 Correct 269 ms 9164 KB Output is correct
30 Correct 265 ms 9152 KB Output is correct
31 Correct 261 ms 9172 KB Output is correct
32 Correct 254 ms 9420 KB Output is correct
33 Correct 1 ms 1876 KB Output is correct
34 Correct 263 ms 4684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 882 ms 407372 KB Output is correct
2 Correct 894 ms 403048 KB Output is correct
3 Correct 855 ms 378948 KB Output is correct
4 Correct 816 ms 375860 KB Output is correct
5 Correct 869 ms 386072 KB Output is correct
6 Correct 97 ms 17592 KB Output is correct
7 Correct 97 ms 17364 KB Output is correct
8 Correct 97 ms 17436 KB Output is correct
9 Correct 108 ms 17256 KB Output is correct
10 Correct 106 ms 18348 KB Output is correct
11 Correct 424 ms 197704 KB Output is correct
12 Correct 499 ms 216368 KB Output is correct
13 Correct 439 ms 197580 KB Output is correct
14 Correct 509 ms 203636 KB Output is correct
15 Correct 621 ms 215404 KB Output is correct
16 Correct 2 ms 1876 KB Output is correct
17 Correct 158 ms 17672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 840 ms 391928 KB Output is correct
2 Correct 850 ms 389940 KB Output is correct
3 Correct 845 ms 390884 KB Output is correct
4 Correct 868 ms 394776 KB Output is correct
5 Correct 886 ms 409556 KB Output is correct
6 Correct 91 ms 17320 KB Output is correct
7 Correct 97 ms 17548 KB Output is correct
8 Correct 97 ms 17752 KB Output is correct
9 Correct 99 ms 18004 KB Output is correct
10 Correct 100 ms 17532 KB Output is correct
11 Correct 546 ms 212012 KB Output is correct
12 Correct 431 ms 199424 KB Output is correct
13 Correct 423 ms 199020 KB Output is correct
14 Correct 481 ms 212588 KB Output is correct
15 Correct 454 ms 206300 KB Output is correct
16 Correct 1 ms 1876 KB Output is correct
17 Correct 103 ms 18232 KB Output is correct
18 Correct 32 ms 16816 KB Output is correct
19 Correct 29 ms 16072 KB Output is correct
20 Correct 30 ms 16284 KB Output is correct
21 Correct 30 ms 16792 KB Output is correct
22 Correct 30 ms 15992 KB Output is correct
23 Correct 10 ms 2432 KB Output is correct
24 Correct 11 ms 2408 KB Output is correct
25 Correct 11 ms 2388 KB Output is correct
26 Correct 13 ms 2388 KB Output is correct
27 Correct 10 ms 2388 KB Output is correct
28 Correct 19 ms 7252 KB Output is correct
29 Correct 19 ms 6996 KB Output is correct
30 Correct 16 ms 7000 KB Output is correct
31 Correct 18 ms 7300 KB Output is correct
32 Correct 17 ms 7380 KB Output is correct
33 Correct 1 ms 1876 KB Output is correct
34 Correct 10 ms 2464 KB Output is correct
35 Correct 303 ms 19468 KB Output is correct
36 Correct 284 ms 18680 KB Output is correct
37 Correct 311 ms 19852 KB Output is correct
38 Correct 306 ms 18608 KB Output is correct
39 Correct 333 ms 18624 KB Output is correct
40 Correct 274 ms 4940 KB Output is correct
41 Correct 281 ms 5068 KB Output is correct
42 Correct 281 ms 5048 KB Output is correct
43 Correct 290 ms 5004 KB Output is correct
44 Correct 259 ms 5188 KB Output is correct
45 Correct 256 ms 9056 KB Output is correct
46 Correct 269 ms 9164 KB Output is correct
47 Correct 265 ms 9152 KB Output is correct
48 Correct 261 ms 9172 KB Output is correct
49 Correct 254 ms 9420 KB Output is correct
50 Correct 1 ms 1876 KB Output is correct
51 Correct 263 ms 4684 KB Output is correct
52 Correct 882 ms 407372 KB Output is correct
53 Correct 894 ms 403048 KB Output is correct
54 Correct 855 ms 378948 KB Output is correct
55 Correct 816 ms 375860 KB Output is correct
56 Correct 869 ms 386072 KB Output is correct
57 Correct 97 ms 17592 KB Output is correct
58 Correct 97 ms 17364 KB Output is correct
59 Correct 97 ms 17436 KB Output is correct
60 Correct 108 ms 17256 KB Output is correct
61 Correct 106 ms 18348 KB Output is correct
62 Correct 424 ms 197704 KB Output is correct
63 Correct 499 ms 216368 KB Output is correct
64 Correct 439 ms 197580 KB Output is correct
65 Correct 509 ms 203636 KB Output is correct
66 Correct 621 ms 215404 KB Output is correct
67 Correct 2 ms 1876 KB Output is correct
68 Correct 158 ms 17672 KB Output is correct
69 Execution timed out 1117 ms 386696 KB Time limit exceeded
70 Halted 0 ms 0 KB -