Submission #675789

# Submission time Handle Problem Language Result Execution time Memory
675789 2022-12-27T22:27:02 Z Victor Osumnjičeni (COCI21_osumnjiceni) C++17
60 / 110
1000 ms 410548 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;

	//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);
    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;
}
# Verdict Execution time Memory Grader output
1 Correct 903 ms 391892 KB Output is correct
2 Correct 939 ms 390788 KB Output is correct
3 Correct 888 ms 391644 KB Output is correct
4 Correct 951 ms 395724 KB Output is correct
5 Correct 974 ms 410548 KB Output is correct
6 Correct 114 ms 18240 KB Output is correct
7 Correct 121 ms 18524 KB Output is correct
8 Correct 148 ms 18508 KB Output is correct
9 Correct 127 ms 19048 KB Output is correct
10 Correct 128 ms 18360 KB Output is correct
11 Correct 492 ms 212444 KB Output is correct
12 Correct 505 ms 199868 KB Output is correct
13 Correct 455 ms 199256 KB Output is correct
14 Correct 511 ms 212936 KB Output is correct
15 Correct 504 ms 206848 KB Output is correct
16 Correct 1 ms 1876 KB Output is correct
17 Correct 147 ms 19344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 16776 KB Output is correct
2 Correct 35 ms 16148 KB Output is correct
3 Correct 39 ms 16276 KB Output is correct
4 Correct 35 ms 16680 KB Output is correct
5 Correct 34 ms 15948 KB Output is correct
6 Correct 11 ms 2388 KB Output is correct
7 Correct 11 ms 2412 KB Output is correct
8 Correct 10 ms 2384 KB Output is correct
9 Correct 12 ms 2388 KB Output is correct
10 Correct 12 ms 2388 KB Output is correct
11 Correct 20 ms 7284 KB Output is correct
12 Correct 17 ms 7024 KB Output is correct
13 Correct 17 ms 7040 KB Output is correct
14 Correct 23 ms 7252 KB Output is correct
15 Correct 19 ms 7276 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 34 ms 16776 KB Output is correct
2 Correct 35 ms 16148 KB Output is correct
3 Correct 39 ms 16276 KB Output is correct
4 Correct 35 ms 16680 KB Output is correct
5 Correct 34 ms 15948 KB Output is correct
6 Correct 11 ms 2388 KB Output is correct
7 Correct 11 ms 2412 KB Output is correct
8 Correct 10 ms 2384 KB Output is correct
9 Correct 12 ms 2388 KB Output is correct
10 Correct 12 ms 2388 KB Output is correct
11 Correct 20 ms 7284 KB Output is correct
12 Correct 17 ms 7024 KB Output is correct
13 Correct 17 ms 7040 KB Output is correct
14 Correct 23 ms 7252 KB Output is correct
15 Correct 19 ms 7276 KB Output is correct
16 Correct 1 ms 1876 KB Output is correct
17 Correct 13 ms 2388 KB Output is correct
18 Correct 314 ms 19424 KB Output is correct
19 Correct 334 ms 18640 KB Output is correct
20 Correct 328 ms 19760 KB Output is correct
21 Correct 330 ms 18624 KB Output is correct
22 Correct 290 ms 18456 KB Output is correct
23 Correct 268 ms 4872 KB Output is correct
24 Correct 280 ms 4972 KB Output is correct
25 Correct 311 ms 5064 KB Output is correct
26 Correct 269 ms 4940 KB Output is correct
27 Correct 298 ms 4848 KB Output is correct
28 Correct 267 ms 9344 KB Output is correct
29 Correct 275 ms 9068 KB Output is correct
30 Correct 272 ms 9452 KB Output is correct
31 Correct 271 ms 8976 KB Output is correct
32 Correct 262 ms 9412 KB Output is correct
33 Correct 1 ms 1876 KB Output is correct
34 Correct 303 ms 4776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 954 ms 407188 KB Output is correct
2 Correct 937 ms 404108 KB Output is correct
3 Correct 868 ms 379856 KB Output is correct
4 Correct 861 ms 376572 KB Output is correct
5 Correct 881 ms 386908 KB Output is correct
6 Correct 125 ms 18308 KB Output is correct
7 Correct 122 ms 18164 KB Output is correct
8 Correct 126 ms 18236 KB Output is correct
9 Correct 134 ms 18176 KB Output is correct
10 Correct 132 ms 19448 KB Output is correct
11 Correct 460 ms 197936 KB Output is correct
12 Correct 509 ms 217020 KB Output is correct
13 Correct 462 ms 197932 KB Output is correct
14 Correct 474 ms 203976 KB Output is correct
15 Correct 511 ms 216028 KB Output is correct
16 Correct 1 ms 1876 KB Output is correct
17 Correct 128 ms 18496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 903 ms 391892 KB Output is correct
2 Correct 939 ms 390788 KB Output is correct
3 Correct 888 ms 391644 KB Output is correct
4 Correct 951 ms 395724 KB Output is correct
5 Correct 974 ms 410548 KB Output is correct
6 Correct 114 ms 18240 KB Output is correct
7 Correct 121 ms 18524 KB Output is correct
8 Correct 148 ms 18508 KB Output is correct
9 Correct 127 ms 19048 KB Output is correct
10 Correct 128 ms 18360 KB Output is correct
11 Correct 492 ms 212444 KB Output is correct
12 Correct 505 ms 199868 KB Output is correct
13 Correct 455 ms 199256 KB Output is correct
14 Correct 511 ms 212936 KB Output is correct
15 Correct 504 ms 206848 KB Output is correct
16 Correct 1 ms 1876 KB Output is correct
17 Correct 147 ms 19344 KB Output is correct
18 Correct 34 ms 16776 KB Output is correct
19 Correct 35 ms 16148 KB Output is correct
20 Correct 39 ms 16276 KB Output is correct
21 Correct 35 ms 16680 KB Output is correct
22 Correct 34 ms 15948 KB Output is correct
23 Correct 11 ms 2388 KB Output is correct
24 Correct 11 ms 2412 KB Output is correct
25 Correct 10 ms 2384 KB Output is correct
26 Correct 12 ms 2388 KB Output is correct
27 Correct 12 ms 2388 KB Output is correct
28 Correct 20 ms 7284 KB Output is correct
29 Correct 17 ms 7024 KB Output is correct
30 Correct 17 ms 7040 KB Output is correct
31 Correct 23 ms 7252 KB Output is correct
32 Correct 19 ms 7276 KB Output is correct
33 Correct 1 ms 1876 KB Output is correct
34 Correct 13 ms 2388 KB Output is correct
35 Correct 314 ms 19424 KB Output is correct
36 Correct 334 ms 18640 KB Output is correct
37 Correct 328 ms 19760 KB Output is correct
38 Correct 330 ms 18624 KB Output is correct
39 Correct 290 ms 18456 KB Output is correct
40 Correct 268 ms 4872 KB Output is correct
41 Correct 280 ms 4972 KB Output is correct
42 Correct 311 ms 5064 KB Output is correct
43 Correct 269 ms 4940 KB Output is correct
44 Correct 298 ms 4848 KB Output is correct
45 Correct 267 ms 9344 KB Output is correct
46 Correct 275 ms 9068 KB Output is correct
47 Correct 272 ms 9452 KB Output is correct
48 Correct 271 ms 8976 KB Output is correct
49 Correct 262 ms 9412 KB Output is correct
50 Correct 1 ms 1876 KB Output is correct
51 Correct 303 ms 4776 KB Output is correct
52 Correct 954 ms 407188 KB Output is correct
53 Correct 937 ms 404108 KB Output is correct
54 Correct 868 ms 379856 KB Output is correct
55 Correct 861 ms 376572 KB Output is correct
56 Correct 881 ms 386908 KB Output is correct
57 Correct 125 ms 18308 KB Output is correct
58 Correct 122 ms 18164 KB Output is correct
59 Correct 126 ms 18236 KB Output is correct
60 Correct 134 ms 18176 KB Output is correct
61 Correct 132 ms 19448 KB Output is correct
62 Correct 460 ms 197936 KB Output is correct
63 Correct 509 ms 217020 KB Output is correct
64 Correct 462 ms 197932 KB Output is correct
65 Correct 474 ms 203976 KB Output is correct
66 Correct 511 ms 216028 KB Output is correct
67 Correct 1 ms 1876 KB Output is correct
68 Correct 128 ms 18496 KB Output is correct
69 Execution timed out 1077 ms 388148 KB Time limit exceeded
70 Halted 0 ms 0 KB -