Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e2bdfa6

Browse files
another
1 parent 07b98c7 commit e2bdfa6

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
// Type definitions
6+
typedef long long ll;
7+
typedef long double ld;
8+
typedef pair<int, int> pii;
9+
typedef pair<ll, ll> pll;
10+
typedef vector<int> vi;
11+
typedef vector<ll> vl;
12+
typedef vector<pii> vpii;
13+
typedef vector<pll> vpll;
14+
typedef vector<vi> vvi;
15+
typedef vector<vl> vvl;
16+
17+
// Macros
18+
#define nline "\n"
19+
#define all(x) (x).begin(), (x).end()
20+
#define rall(x) (x).rbegin(), (x).rend()
21+
#define sz(x) (int)(x).size()
22+
#define pb push_back
23+
#define mp make_pair
24+
#define F first
25+
#define S second
26+
#define forn(i, n) for (int i = 0; i < int(n); i++)
27+
#define forr(i, a, b) for (int i = a; i <= b; i++)
28+
#define ford(i, a, b) for (int i = a; i >= b; i--)
29+
#define elasped_time 1.0 * clock() / CLOCKS_PER_SEC
30+
31+
// Constants
32+
const int MOD = 1e9 + 7;
33+
const ll INF = 1e18;
34+
const double EPS = 1e-9;
35+
const double PI = acos(-1);
36+
37+
ll mod_add(ll a, ll b, ll m = MOD) { return ((a % m) + (b % m)) % m; }
38+
ll mod_sub(ll a, ll b, ll m = MOD) { return ((a % m) - (b % m) + m) % m; }
39+
ll mod_mul(ll a, ll b, ll m = MOD) { return ((a % m) * (b % m)) % m; }
40+
41+
ll mod_pow(ll base, ll exp, ll m = MOD)
42+
{
43+
ll res = 1;
44+
base %= m;
45+
while (exp > 0)
46+
{
47+
if (exp & 1)
48+
res = mod_mul(res, base, m);
49+
base = mod_mul(base, base, m);
50+
exp >>= 1;
51+
}
52+
return res;
53+
}
54+
55+
ll mod_inv(ll a, ll m = MOD)
56+
{
57+
return mod_pow(a, m - 2, m); // Only works if m is prime
58+
}
59+
60+
ll mod_div(ll a, ll b, ll m = MOD)
61+
{
62+
return mod_mul(a, mod_inv(b, m), m);
63+
}
64+
65+
// Binary exponentiation (for non-modular calculations)
66+
ll binpow(ll base, ll exp)
67+
{
68+
ll res = 1;
69+
while (exp > 0)
70+
{
71+
if (exp & 1)
72+
res *= base;
73+
base *= base;
74+
exp >>= 1;
75+
}
76+
return res;
77+
}
78+
79+
void solve()
80+
{
81+
int n, x;
82+
cin >> n >> x;
83+
84+
forn(i, x)
85+
cout
86+
<< i << " ";
87+
forr(i, x + 1, n - 1)
88+
cout
89+
<< i << " ";
90+
91+
if (x != n)
92+
cout << x << " ";
93+
cout << nline;
94+
}
95+
96+
int main()
97+
{
98+
99+
ios_base::sync_with_stdio(0);
100+
cin.tie(0);
101+
cout.tie(0);
102+
103+
#ifndef ONLINE_JUDGE
104+
freopen("./outputs/input.txt", "r", stdin);
105+
freopen("./outputs/output.txt", "w", stdout);
106+
#endif
107+
108+
int t;
109+
cin >> t;
110+
while (t--)
111+
solve();
112+
113+
return 0;
114+
}
115+
// Explanation
116+
117+
/*
118+
% To maximize the occurrence of x as the mex of the array, we need to:
119+
% - First, print all the integers less than x. In this case, x can only appear once as mex.
120+
% - Next, print all the integers greater than x but less than n. Here, the occurrence of x as mex will be equal to the number of integers greater than x.
121+
% - Finally, if x is not equal to n, print x; otherwise, do not print it.
122+
*/

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /