Skip to content

Commit a00d81e

Browse files
committed
practice questioin
1 parent ce3e10c commit a00d81e

File tree

3 files changed

+442
-0
lines changed

3 files changed

+442
-0
lines changed
+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
Institute: National Institute of Technology, Uttarakhand
5+
*/
6+
#include <bits/stdc++.h>
7+
#include <ext/pb_ds/assoc_container.hpp>
8+
#include <ext/pb_ds/tree_policy.hpp>
9+
using namespace std;
10+
using namespace __gnu_pbds;
11+
typedef long long ll ;
12+
typedef unsigned long long ull;
13+
typedef vector<ll> vl;
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+
#define Endl "\n"
22+
// loops
23+
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
24+
// Some print
25+
#define no cout<<"No"<<endl;
26+
#define yes cout<<"Yes"<<endl;
27+
// sort
28+
#define all(V) (V).begin(),(V).end()
29+
#define srt(V) sort(all(V))
30+
#define srtGreat(V) sort(all(V),greater<ll>())
31+
// some extra
32+
#define printv(v) for(ll i=0;i<ll(v.size());i++){cout<<v[i]<<" ";} line;
33+
#define precision(x) cout<<fixed<<setprecision(x);
34+
#define sz(V) ll(V.size())
35+
// template
36+
template <typename T>
37+
T mymax(T x,T y)
38+
{
39+
return (x>y)?x:y;
40+
}
41+
// function
42+
ll power(ll x,ll y,ll mod)
43+
{
44+
ll res=1;
45+
// x=x%mod;
46+
while(y>0)
47+
{
48+
if(y%2==1)
49+
{
50+
res*=x;
51+
// res=res%mod;
52+
}
53+
y/=2; x*=x; // x=x%mod;
54+
}
55+
return res;
56+
}
57+
ll str_to_num(string s)
58+
{
59+
return stoi(s);
60+
}
61+
62+
string num_to_str(ll num)
63+
{
64+
return to_string(num);
65+
}
66+
// datatype definination
67+
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
68+
class Point
69+
{
70+
public:
71+
ll x;
72+
ll y;
73+
ll z;
74+
ll getsum()
75+
{
76+
return x+y+z;
77+
}
78+
};
79+
/* ascii value
80+
A=65,Z=90,a=97,z=122
81+
*/
82+
/* --------------------MAIN PROGRAM----------------------------*/
83+
// to run ctrl+b
84+
const ll INF=LONG_MAX;
85+
const ll mod1=1e9+7;
86+
const ll mod2=998244353;
87+
88+
89+
// Techniques
90+
// divide into cases, brute force, pattern finding
91+
// sort, greedy, binary search, two pointer
92+
// transform into graph
93+
94+
ll solve()
95+
{
96+
ll n;
97+
cin>>n;
98+
vector<pair<ll,ll>> v(n);
99+
for(ll i=0;i<n;i++){
100+
cin>>v[i].ff;
101+
}
102+
for(ll i=0;i<n;i++)
103+
cin>>v[i].ss;
104+
ll a=v[0].ff,b=v[0].ss;
105+
for(ll i=1;i<n;i++){
106+
a=max(a,v[i].ff);
107+
b=min(b,v[i].ss);
108+
}
109+
ll ans=b-a+1;
110+
ans=max(ans,0LL);
111+
cout<<ans<<endl;
112+
return 0;
113+
}
114+
115+
int main()
116+
{
117+
speed;
118+
/* #ifndef ONLINE_JUDGE
119+
freopen("input.txt","r",stdin);
120+
freopen("output.txt","w",stdout);
121+
#endif */
122+
ll TestCase=1;
123+
// cin>>TestCase;
124+
while(TestCase--)
125+
{
126+
solve();
127+
}
128+
}
129+
/* -----------------END OF PROGRAM --------------------*/
130+
/*
131+
* stuff you should look before submission
132+
* constraint and time limit
133+
* int overflow
134+
* special test case (n=0||n=1||n=2)
135+
* don't get stuck on one approach if you get wrong answer
136+
*/

Atcoder/Practice/abc199_C-IPFL.cpp

+169
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
Institute: National Institute of Technology, Uttarakhand
5+
*/
6+
#include <bits/stdc++.h>
7+
#include <ext/pb_ds/assoc_container.hpp>
8+
#include <ext/pb_ds/tree_policy.hpp>
9+
using namespace std;
10+
using namespace __gnu_pbds;
11+
typedef long long ll ;
12+
typedef unsigned long long ull;
13+
typedef vector<ll> vl;
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+
#define Endl "\n"
22+
// loops
23+
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
24+
// Some print
25+
#define no cout<<"No"<<endl;
26+
#define yes cout<<"Yes"<<endl;
27+
// sort
28+
#define all(V) (V).begin(),(V).end()
29+
#define srt(V) sort(all(V))
30+
#define srtGreat(V) sort(all(V),greater<ll>())
31+
// some extra
32+
#define printv(v) for(ll i=0;i<ll(v.size());i++){cout<<v[i]<<" ";} line;
33+
#define precision(x) cout<<fixed<<setprecision(x);
34+
#define sz(V) ll(V.size())
35+
// template
36+
template <typename T>
37+
T mymax(T x,T y)
38+
{
39+
return (x>y)?x:y;
40+
}
41+
// function
42+
ll power(ll x,ll y,ll mod)
43+
{
44+
ll res=1;
45+
// x=x%mod;
46+
while(y>0)
47+
{
48+
if(y%2==1)
49+
{
50+
res*=x;
51+
// res=res%mod;
52+
}
53+
y/=2; x*=x; // x=x%mod;
54+
}
55+
return res;
56+
}
57+
ll str_to_num(string s)
58+
{
59+
return stoi(s);
60+
}
61+
62+
string num_to_str(ll num)
63+
{
64+
return to_string(num);
65+
}
66+
// datatype definination
67+
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
68+
class Point
69+
{
70+
public:
71+
ll x;
72+
ll y;
73+
ll z;
74+
ll getsum()
75+
{
76+
return x+y+z;
77+
}
78+
};
79+
/* ascii value
80+
A=65,Z=90,a=97,z=122
81+
*/
82+
/* --------------------MAIN PROGRAM----------------------------*/
83+
// to run ctrl+b
84+
const ll INF=LONG_MAX;
85+
const ll mod1=1e9+7;
86+
const ll mod2=998244353;
87+
88+
89+
// Techniques
90+
// divide into cases, brute force, pattern finding
91+
// sort, greedy, binary search, two pointer
92+
// transform into graph
93+
94+
ll solve()
95+
{
96+
ll n;
97+
cin>>n;
98+
string s;
99+
cin>>s;
100+
string a="",b="";
101+
for(ll i=0;i<2*n;i++){
102+
if(i<n)
103+
a+=s[i];
104+
else
105+
b+=s[i];
106+
}
107+
ll count=0;
108+
ll q;
109+
cin>>q;
110+
while(q--){
111+
ll ti,ai,bi;
112+
cin>>ti>>ai>>bi;
113+
ai--;
114+
bi--;
115+
if(ti==2)
116+
count++;
117+
else{
118+
if(count&1){
119+
if(ai<n&&bi<n)
120+
swap(b[ai],b[bi]);
121+
else if(ai>=n&&bi>=n)
122+
swap(a[ai-n],a[bi-n]);
123+
else if(ai>=n&&bi<n)
124+
swap(a[ai-n],b[bi]);
125+
else{
126+
swap(b[ai],a[bi-n]);
127+
}
128+
}
129+
else{
130+
if(ai<n&&bi<n)
131+
swap(a[ai],a[bi]);
132+
else if(ai>=n&&bi>=n)
133+
swap(b[ai-n],b[bi-n]);
134+
else if(ai>=n&&bi<n)
135+
swap(b[ai-n],a[bi]);
136+
else
137+
swap(a[ai],b[bi-n]);
138+
}
139+
}
140+
}
141+
if(count&1)
142+
cout<<b<<a<<endl;
143+
else
144+
cout<<a<<b<<endl;
145+
return 0;
146+
}
147+
148+
int main()
149+
{
150+
speed;
151+
/* #ifndef ONLINE_JUDGE
152+
freopen("input.txt","r",stdin);
153+
freopen("output.txt","w",stdout);
154+
#endif */
155+
ll TestCase=1;
156+
// cin>>TestCase;
157+
while(TestCase--)
158+
{
159+
solve();
160+
}
161+
}
162+
/* -----------------END OF PROGRAM --------------------*/
163+
/*
164+
* stuff you should look before submission
165+
* constraint and time limit
166+
* int overflow
167+
* special test case (n=0||n=1||n=2)
168+
* don't get stuck on one approach if you get wrong answer
169+
*/

0 commit comments

Comments
 (0)