Submission #536033

# Submission time Handle Problem Language Result Execution time Memory
536033 2022-03-12T07:34:15 Z inksamurai Osumnjičeni (COCI21_osumnjiceni) C++17
110 / 110
510 ms 32928 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rng(i,x,n) for(int i=x;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3HspL4A ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vec(int);
void print(){cout<<"\n";}
template<class T,class...E>
void print(const T&v,const E&...u){cout<<v<<' ',print(u...);}
// e

using vp=vec(pii);

const int inf=1e9+11;

int cross(int a,int b,int c,int d){
	if(c>=a and c<=b) return 1;
	if(a>=c and a<=d) return 1;
	if(d>=a and d<=b) return 1;
	if(b>=c and b<=d) return 1;
	return 0;
}

signed main(){
_3HspL4A;
	int n;
	cin>>n;
	vp a(n);
	rep(i,n){
		cin>>a[i].fi>>a[i].se;
	}
	
	vi tmp;
	rep(i,n){
		tmp.pb(a[i].fi);
		tmp.pb(a[i].se);
	}
	sort(tmp.begin(),tmp.end());
	tmp.erase(unique(tmp.begin(),tmp.end()),tmp.end());
	rep(i,n){
		a[i].fi=lower_bound(tmp.begin(),tmp.end(),a[i].fi)-tmp.begin();
		a[i].se=lower_bound(tmp.begin(),tmp.end(),a[i].se)-tmp.begin();
	}
	const int m=sz(tmp);

	vi nxt(n,-1);
	{
		multiset<pii> mst;
		int j=0;
		rep(i,n){
			pii p=a[i];
			nxt[i]=i+1;
			if(!sz(mst)){
				mst.insert(p);
			}else{
				vi c={p.fi,p.se};
				while(1){
					bool pok=1;
					for(auto v:c){
						auto it=mst.lower_bound({v,-inf});
						if(it!=mst.end()){
							if(cross(it->fi,it->se,p.fi,p.se)) pok=0;
						}
						if(it!=mst.begin()){
							it=prev(it);
							if(cross(it->fi,it->se,p.fi,p.se)) pok=0;	
						}
					}	
					if(pok) break;
					mst.erase(mst.find({a[j].fi,a[j].se}));
					nxt[j]=i;
					j=j+1;
				}
				mst.insert(p);
			}
		}
		rng(k,j,n){
			nxt[k]=n;
		}
	}
	vec(vi) f(25,vi(n+1));
	rep(i,n){
		f[0][i]=nxt[i];
	}
	f[0][n]=n;
	rng(j,1,25){
		rep(i,n+1){
			f[j][i]=f[j-1][f[j-1][i]];
		}
	}
	int q;
	cin>>q;
	rep(_,q){
		int s,t;
		cin>>s>>t;
		s-=1;
		int now=0,ans=inf;
		per(j,25){
			if(f[j][s]>=t){
				ans=now+(1<<j);
			}else{
				s=f[j][s];
				now+=(1<<j);
			}
		}
		print(ans);
	}
//	
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:52:12: warning: unused variable 'm' [-Wunused-variable]
   52 |  const int m=sz(tmp);
      |            ^
# Verdict Execution time Memory Grader output
1 Correct 150 ms 23416 KB Output is correct
2 Correct 158 ms 23112 KB Output is correct
3 Correct 146 ms 23156 KB Output is correct
4 Correct 150 ms 23420 KB Output is correct
5 Correct 202 ms 24412 KB Output is correct
6 Correct 65 ms 22212 KB Output is correct
7 Correct 70 ms 22616 KB Output is correct
8 Correct 83 ms 22896 KB Output is correct
9 Correct 87 ms 23404 KB Output is correct
10 Correct 99 ms 22620 KB Output is correct
11 Correct 273 ms 26568 KB Output is correct
12 Correct 278 ms 24932 KB Output is correct
13 Correct 244 ms 25076 KB Output is correct
14 Correct 263 ms 24260 KB Output is correct
15 Correct 281 ms 26504 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 70 ms 23720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 852 KB Output is correct
2 Correct 6 ms 852 KB Output is correct
3 Correct 5 ms 852 KB Output is correct
4 Correct 6 ms 852 KB Output is correct
5 Correct 6 ms 852 KB Output is correct
6 Correct 6 ms 852 KB Output is correct
7 Correct 5 ms 852 KB Output is correct
8 Correct 6 ms 920 KB Output is correct
9 Correct 5 ms 892 KB Output is correct
10 Correct 5 ms 852 KB Output is correct
11 Correct 8 ms 908 KB Output is correct
12 Correct 6 ms 852 KB Output is correct
13 Correct 6 ms 980 KB Output is correct
14 Correct 7 ms 960 KB Output is correct
15 Correct 6 ms 976 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 4 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 852 KB Output is correct
2 Correct 6 ms 852 KB Output is correct
3 Correct 5 ms 852 KB Output is correct
4 Correct 6 ms 852 KB Output is correct
5 Correct 6 ms 852 KB Output is correct
6 Correct 6 ms 852 KB Output is correct
7 Correct 5 ms 852 KB Output is correct
8 Correct 6 ms 920 KB Output is correct
9 Correct 5 ms 892 KB Output is correct
10 Correct 5 ms 852 KB Output is correct
11 Correct 8 ms 908 KB Output is correct
12 Correct 6 ms 852 KB Output is correct
13 Correct 6 ms 980 KB Output is correct
14 Correct 7 ms 960 KB Output is correct
15 Correct 6 ms 976 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 4 ms 852 KB Output is correct
18 Correct 82 ms 1960 KB Output is correct
19 Correct 84 ms 1820 KB Output is correct
20 Correct 83 ms 1928 KB Output is correct
21 Correct 74 ms 1872 KB Output is correct
22 Correct 101 ms 1828 KB Output is correct
23 Correct 88 ms 1876 KB Output is correct
24 Correct 75 ms 1928 KB Output is correct
25 Correct 75 ms 1928 KB Output is correct
26 Correct 74 ms 1836 KB Output is correct
27 Correct 86 ms 1712 KB Output is correct
28 Correct 75 ms 1456 KB Output is correct
29 Correct 52 ms 1412 KB Output is correct
30 Correct 54 ms 1428 KB Output is correct
31 Correct 59 ms 1464 KB Output is correct
32 Correct 69 ms 1580 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 61 ms 2472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 172 ms 24456 KB Output is correct
2 Correct 163 ms 24004 KB Output is correct
3 Correct 144 ms 22348 KB Output is correct
4 Correct 154 ms 22092 KB Output is correct
5 Correct 154 ms 22852 KB Output is correct
6 Correct 62 ms 22468 KB Output is correct
7 Correct 68 ms 22204 KB Output is correct
8 Correct 84 ms 22480 KB Output is correct
9 Correct 95 ms 22156 KB Output is correct
10 Correct 114 ms 23992 KB Output is correct
11 Correct 260 ms 25144 KB Output is correct
12 Correct 340 ms 26360 KB Output is correct
13 Correct 312 ms 24568 KB Output is correct
14 Correct 273 ms 24676 KB Output is correct
15 Correct 365 ms 25424 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 69 ms 22852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 150 ms 23416 KB Output is correct
2 Correct 158 ms 23112 KB Output is correct
3 Correct 146 ms 23156 KB Output is correct
4 Correct 150 ms 23420 KB Output is correct
5 Correct 202 ms 24412 KB Output is correct
6 Correct 65 ms 22212 KB Output is correct
7 Correct 70 ms 22616 KB Output is correct
8 Correct 83 ms 22896 KB Output is correct
9 Correct 87 ms 23404 KB Output is correct
10 Correct 99 ms 22620 KB Output is correct
11 Correct 273 ms 26568 KB Output is correct
12 Correct 278 ms 24932 KB Output is correct
13 Correct 244 ms 25076 KB Output is correct
14 Correct 263 ms 24260 KB Output is correct
15 Correct 281 ms 26504 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 70 ms 23720 KB Output is correct
18 Correct 7 ms 852 KB Output is correct
19 Correct 6 ms 852 KB Output is correct
20 Correct 5 ms 852 KB Output is correct
21 Correct 6 ms 852 KB Output is correct
22 Correct 6 ms 852 KB Output is correct
23 Correct 6 ms 852 KB Output is correct
24 Correct 5 ms 852 KB Output is correct
25 Correct 6 ms 920 KB Output is correct
26 Correct 5 ms 892 KB Output is correct
27 Correct 5 ms 852 KB Output is correct
28 Correct 8 ms 908 KB Output is correct
29 Correct 6 ms 852 KB Output is correct
30 Correct 6 ms 980 KB Output is correct
31 Correct 7 ms 960 KB Output is correct
32 Correct 6 ms 976 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 4 ms 852 KB Output is correct
35 Correct 82 ms 1960 KB Output is correct
36 Correct 84 ms 1820 KB Output is correct
37 Correct 83 ms 1928 KB Output is correct
38 Correct 74 ms 1872 KB Output is correct
39 Correct 101 ms 1828 KB Output is correct
40 Correct 88 ms 1876 KB Output is correct
41 Correct 75 ms 1928 KB Output is correct
42 Correct 75 ms 1928 KB Output is correct
43 Correct 74 ms 1836 KB Output is correct
44 Correct 86 ms 1712 KB Output is correct
45 Correct 75 ms 1456 KB Output is correct
46 Correct 52 ms 1412 KB Output is correct
47 Correct 54 ms 1428 KB Output is correct
48 Correct 59 ms 1464 KB Output is correct
49 Correct 69 ms 1580 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 61 ms 2472 KB Output is correct
52 Correct 172 ms 24456 KB Output is correct
53 Correct 163 ms 24004 KB Output is correct
54 Correct 144 ms 22348 KB Output is correct
55 Correct 154 ms 22092 KB Output is correct
56 Correct 154 ms 22852 KB Output is correct
57 Correct 62 ms 22468 KB Output is correct
58 Correct 68 ms 22204 KB Output is correct
59 Correct 84 ms 22480 KB Output is correct
60 Correct 95 ms 22156 KB Output is correct
61 Correct 114 ms 23992 KB Output is correct
62 Correct 260 ms 25144 KB Output is correct
63 Correct 340 ms 26360 KB Output is correct
64 Correct 312 ms 24568 KB Output is correct
65 Correct 273 ms 24676 KB Output is correct
66 Correct 365 ms 25424 KB Output is correct
67 Correct 0 ms 212 KB Output is correct
68 Correct 69 ms 22852 KB Output is correct
69 Correct 444 ms 30192 KB Output is correct
70 Correct 475 ms 31544 KB Output is correct
71 Correct 490 ms 29292 KB Output is correct
72 Correct 488 ms 30708 KB Output is correct
73 Correct 488 ms 30304 KB Output is correct
74 Correct 431 ms 31892 KB Output is correct
75 Correct 353 ms 29768 KB Output is correct
76 Correct 416 ms 32020 KB Output is correct
77 Correct 366 ms 29664 KB Output is correct
78 Correct 409 ms 30160 KB Output is correct
79 Correct 510 ms 32928 KB Output is correct
80 Correct 404 ms 30996 KB Output is correct
81 Correct 402 ms 31800 KB Output is correct
82 Correct 421 ms 31712 KB Output is correct
83 Correct 395 ms 29232 KB Output is correct
84 Correct 1 ms 212 KB Output is correct
85 Correct 178 ms 29632 KB Output is correct