-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunc.cpp
More file actions
140 lines (115 loc) · 2.89 KB
/
Copy pathfunc.cpp
File metadata and controls
140 lines (115 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include <bits/stdc++.h>
#define ll long long
using namespace std;
// vector pair sort
//basis of first element of pairs in ascending order.
// sort(vect.begin(), vect.end());
//basis of second element of pairs in ascending order.
// bool cmp(pair<ll,ll> a, pair<ll,ll> b){
// return (a.second < b.second);
// }
// sort(vect.begin(), vect.end(), cmp);
// basis of first element of pairs in descending order.
// sort(vect.rbegin(), vect.rend());
// basis of second element of pairs in descending order.
// bool cmp(pair<ll,ll> a, pair<ll,ll> b){
// return (a.second > b.second);
// }
// sort(vect.begin(), vect.end(), cmp);
// first : - descending, second :- ascending
bool cmp1(pair<ll,ll> a, pair<ll,ll> b)
{
if(a.first == b.first)
return a.second < b.second;
return a.first > b.first;
}
// sort(v.begin(),v.end(),cmp1);
// Check if a number is prime or not
// O(root(n))
bool prime(int n) {
if (n<2) return false;
for (int x = 2;x*x<=n; x++) if (n%x==0) return false;
return true;
}
// seive of erarostheses
// int n;
// vector<bool> is_prime(n+1, true);
// is_prime[0] = is_prime[1] = false;
// for (int i = 2; i * i <= n; i++) {
// if (is_prime[i]) {
// for (int j = i * i; j <= n; j += i)
// is_prime[j] = false;
// }
// }
// Return a vector conrtaining prime factorization of n
// O(root(n))
vector<int> factor(int n){
vector<int> f;
for (int x = 2; x*x <= n; x++) {
while (n%x == 0){
f.push_back(x);
n /= x;
}
}
if (n>1) f.push_back(n);
return f;
}
//Euclid's Algorithm
// O(log(n)) where n = min(a,b)
// Worst case when a and b are consecutive fibonacci numbers
int gcd(int a,int b){
if (b==0) return a;
return gcd(b,a%b);
}
// x^n in O(logn)
ll binpow(ll a, ll b){
ll res = 1;
while (b > 0) {
if (b & 1) {
res = res*a;
}
a = a * a;
b >>= 1;
}
return res;
}
// x^n mod m
ll binpowmod(ll a, ll b, ll m){
a %= m;
ll res = 1;
while (b > 0){
if (b & 1){
res = res * a % m;
}
a = a * a % m;
b >>= 1;
}
return res;
}
// remove duplicates form a vector
// a.resize(unique(a.begin(), a.end()) - a.begin());
void solve(){
ll n,i,ai;
cin >> n;
vector<pair<int,int>> v(n);
for (i=0;i<n;i++) {
cin >> ai;
v[i] = {ai,i};
}
sort(v.rbegin(),v.rend());
for (auto x:v) cout << x.first << " " << x.second << "\n";
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
// cin >> t;
while (t--){
solve();
}
// cout << prime(12) << "\n";
// for (auto x:factor(123)){
// cout << x << " ";
// }
// cout << gcd(36, 18) << "\n";
return 0;
}