11/*
22 written by Pankaj Kumar.
33 country:-INDIA
4- Institute: National Institute of Technology, Uttarakhand
54*/
65#include < bits/stdc++.h>
7- #include < ext/pb_ds/assoc_container.hpp>
8- #include < ext/pb_ds/tree_policy.hpp>
96using namespace std ;
10- using namespace __gnu_pbds ;
11- typedef long long ll ;
12- typedef vector<ll> vl;
13- typedef vector<vector<ll>> vvl;
14- #define speed cin.tie(0 );cout.tie(0 );ios_base::sync_with_stdio(0 );
15- /* Abbrevations */
16- #define ff first
17- #define ss second
18- #define mp make_pair
19- #define line cout<<endl;
20- #define pb push_back
21- // loops
22- #define forin (arr,n ) for (ll i=0 ;i<n;i++) cin>>arr[i];
23- // Some print
24- #define no cout<<" NO" <<endl;
25- #define yes cout<<" YES" <<endl;
26- // sort
27- #define all (V ) (V).begin(),(V).end()
28- #define srt (V ) sort(all(V))
29- #define srtGreat (V ) sort(all(V),greater<ll>())
30- // some extra
31- #define printv (v ) for (ll i=0 ;i<ll(v.size());i++){cout<<v[i]<<" " ;} line;
32- #define precision (x ) cout<<fixed<<setprecision(x);
33- #define sz (V ) ll(V.size())
34- // datatype definination
35- #define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
36-
37-
38- ll ppow (ll n, ll m, ll mod){
39- if (m==0 ) return 1 ;
40- ll tmp=ppow (n, m/2 , mod);
41- tmp=tmp*tmp%mod;
42- return m%2 ? tmp*n%mod: tmp;
43- }
44- namespace mod_operations {
45- ll modInv (ll n, ll mod){
46- return ppow (n,mod-2 , mod);
47- }
48- ll modAdd (ll n, ll m, ll mod){
49- n=(n%mod+mod)%mod; m=(m%mod+mod)%mod;
50- return (n+m)%mod;
51- }
52- ll modMul (ll n, ll m, ll mod){
53- n=(n%mod+mod)%mod; m=(m%mod+mod)%mod;
54- return n*m %mod;
55- }
56- ll modSub (ll n, ll m, ll mod){
57- n=(n%mod+mod)%mod; m=(m%mod+mod)%mod;
58- return modAdd (n,-m, mod);
59- }
60- ll modDiv (ll n, ll m, ll mod){
61- return modMul (n, modInv (m, mod), mod);
7+ typedef long long ll;
8+
9+
10+ int solve (){
11+ ll n;
12+ cin >> n;
13+ vector<pair<ll, ll>> t (n);
14+ for (ll i = 0 ; i < n; i++)
15+ {
16+ cin >> t[i].first >> t[i].second ;
6217 }
63- }
64- using namespace mod_operations ;
65-
66-
67- class Atcoder
68- {
69- private:
70- // read only variable
71- const ll INF=1e18 ;
72- const ll mod1=1e9 +7 ;
73- const ll mod2=998244353 ;
74-
75-
76- public:
77- Atcoder (){
78-
79- }
80-
81- ll power (ll x,ll y){
82- ll result=1 ;
83- while (y>0 ){
84- if (y&1 ){
85- result*=x;
86- }
87- y>>=1 ;
88- x*=x;
89- }
90- return result;
91- }
92-
93- ll power (ll x,ll y,ll mod){
94- ll result=1 ;
95- x%=mod;
96- while (y>0 ){
97- if (y&1 ){
98- result*=x;
99- result%=mod;
100- }
101- y>>=1 ;
102- x*=x;
103- x%=mod;
104- }
105- return result;
106- }
107-
108- ll str_to_num (string s)
109- {
110- stringstream pk (s);
111- ll num;
112- pk>>num;
113- return num;
114- }
115-
116- string num_to_str (ll num)
18+ sort (t.begin (),t.end ());
19+
20+ ll ans = 0 , current = 0 ;
21+ for (ll i = 0 ; i < n; i++)
22+ {
23+ if (i == 0 )
11724 {
118- return to_string (num);
25+ current = t[i].second ;
26+ ans++;
11927 }
120- // Techniques :
121- // divide into cases, brute force, pattern finding
122- // sort, greedy, binary search, two pointer
123- // transform into graph
124-
125- // Experience :
126- // Cp is nothing but only observation and mathematics.
127- ll solve ()
28+ else
12829 {
129- ll n;
130- cin>>n;
131- vector<pair<ll,ll>> t (n);
132- for (ll i=0 ;i<n;i++){
133- cin>>t[i].ff >>t[i].ss ;
30+ if (t[i].first >= current)
31+ {
32+ current = t[i].second ;
33+ ans++;
13434 }
135- srt (t);
136-
137- ll ans=0 ,maxo=0 ,current=0 ;
138- for (ll i=0 ;i<n;i++){
139- if (i==0 ){
140- current=t[i].ss ;
141- ans++;
142- }
143- else {
144- if (t[i].ff >=current){
145- current=t[i].ss ;
146- ans++;
147- }
148- else {
149- current=min (current,t[i].ss );
150- }
151- }
152- maxo=max (maxo,ans);
35+ else
36+ {
37+ current = min (current, t[i].second );
15338 }
154- cout<<ans<<endl;
155- return 0 ;
15639 }
157- };
158-
159-
160- /* --------------------MAIN PROGRAM----------------------------*/
161-
40+ }
41+ cout << ans << endl;
42+ return 0 ;
43+ }
16244int main ()
16345{
164- speed;
165- /* #ifndef ONLINE_JUDGE
166- freopen("input.txt","r",stdin);
167- freopen("output.txt","w",stdout);
168- #endif */
169- ll TestCase=1 ;
170- // cin>>TestCase;;
171- while (TestCase--)
172- {
173- Atcoder at;
174- at.solve ();
46+ int testCase=1 ;
47+ while (testCase--){
48+ solve ();
17549 }
176- }
177- /* -----------------END OF PROGRAM --------------------*/
178- /*
179- * stuff you should look before submission
180- * constraint and time limit
181- * int overflow
182- * special test case (n=0||n=1||n=2)
183- * don't get stuck on one approach if you get wrong answer
184- */
50+ return 0 ;
51+ }
0 commit comments