Search is not available for this dataset
name
stringlengths
2
88
description
stringlengths
31
8.62k
public_tests
dict
private_tests
dict
solution_type
stringclasses
2 values
programming_language
stringclasses
5 values
solution
stringlengths
1
983k
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; const double PI = acos((long double)-1.0); const double EPS = 1e-10; const int MOD = 1e9 + 7; template <typename T> void cmin(T &x, T y) { if (y < x) x = y; } template <typename T> void cmax(T &x, T ...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
CORRECT
python3
n = int(input()) a = [0] + list(map(int, input().split())) pos, pb, ps = [[0] * (n + 1) for x in range(3)] def add(bit, i, val): while i <= n: bit[i] += val i += i & -i def sum(bit, i): res = 0 while i > 0: res += bit[i] i -= i & -i return res def find(bit, sum): ...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; int n; int a[MAXN]; int pos[MAXN]; struct BIT { long long tree[MAXN]; BIT() {} int LB(int x) { return x & -x; } void Modify(int p, long long k) { while (p <= n) { tree[p] += k; p += LB(p); } } long long Query(int p) ...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int INF = 1061109567; const long long LINF = 4557430888798830399ll; const int MOD = 1000000007; long long qpow(long long x, long long n) { long long res = 1; while (n) { if (n & 1) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } stru...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int INF = 1061109567; const long long LINF = 4557430888798830399ll; const int MOD = 1000000007; long long qpow(long long x, long long n) { long long res = 1; while (n) { if (n & 1) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } stru...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const bool debug = true; int p[200001]; int pos[200001]; class seg_tree { int* st; int n; public: seg_tree(int a) { st = new int[2 * a]; for (int i = 0; i < 2 * a; i++) st[i] = 0; n = a; } void set(int x) { x += n; st[x] = 1; x /= 2; ...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 1, base = (1 << 19); int n, p[N], inv_t[2 * base + 1], where[N], pref; long long pos_t[2 * base + 1]; void add(int pos) { pos += base; while (pos) { inv_t[pos]++; pos /= 2; } } int sum(int l, int r) { l += base; r += base; int res = i...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int MAX_N = 2e5 + 10; int bit[MAX_N], n, pos[MAX_N], x; long long ans = 0; int lowbit(int x) { return x & (-x); } int sum(int x) { int res = 0; while (x < MAX_N) { res += bit[x]; x += lowbit(x); } return res; } void update(int x) { while (x) { bi...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 5; int a[MAX], p[MAX], n; long long c1[MAX], c2[MAX]; set<int> st; void add(long long *c, int x, int k) { for (; x <= n; x += x & -x) c[x] += k; } long long query(long long *c, int x) { long long sum = 0; for (; x; x -= x & -x) sum += c[x]; ret...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int INF = 1061109567; const int MAXN = 201010; int n, median; int v[MAXN]; int ind[MAXN]; long long st[4 * MAXN]; long long adjust[MAXN]; long long inversions[MAXN]; priority_queue<int> maxheap; priority_queue<int, vector<int>, greater<int> > minheap; void update(int ...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; long long bit[N] = {}; int idx[N] = {}; int n; priority_queue<int> A; priority_queue<int, vector<int>, greater<int>> B; inline long long __abs(int x) { return (x ^ (x >> 31)) - (x >> 31); } long long sum(int x) { int ret = 0; while (x) { ret +...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
CORRECT
cpp
#include <bits/stdc++.h> const int inf = (1 << 29) - 1; const int maxn = (int)2e5 + 10; const int mod = (int)1e9 + 7; using namespace std; int n; int p[maxn]; long long t[2][maxn]; int rp[maxn]; void upd(int id, int pos, int val) { for (int i = pos; i <= n; i |= i + 1) t[id][i] += val; } long long get(int id, int pos...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 9; long long mid[N], a[N], mark[N], k, f1[N][2], n, g[N], h[N], p, ct, cn, tvn = 1, tedad[N * 4]; string s, s2; long long saghf(long long x) { return (x / 2) + (x % 2); } string binary(int m, int k) { string g = ""; for (long long i = 0; i < k; i...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; long long bit[N] = {}; int idx[N] = {}; int n; priority_queue<int> A; priority_queue<int, vector<int>, greater<int>> B; long long sum(int x) { int ret = 0; while (x) { ret += bit[x]; x -= (x & -x); } return ret; } void add(int x, int v...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int n; int pos[maxn]; long long sum1[maxn], sum2[maxn]; int lowbit(int x) { return x & -x; } void add(long long *sum, int x, long long v) { while (x <= n) { sum[x] += v; x += lowbit(x); } } long long query(long long *sum, int x) { lo...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; long long ans, n, a[210000], x, sum1, sum2, las; int rd[450000], siz[450000], son[450000][2], v[450000], root, num[450000], cnt; priority_queue<int> q1; priority_queue<int, vector<int>, greater<int> > q2; inline void update(int x) { if (!q2.size() || x > q2.top()) q2....
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
CORRECT
cpp
#include <bits/stdc++.h> const long long maxn = 200000 + 10; class BIT { private: long long n; long long bit[maxn]; public: BIT(long long size) { n = size; std::fill(bit, bit + maxn, 0); } void add(long long x, long long v) { while (x <= this->n) { bit[x] += v; x += ((x) & (-x)); ...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
CORRECT
java
import java.util.Scanner; public class KIntegers { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] p = new int[n + 1]; int[] q = new int[n + 1]; for (int j = 1; j <= n; j++) { p[j] = in.nextInt(); ...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const long long MAXN = 200000 + 10; long long BIT1[MAXN], BIT2[MAXN]; long long N; void update(long long p, long long num, long long *BIT) { for (; p <= N; p += p & -p) { BIT[p] += num; } } long long query(long long p, long long *BIT) { long long sum = 0; for (;...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; long long sum1[MAXN], sum2[MAXN], a[MAXN], pos[MAXN]; void add1(long long x, long long y) { if (!x) return; for (; x < MAXN; x += x & -x) { sum1[x] += y; } } long long query1(long long x) { long long ans = 0; for (; x; x -= x & -x) { ...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5; const int INF = 0x3f3f3f3f; const int mod = 1e9 + 7; const double Pi = acos(-1); long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } double dpow(double a, l...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
CORRECT
python2
n = input() arr = map(int,raw_input().split(" ")) trees = [0]*(1+n) dic = [0]*(n+1) ans = [0]*n def update(t,i,v): while i < len(t): t[i] += v i += lowbit(i) def lowbit(x): return x&-x def sum(t,i): ans = 0 while i>0: ans += t[i] ...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int s[200005], sum[200005], ara[200005], p[200005], seg[4 * 200005]; void add(int x, int n) { while (x <= n) { sum[x]++; x += (x & -x); } return; } int query(int x) { int ret = 0; while (x) { ret += sum[x]; x -= (x & -x); } return ret; } void u...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
CORRECT
python3
from bisect import bisect_right, bisect_left # instead of AVLTree class BITbisect(): def __init__(self, InputProbNumbers): # 座圧 self.ind_to_co = [-10**18] self.co_to_ind = {} for ind, num in enumerate(sorted(list(set(InputProbNumbers)))): self.ind_to_co.append(num) ...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 7; int n, sum[maxn], r[maxn]; void add(int i) { while (i <= n) { sum[i]++; i += i & (-i); } } int getsum(int i) { int ans = 0; while (i) { ans += sum[i]; i -= i & (-i); } return ans; } int bs(int s, int e, int t) { int mi...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
CORRECT
java
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.StringTokenizer; import java.io.BufferedReader; import java.util.Comparator; import java.util.Collec...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using ll = long long; using dd = double; using pll = pair<ll, ll>; using tll = tuple<ll, ll, ll>; using vll = vector<ll>; using vdd = vector<dd>; using vpll = vector<pll>; using vtll = vector<tll>; using vvll = vector<vll>; using vvdd = vector<vdd>; using vvpll = vector<vpl...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
CORRECT
java
/* If you want to aim high, aim high Don't let that studying and grades consume you Just live life young ****************************** If I'm the sun, you're the moon Because when I go up, you go down ******************************* I'm working for the day I will surpass you https://www.a2oj.com/Ladder16.html */ impor...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int MX = 2e5 + 5, MXX = 23; const long long mod = 1e9 + 7, inf = 1e18 + 6; int n, a[MX], ind[MX], ver[MX]; void add(int l) { for (int i = l + 1; i < MX; i += i & -i) ver[i]++; } int ask(int pn) { int ans = 0; for (pn++; pn; pn -= pn & -pn) ans += ver[pn]; retu...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
CORRECT
cpp
#include <bits/stdc++.h> int size = 256 * 1024; int Count(std::vector<int>& tree, int l, int r) { l += size; r += size; int ans = 0; while (l <= r) { if (l % 2) { ans += tree[l]; ++l; } if (r % 2 == 0) { ans += tree[r]; --r; } if (l > r) break; r >>= 1; l >>= ...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const long long N = 200010; long long tr1[N], tr2[N]; long long n; long long c[N]; long long lowbit(long long x) { return x & -x; } void ud(long long tr[], long long x, long long d) { for (long long i = x; i <= n; i += lowbit(i)) { tr[i] += d; } } long long qur(long...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
CORRECT
cpp
#include <bits/stdc++.h> const int maxn = 2e5 + 10; const int maxm = 1e5 + 10; const long long int mod = 1e9 + 7; const long long int INF = 1e18 + 100; const int inf = 0x3f3f3f3f; const double pi = acos(-1.0); const double eps = 1e-8; using namespace std; int n, m; int cas, tol, T; set<int> st; int a[maxn], p[maxn]; lo...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5; const int INF = 0x3f3f3f3f; const int mod = 1e9 + 7; const double Pi = acos(-1); long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } double dpow(double a, l...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct fenwick { int N; vector<int> bit; fenwick(int n = 1e5) { N = n + 5; bit.assign(N, 0); } void resize(int n) { N = n + 5; bit.assign(N, 0); } void update(int x, int val) { while (x < N) { bit[x] += val; x += x & -x; } ...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 2e5 + 233; int ch[maxn]; int a[maxn], n, p[maxn]; long long ans[maxn], sum[maxn]; void add(int x, int v) { for (int i = x; i <= n; i += i & (-i)) ch[i] += v; } int query(int x) { int sum = 0; for (int i = x; i; i -= i & (-i)) ...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 9; long long mid[N], a[N], mark[N], k, f1[N][2], n, g[N], h[N], p, ct, cn, tvn = 1, tedad[N]; string s, s2; long long saghf(long long x) { return (x / 2) + (x % 2); } string binary(int m, int k) { string g = ""; for (long long i = 0; i < k; i++) ...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> #define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); typedef long long ll; typedef long double ld; #define pb push_back #define mp make_pair #define ff first #define ss second #define mod 1000000007 #define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++) #defin...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define uid uniform_int_distribution mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); #define bpop(x) __builtin_po...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
java
import java.io.*; import java.util.*; public class Contest1 { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> #include <cassert> #include <numeric> #include <type_traits> namespace atcoder { namespace internal { #ifndef _MSC_VER template <class T> using is_signed_int128 = typename std::conditional<std::is_same<T, __int128_t>::value || std::is_same<T, __int128...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> const int maxn = 200000 + 10; class BIT { private: int n; int bit[maxn]; public: BIT(int size) { n = size; std::fill(bit, bit + size, 0); } void add(int x, int v) { while (x <= this->n) { bit[x] += v; x += ((x) & (-x)); } } int query(int x) { int...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int n; int pos[maxn]; int sum1[maxn], sum2[maxn]; int lowbit(int x) { return x & -x; } void add(int *sum, int x, int v) { while (x <= n) { sum[x] += v; x += lowbit(x); } } int query(int *sum, int x) { int ans = 0; while (x > 0) { ...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> #ifndef ONLINE_JUDGE #include <custom/prettyprint.hpp> #endif using namespace std; #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; typedef long long ll; #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define sz(x) (int)x.size() #define dbg(x) cerr << #x << " = " << x <...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = 200000; int a[200005], pos[200005]; long long sum1[200005], sum2[200005]; void add(long long *sum1, int x, int val) { while (x <= maxn) { sum1[x] += val; x += x & (-x); } } int sum(long long *sum1, int pos) { int res = 0; while (pos) { r...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int INF = 1061109567; const int MAXN = 201010; int n, median; int v[MAXN]; int ind[MAXN]; int st[4 * MAXN]; long long adjust[MAXN]; long long inversions[MAXN]; priority_queue<int> maxheap; priority_queue<int, vector<int>, greater<int> > minheap; void update(int nd, in...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; long long bit[N] = {}; int idx[N] = {}; int n; priority_queue<int> A; priority_queue<int, vector<int>, greater<int>> B; long long sum(int x) { int ret = 0; while (x) { ret += bit[x]; x -= (x & -x); } return ret; } void add(int x, int v...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> const int maxn = 200000 + 10; class BIT { private: int n; int bit[maxn]; public: BIT(int size) { n = size; std::fill(bit, bit + size, 0); } void add(int x, int v) { while (x <= this->n) { bit[x] += v; x += ((x) & (-x)); } } int query(int x) { int...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> int main() { int i,j,n,k; cin>>n; vector<int>a(n)...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; class BinTree : vector<long long> { public: explicit BinTree(long long k = 0) { assign(k + 1, 0); } long long lowbit(long long k) { return k & -k; } long long sum(long long k) { return k > 0 ? sum(k - lowbit(k)) + (*this)[k] : 0; } long long last() { return s...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
python3
from bisect import bisect_right, bisect_left # instead of AVLTree class BITbisect(): def __init__(self, InputProbNumbers): # 座圧 self.ind_to_co = [-10**18] self.co_to_ind = {} for ind, num in enumerate(sorted(list(set(InputProbNumbers)))): self.ind_to_co.append(num) ...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> #include <cassert> #include <numeric> #include <type_traits> namespace atcoder { namespace internal { #ifndef _MSC_VER template <class T> using is_signed_int128 = typename std::conditional<std::is_same<T, __int128_t>::value || std::is_same<T, __int128>:...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct fenwick { int N; vector<int> bit; fenwick(int n = 1e5) { N = n + 5; bit.assign(N, 0); } void resize(int n) { N = n + 5; bit.assign(N, 0); } void update(int x, int val) { while (x < N) { bit[x] += val; x += x & -x; } ...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> const int maxn = 2e5 + 10; const int maxm = 1e5 + 10; const long long int mod = 1e9 + 7; const long long int INF = 1e18 + 100; const int inf = 0x3f3f3f3f; const double pi = acos(-1.0); const double eps = 1e-8; using namespace std; int n, m; int cas, tol, T; set<int> st; int a[maxn], p[maxn]; in...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int s[200005], sum[200005], ara[200005], p[200005], seg[4 * 200005]; void add(int x, int n) { while (x <= n) { sum[x]++; x += (x & -x); } return; } int query(int x) { int ret = 0; while (x) { ret += sum[x]; x -= (x & -x); } return ret; } void u...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int MAXN = 200000 + 10; int BIT1[MAXN], BIT2[MAXN]; int N; void update(int p, int num, int *BIT) { for (; p < N; p += p & -p) { BIT[p] += num; } } int query(int p, int *BIT) { int sum = 0; for (; p > 0; p -= p & -p) { sum += BIT[p]; } return sum; }...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define LL long long #define PI pair<int,int> #define PL pair<LL,LL> #define st first #define nd second #define all(x) x.begin(),x.end() using namespace __gnu_pbds; using namespace std; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statis...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 2e5 + 233; int ch[maxn]; int a[maxn], n, p[maxn]; long long ans[maxn], sum[maxn]; void add(int x, int v) { for (int i = x; i <= n; i += i & (-i)) ch[i] += v; } int query(int x) { int sum = 0; for (int i = x; i; i -= i & (-i)) ...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int N; int p[maxn], ip[maxn]; long long sum[maxn << 2][2]; void update(int ver, int pos, int val) { while (pos <= N) { sum[pos][ver] += val; pos += pos & (-pos); } } long long ask(int ver, int pos) { int ret = 0; while (pos) { ...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int s[200005], sum[200005], ara[200005], p[200005], seg[4 * 200005]; void add(int x, int n) { while (x <= n) { sum[x]++; x += (x & -x); } return; } int query(int x) { int ret = 0; while (x) { ret += sum[x]; x -= (x & -x); } return ret; } void u...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> int main() { int i,j,n,k; cin>>n; vector<int>a(n)...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; int n, a[200010], p[200010], c[200010]; long long inv[200010]; set<int> st; set<int>::iterator it; int Lowbit(int x) { return x & (-x); } void Update(int x, int d) { while (x <= n) { c[x] += d; x += Lowbit(x); } } int Getsum(int x) { ...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int MAXN = 200100; const long long INF = 0x3f3f3f3f3f3f3f3f; struct seg { seg *fe, *fd; long long meio, soma, l, r; seg(long long x, long long y) { l = x, r = y; meio = (x + y) / 2; soma = 0; if (l == r) return; fe = new seg(x, meio); fd ...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int MX = 2e5 + 5, MXX = 23; const long long mod = 1e9 + 7, inf = 1e18 + 6; int n, a[MX], ind[MX], ver[MX]; long long seg[4 * MX], rm[4 * MX]; void add(int l) { for (int i = l + 1; i < MX; i += i & -i) ver[i]++; } int ask(int pn) { int ans = 0; for (pn++; pn; pn ...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include<bits/stdc++.h> #define ll long long using namespace std; struct SEG{ struct node{ int l,r; ll req; }tree[1<<22]; int tn=1; void make(int a){ if(a>=tn) return; make(2*a); make(2*a+1); tree[a].l=tree[2*a].l; tree[a].r=tree[2*a+1].r; tree[a].req=tree[2*a].req+tree[2*a+1].req; } void init(int n){ ...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) { return os << "(" << P.first << "," << P.second << ")"; } template <class T> ostream &operator<<(ostream &os, vector<T> V) { os << "["; for (auto vv : V) os << vv << ","; return os << "]"; }...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; #include <bits/extc++.h> /** keep-include */ using namespace __gnu_pbds; template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using namespace std; class Median_heap { private: priority_queue<int> min_heap; priority_queue<int> max_heap; long long sml = 0; long long big = 0; public: Median_heap(){}; void update(int x) { if (min_heap.empty()) { min_heap.push(-x); big +=...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> #include <cassert> #include <numeric> #include <type_traits> namespace atcoder { namespace internal { #ifndef _MSC_VER template <class T> using is_signed_int128 = typename std::conditional<std::is_same<T, __int128_t>::value || std::is_same<T, __int128...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 200010; int tr1[N], tr2[N]; int n; int c[N]; int lowbit(int x) { return x & -x; } void ud(int tr[], int x, int d) { for (int i = x; i <= n; i += lowbit(i)) { tr[i] += d; } } int qur(int tr[], int x) { int ans = 0; for (int i = x; i; i -= lowbit(i))...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#pragma GCC optimize(2) #include <cstdio> #include <queue> #include <string> #include <cstring> #include <algorithm> #include <cstdlib> #include <iostream> #include <iomanip> #include <cmath> #include <vector> #include <set> #include <map> #include <fstream> #include <cassert> #include <complex> #include <ctime> #inclu...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = 200000; int a[200005], pos[200005]; long long sum1[200005], sum2[200005]; void add(long long *sum1, int x, int val) { while (x <= maxn) { sum1[x] += val; x += x & (-x); } } long long sum(long long *sum1, int pos) { long long res = 0; while (...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int INF = 1061109567; const long long LINF = 4557430888798830399ll; const int MOD = 1000000007; long long qpow(long long x, long long n) { long long res = 1; while (n) { if (n & 1) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } stru...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#pragma GCC optimize ("-O3") #include <bits/stdc++.h> #include <complex> #include <queue> #include <set> #include <unordered_set> #include <list> #include <chrono> #include <random> #include <iostream> #include <algorithm> #include <cmath> #include <string> #include <vector> #include <map> #include <unordered_map> #i...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; long long const inf = 1e9; long long const mod = 1e9 + 7; long double const eps = 1e-9; int bit[200005]; int bit2[200005]; long long sumbit[200005]; int n; void update(int k) { while (k <= 200000) { bit[k] += 1; k += k & -k; } } int sum(int k) { int s = 0; w...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const bool debug = true; int p[200001]; int pos[200001]; class seg_tree { int* st; int n; public: seg_tree(int a) { st = new int[2 * a]; for (int i = 0; i < 2 * a; i++) st[i] = 0; n = a; } void set(int x) { x += n; st[x] = 1; x /= 2; ...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int MX = 2e5 + 5; const int INF = 1e9 + 9; int n; long long Bit[MX]; long long Idx[MX]; long long Inv[MX]; long long Pos[MX]; vector<int> A; void Add_Bit(int x, int val) { for (; x <= n + 1; x += x & -x) Bit[x] += val; } void Add_Idx(int x, int val) { for (; x <= ...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> #include <cassert> #include <numeric> #include <type_traits> namespace atcoder { namespace internal { #ifndef _MSC_VER template <class T> using is_signed_int128 = typename std::conditional<std::is_same<T, __int128_t>::value || std::is_same<T, __int128...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using ll = long long; using dd = double; using pll = pair<ll, ll>; using tll = tuple<ll, ll, ll>; using vll = vector<ll>; using vdd = vector<dd>; using vpll = vector<pll>; using vtll = vector<tll>; using vvll = vector<vll>; using vvdd = vector<vdd>; using vvpll = vector<vpl...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int idx[N] = {}; int bit[N] = {}; long long ans[N] = {}; int n; int sum(int x) { int ret = 0; while (x) { ret += bit[x]; x -= (x & -x); } return ret; } void add(int x, int val) { while (x <= n) { bit[x] += val; x += (x & -x);...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxd = 2e5 + 10; int a[maxd], t[maxd]; void add(int x) { for (; x <= maxd; x += (x & -(x))) t[x]++; } int getsum(int x) { int sum = 0; for (; x; x -= (x & (-x))) sum += t[x]; return sum; } int main() { int n, k; scanf("%d", &n); int ans = 0; for (i...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
/* ID : omarmuh1 PROG : test LANG : C++11 */ #include "bits/stdc++.h" #include "ext/pb_ds/assoc_container.hpp" #define mp make_pair #define pb push_back #define ppb pop_back #define db puts("*****") #define mid(x , y) ((x+y)>>1) #define ff first #define ss second #define all(x) x.begin(),x.end() #define ll long long ...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> const int maxn = 2e5 + 10; const int maxm = 1e5 + 10; const long long int mod = 1e9 + 7; const long long int INF = 1e18 + 100; const int inf = 0x3f3f3f3f; const double pi = acos(-1.0); const double eps = 1e-8; using namespace std; int n, m; int cas, tol, T; set<int> st; int a[maxn], p[maxn]; in...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> const int maxn = 200000 + 10; class BIT { private: int n; int bit[maxn]; public: BIT(int size) { n = size; std::fill(bit, bit + size, 0); } void add(int x, int v) { while (x <= this->n) { bit[x] += v; x += ((x) & (-x)); } } int query(int x) { int...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 200010; int tr1[N], tr2[N]; int n; int c[N]; int lowbit(int x) { return x & -x; } void ud(int tr[], int x, int d) { for (int i = x; i <= n; i += lowbit(i)) { tr[i] += d; } } int qur(int tr[], int x) { int ans = 0; for (int i = x; i; i -= lowbit(i))...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 200010; int tr1[N], tr2[N]; int n; int c[N]; int lowbit(int x) { return x & -x; } void ud(int tr[], int x, int d) { for (int i = x; i <= n; i += lowbit(i)) { tr[i] += d; } } int qur(int tr[], int x) { int ans = 0; for (int i = x; i; i -= lowbit(i))...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define pii pair<int,int> #define pb push_back #define mp make_pair #define mt make_tuple #define DEBUG 1 #define cerr if (DEBUG) cerr #define fprintf if (DEBUG) fprintf #define local freopen("in.txt","r",stdin); #define test cerr<<"hi\n"; #define tr(x) ...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> int main() { int i,j,n,k; cin>>n; vector<int>a(n)...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> const int maxn = 200000 + 10; class BIT { private: int n; int bit[maxn]; public: BIT(int size) { n = size; std::fill(bit, bit + size, 0); } void add(int x, int v) { while (x <= this->n) { bit[x] += v; x += ((x) & (-x)); } } int query(int x) { int...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#pragma GCC optimize(2) #include <cstdio> #include <queue> #include <string> #include <cstring> #include <algorithm> #include <cstdlib> #include <iostream> #include <iomanip> #include <cmath> #include <vector> #include <set> #include <map> #include <fstream> #include <cassert> #include <complex> #include <ctime> #inclu...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define uid uniform_int_distribution mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); #define bpop(x) __builtin_po...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
python3
n = int(input()) a = [0] + list(map(int, input().split())) pos, bit = [[0] * (n+1), [0] * (n+1)] def add(i): while i <= n: bit[i] += 1 i += i & -i def sum(i): res = 0 while i > 0: res += bit[i] i -= i & -i return res for i in range(1, n+1): pos[a[i]] = i Max, ...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define endl '\n' #define fast_io \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); typedef lo...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
java
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.StringTokenizer; import java.io.BufferedReader; import java.util.Comparator; import java.util.Collec...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#pragma GCC optimize(2) #include <cstdio> #include <queue> #include <string> #include <cstring> #include <algorithm> #include <cstdlib> #include <iostream> #include <iomanip> #include <cmath> #include <vector> #include <set> #include <map> #include <fstream> #include <cassert> #include <complex> #include <ctime> #inclu...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 5; int a[MAX], p[MAX], c1[MAX], c2[MAX], n; set<int> st; void add(int *c, int x, int k) { for (; x <= n; x += x & -x) c[x] += k; } long long query(int *c, int x) { long long sum = 0; for (; x; x -= x & -x) sum += c[x]; return sum; } int main() ...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5; const int INF = 0x3f3f3f3f; const int mod = 1e9 + 7; const double Pi = acos(-1); long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } double dpow(double a, l...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e6 + 10; const long long mod = 1e9 + 7; const long long N = 1e6 + 10; long long n, m; long long fen[maxn]; void add(long long pos) { pos--; for (; pos < n; pos = (pos | (pos + 1))) fen[pos]++; } long long qu(long long r) { long long sm = 0; r...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; class BinTree : vector<long long> { public: explicit BinTree(long long k = 0) { assign(k + 1, 0); } long long lowbit(long long k) { return k & -k; } long long sum(long long k) { return k > 0 ? sum(k - lowbit(k)) + (*this)[k] : 0; } long long last() { return s...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> const int maxn = 2e5 + 10; const int maxm = 1e5 + 10; const long long int mod = 1e9 + 7; const long long int INF = 1e18 + 100; const int inf = 0x3f3f3f3f; const double pi = acos(-1.0); const double eps = 1e-8; using namespace std; int n, m; int cas, tol, T; set<int> st; int a[maxn], p[maxn]; lo...
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n" ], "output": [ "0 0 0\n", "0 1 3 6 10\n" ] }
{ "input": [ "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 ...
IN-CORRECT
cpp
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> using namespace __gnu_pbds; using namespace std; #define ll long long #define pb push_back #define ff first #define ss second #define all(v) v.begin(),v.end() #define ...