답안 #675796

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
675796 2022-12-27T22:44:40 Z Victor Osumnjičeni (COCI21_osumnjiceni) C++17
60 / 110
1000 ms 407348 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;

int pos_update;
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(const int &L, const int &R) {
		if (R <= lo || hi <= L) return inf;
		if (L <= lo && hi <= R) {
			int prev_val=val;
			val=mset=pos_update;
			return prev_val;
		}
		push();
		val=pos_update;
		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) {
		pos_update=i;
        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:97:6: warning: unused variable 'min_val' [-Wunused-variable]
   97 |  int min_val=n;
      |      ^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 685 ms 391960 KB Output is correct
2 Correct 652 ms 387216 KB Output is correct
3 Correct 684 ms 388012 KB Output is correct
4 Correct 698 ms 392040 KB Output is correct
5 Correct 752 ms 406720 KB Output is correct
6 Correct 67 ms 14668 KB Output is correct
7 Correct 75 ms 14876 KB Output is correct
8 Correct 76 ms 15068 KB Output is correct
9 Correct 80 ms 15272 KB Output is correct
10 Correct 79 ms 14936 KB Output is correct
11 Correct 405 ms 209232 KB Output is correct
12 Correct 353 ms 196808 KB Output is correct
13 Correct 412 ms 196432 KB Output is correct
14 Correct 398 ms 209728 KB Output is correct
15 Correct 369 ms 203784 KB Output is correct
16 Correct 1 ms 1876 KB Output is correct
17 Correct 77 ms 15552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 16816 KB Output is correct
2 Correct 31 ms 15996 KB Output is correct
3 Correct 24 ms 16084 KB Output is correct
4 Correct 26 ms 16580 KB Output is correct
5 Correct 24 ms 15828 KB Output is correct
6 Correct 10 ms 2352 KB Output is correct
7 Correct 10 ms 2260 KB Output is correct
8 Correct 9 ms 2260 KB Output is correct
9 Correct 10 ms 2260 KB Output is correct
10 Correct 10 ms 2348 KB Output is correct
11 Correct 14 ms 7216 KB Output is correct
12 Correct 14 ms 6928 KB Output is correct
13 Correct 15 ms 6996 KB Output is correct
14 Correct 15 ms 7084 KB Output is correct
15 Correct 16 ms 7288 KB Output is correct
16 Correct 1 ms 1876 KB Output is correct
17 Correct 11 ms 2352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 16816 KB Output is correct
2 Correct 31 ms 15996 KB Output is correct
3 Correct 24 ms 16084 KB Output is correct
4 Correct 26 ms 16580 KB Output is correct
5 Correct 24 ms 15828 KB Output is correct
6 Correct 10 ms 2352 KB Output is correct
7 Correct 10 ms 2260 KB Output is correct
8 Correct 9 ms 2260 KB Output is correct
9 Correct 10 ms 2260 KB Output is correct
10 Correct 10 ms 2348 KB Output is correct
11 Correct 14 ms 7216 KB Output is correct
12 Correct 14 ms 6928 KB Output is correct
13 Correct 15 ms 6996 KB Output is correct
14 Correct 15 ms 7084 KB Output is correct
15 Correct 16 ms 7288 KB Output is correct
16 Correct 1 ms 1876 KB Output is correct
17 Correct 11 ms 2352 KB Output is correct
18 Correct 295 ms 17380 KB Output is correct
19 Correct 280 ms 16892 KB Output is correct
20 Correct 295 ms 17752 KB Output is correct
21 Correct 296 ms 16908 KB Output is correct
22 Correct 288 ms 16556 KB Output is correct
23 Correct 268 ms 3148 KB Output is correct
24 Correct 301 ms 3108 KB Output is correct
25 Correct 280 ms 3072 KB Output is correct
26 Correct 273 ms 3140 KB Output is correct
27 Correct 263 ms 3044 KB Output is correct
28 Correct 253 ms 7284 KB Output is correct
29 Correct 267 ms 7244 KB Output is correct
30 Correct 275 ms 7208 KB Output is correct
31 Correct 258 ms 7372 KB Output is correct
32 Correct 260 ms 7536 KB Output is correct
33 Correct 1 ms 1876 KB Output is correct
34 Correct 263 ms 3276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 727 ms 407348 KB Output is correct
2 Correct 693 ms 400336 KB Output is correct
3 Correct 669 ms 376360 KB Output is correct
4 Correct 644 ms 373096 KB Output is correct
5 Correct 682 ms 383308 KB Output is correct
6 Correct 74 ms 14792 KB Output is correct
7 Correct 72 ms 14588 KB Output is correct
8 Correct 77 ms 14744 KB Output is correct
9 Correct 81 ms 14592 KB Output is correct
10 Correct 84 ms 15704 KB Output is correct
11 Correct 379 ms 195052 KB Output is correct
12 Correct 401 ms 213644 KB Output is correct
13 Correct 343 ms 195028 KB Output is correct
14 Correct 387 ms 200992 KB Output is correct
15 Correct 388 ms 212720 KB Output is correct
16 Correct 1 ms 1876 KB Output is correct
17 Correct 94 ms 14872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 685 ms 391960 KB Output is correct
2 Correct 652 ms 387216 KB Output is correct
3 Correct 684 ms 388012 KB Output is correct
4 Correct 698 ms 392040 KB Output is correct
5 Correct 752 ms 406720 KB Output is correct
6 Correct 67 ms 14668 KB Output is correct
7 Correct 75 ms 14876 KB Output is correct
8 Correct 76 ms 15068 KB Output is correct
9 Correct 80 ms 15272 KB Output is correct
10 Correct 79 ms 14936 KB Output is correct
11 Correct 405 ms 209232 KB Output is correct
12 Correct 353 ms 196808 KB Output is correct
13 Correct 412 ms 196432 KB Output is correct
14 Correct 398 ms 209728 KB Output is correct
15 Correct 369 ms 203784 KB Output is correct
16 Correct 1 ms 1876 KB Output is correct
17 Correct 77 ms 15552 KB Output is correct
18 Correct 27 ms 16816 KB Output is correct
19 Correct 31 ms 15996 KB Output is correct
20 Correct 24 ms 16084 KB Output is correct
21 Correct 26 ms 16580 KB Output is correct
22 Correct 24 ms 15828 KB Output is correct
23 Correct 10 ms 2352 KB Output is correct
24 Correct 10 ms 2260 KB Output is correct
25 Correct 9 ms 2260 KB Output is correct
26 Correct 10 ms 2260 KB Output is correct
27 Correct 10 ms 2348 KB Output is correct
28 Correct 14 ms 7216 KB Output is correct
29 Correct 14 ms 6928 KB Output is correct
30 Correct 15 ms 6996 KB Output is correct
31 Correct 15 ms 7084 KB Output is correct
32 Correct 16 ms 7288 KB Output is correct
33 Correct 1 ms 1876 KB Output is correct
34 Correct 11 ms 2352 KB Output is correct
35 Correct 295 ms 17380 KB Output is correct
36 Correct 280 ms 16892 KB Output is correct
37 Correct 295 ms 17752 KB Output is correct
38 Correct 296 ms 16908 KB Output is correct
39 Correct 288 ms 16556 KB Output is correct
40 Correct 268 ms 3148 KB Output is correct
41 Correct 301 ms 3108 KB Output is correct
42 Correct 280 ms 3072 KB Output is correct
43 Correct 273 ms 3140 KB Output is correct
44 Correct 263 ms 3044 KB Output is correct
45 Correct 253 ms 7284 KB Output is correct
46 Correct 267 ms 7244 KB Output is correct
47 Correct 275 ms 7208 KB Output is correct
48 Correct 258 ms 7372 KB Output is correct
49 Correct 260 ms 7536 KB Output is correct
50 Correct 1 ms 1876 KB Output is correct
51 Correct 263 ms 3276 KB Output is correct
52 Correct 727 ms 407348 KB Output is correct
53 Correct 693 ms 400336 KB Output is correct
54 Correct 669 ms 376360 KB Output is correct
55 Correct 644 ms 373096 KB Output is correct
56 Correct 682 ms 383308 KB Output is correct
57 Correct 74 ms 14792 KB Output is correct
58 Correct 72 ms 14588 KB Output is correct
59 Correct 77 ms 14744 KB Output is correct
60 Correct 81 ms 14592 KB Output is correct
61 Correct 84 ms 15704 KB Output is correct
62 Correct 379 ms 195052 KB Output is correct
63 Correct 401 ms 213644 KB Output is correct
64 Correct 343 ms 195028 KB Output is correct
65 Correct 387 ms 200992 KB Output is correct
66 Correct 388 ms 212720 KB Output is correct
67 Correct 1 ms 1876 KB Output is correct
68 Correct 94 ms 14872 KB Output is correct
69 Execution timed out 1081 ms 385484 KB Time limit exceeded
70 Halted 0 ms 0 KB -