feat(cf): 894
This commit is contained in:
parent
ab4fbd97b2
commit
372c5d20a5
48 changed files with 2330 additions and 0 deletions
9
codeforces/891/.clang-format
Normal file
9
codeforces/891/.clang-format
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
BasedOnStyle: Google
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortCompoundRequirementOnASingleLine: false
|
||||
AllowShortEnumsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: false
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLambdasOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
8
codeforces/891/.clangd
Normal file
8
codeforces/891/.clangd
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
CompileFlags:
|
||||
Add:
|
||||
- -Wall
|
||||
- -Wextra
|
||||
- -Wpedantic
|
||||
- -Wshadow
|
||||
- -DLOCAL
|
||||
- -Wno-unknown-pragmas
|
||||
101
codeforces/891/a.cc
Normal file
101
codeforces/891/a.cc
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MIN() {
|
||||
return std::numeric_limits<T>::min();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MAX() {
|
||||
return std::numeric_limits<T>::max();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto &&x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto &&x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
|
||||
#define prln(...) std::println(__VA_ARGS__)
|
||||
#define pr(...) std::print(__VA_ARGS__)
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbgln(...) std::println(__VA_ARGS__)
|
||||
#define dbg(...) std::print(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
inline static void NO() {
|
||||
prln("NO");
|
||||
}
|
||||
|
||||
inline static void YES() {
|
||||
prln("YES");
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using ve = std::vector<T>;
|
||||
template <typename T, size_t N>
|
||||
using ar = std::array<T, N>;
|
||||
template <typename T1, typename T2>
|
||||
using pa = std::pair<T1, T2>;
|
||||
template <typename... Ts>
|
||||
using tu = std::tuple<Ts...>;
|
||||
template <typename... Ts>
|
||||
using dq = std::deque<Ts...>;
|
||||
template <typename... Ts>
|
||||
using qu = std::queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using pq = std::priority_queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using st = std::stack<Ts...>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
int n;
|
||||
cin >> n;
|
||||
ve<int> a(n);
|
||||
for (auto &e : a)
|
||||
cin >> e;
|
||||
sort(all(a));
|
||||
|
||||
ll total = 0;
|
||||
for (int i = 1; i < n; ++i) {
|
||||
total += a[i];
|
||||
}
|
||||
(a[0] & 1) == (total & 1) ? YES() : NO();
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
15
codeforces/891/a.in
Normal file
15
codeforces/891/a.in
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
7
|
||||
8
|
||||
1 2 4 3 2 3 5 4
|
||||
2
|
||||
4 7
|
||||
3
|
||||
3 9 8
|
||||
2
|
||||
1 7
|
||||
5
|
||||
5 4 3 2 1
|
||||
4
|
||||
4 3 4 5
|
||||
2
|
||||
50 48
|
||||
10
codeforces/891/a.out
Normal file
10
codeforces/891/a.out
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
YES
|
||||
NO
|
||||
YES
|
||||
YES
|
||||
NO
|
||||
YES
|
||||
YES
|
||||
|
||||
[code]: 0
|
||||
[time]: 12.9125 ms
|
||||
108
codeforces/891/b.cc
Normal file
108
codeforces/891/b.cc
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MIN() {
|
||||
return std::numeric_limits<T>::min();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MAX() {
|
||||
return std::numeric_limits<T>::max();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto&& x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto&& x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
|
||||
#define prln(...) std::println(__VA_ARGS__)
|
||||
#define pr(...) std::print(__VA_ARGS__)
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbgln(...) std::println(__VA_ARGS__)
|
||||
#define dbg(...) std::print(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
inline static void NO() {
|
||||
prln("NO");
|
||||
}
|
||||
|
||||
inline static void YES() {
|
||||
prln("YES");
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using ve = std::vector<T>;
|
||||
template <typename T, size_t N>
|
||||
using ar = std::array<T, N>;
|
||||
template <typename T1, typename T2>
|
||||
using pa = std::pair<T1, T2>;
|
||||
template <typename... Ts>
|
||||
using tu = std::tuple<Ts...>;
|
||||
template <typename... Ts>
|
||||
using dq = std::deque<Ts...>;
|
||||
template <typename... Ts>
|
||||
using qu = std::queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using pq = std::priority_queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using st = std::stack<Ts...>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
string s;
|
||||
cin >> s;
|
||||
|
||||
bool carry = false;
|
||||
int leftmost = sz<int>(s);
|
||||
|
||||
for (int i = sz<int>(s) - 1; i >= 0; --i) {
|
||||
int d = s[i] - '0' + int(carry);
|
||||
if (d < 5)
|
||||
s[i] += carry;
|
||||
if (carry = d >= 5)
|
||||
leftmost = i;
|
||||
}
|
||||
|
||||
if (carry)
|
||||
pr("1");
|
||||
for (int i = 0; i < sz<int>(s); ++i)
|
||||
pr("{}", (i < leftmost) ? '0' : s[i]);
|
||||
prln();
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
11
codeforces/891/b.in
Normal file
11
codeforces/891/b.in
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
10
|
||||
1
|
||||
5
|
||||
99
|
||||
913
|
||||
1980
|
||||
20444
|
||||
20445
|
||||
60947
|
||||
419860
|
||||
40862016542130810467
|
||||
13
codeforces/891/b.out
Normal file
13
codeforces/891/b.out
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
0
|
||||
15
|
||||
199
|
||||
1913
|
||||
0980
|
||||
00000
|
||||
00445
|
||||
161947
|
||||
009860
|
||||
00862026542131811467
|
||||
|
||||
[code]: 0
|
||||
[time]: 6.30426 ms
|
||||
215
codeforces/891/c.cc
Normal file
215
codeforces/891/c.cc
Normal file
|
|
@ -0,0 +1,215 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MIN() {
|
||||
return std::numeric_limits<T>::min();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MAX() {
|
||||
return std::numeric_limits<T>::max();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto &&x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto &&x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
|
||||
#define prln(...) std::println(__VA_ARGS__)
|
||||
#define pr(...) std::print(__VA_ARGS__)
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbgln(...) std::println(__VA_ARGS__)
|
||||
#define dbg(...) std::print(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
inline static void NO() {
|
||||
prln("NO");
|
||||
}
|
||||
|
||||
inline static void YES() {
|
||||
prln("YES");
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using ve = std::vector<T>;
|
||||
template <typename T, size_t N>
|
||||
using ar = std::array<T, N>;
|
||||
template <typename T1, typename T2>
|
||||
using pa = std::pair<T1, T2>;
|
||||
template <typename... Ts>
|
||||
using tu = std::tuple<Ts...>;
|
||||
template <typename... Ts>
|
||||
using dq = std::deque<Ts...>;
|
||||
template <typename... Ts>
|
||||
using qu = std::queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using pq = std::priority_queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using st = std::stack<Ts...>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
// }}}
|
||||
|
||||
#include <ext/pb_ds/assoc_container.hpp>
|
||||
#include <ext/pb_ds/tree_policy.hpp>
|
||||
|
||||
using namespace __gnu_pbds;
|
||||
|
||||
// https://mirror.codeforces.com/blog/entry/124683
|
||||
|
||||
namespace hashing {
|
||||
using i64 = std::int64_t;
|
||||
using u64 = std::uint64_t;
|
||||
static const u64 FIXED_RANDOM =
|
||||
std::chrono::steady_clock::now().time_since_epoch().count();
|
||||
|
||||
#if USE_AES
|
||||
std::mt19937 rd(FIXED_RANDOM);
|
||||
const __m128i KEY1{(i64)rd(), (i64)rd()};
|
||||
const __m128i KEY2{(i64)rd(), (i64)rd()};
|
||||
#endif
|
||||
|
||||
template <class T, class D = void>
|
||||
struct custom_hash {};
|
||||
|
||||
template <class T>
|
||||
inline void hash_combine(u64 &seed, T const &v) {
|
||||
custom_hash<T> hasher;
|
||||
seed ^= hasher(v) + 0x9e3779b97f4a7c15 + (seed << 12) + (seed >> 4);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct custom_hash<T,
|
||||
typename std::enable_if<std::is_integral<T>::value>::type> {
|
||||
u64 operator()(T _x) const {
|
||||
u64 x = _x;
|
||||
#if USE_AES
|
||||
__m128i m{i64(u64(x) * 0xbf58476d1ce4e5b9u64), (i64)FIXED_RANDOM};
|
||||
__m128i y = _mm_aesenc_si128(m, KEY1);
|
||||
__m128i z = _mm_aesenc_si128(y, KEY2);
|
||||
return z[0];
|
||||
#else
|
||||
x += 0x9e3779b97f4a7c15 + FIXED_RANDOM;
|
||||
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
|
||||
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
|
||||
return x ^ (x >> 31);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct custom_hash<T, std::void_t<decltype(std::begin(std::declval<T>()))>> {
|
||||
u64 operator()(T const &a) const {
|
||||
u64 value = FIXED_RANDOM;
|
||||
for (auto &x : a)
|
||||
hash_combine(value, x);
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
template <class... T>
|
||||
struct custom_hash<std::tuple<T...>> {
|
||||
u64 operator()(const std::tuple<T...> &a) const {
|
||||
u64 value = FIXED_RANDOM;
|
||||
std::apply(
|
||||
[&value](T const &...args) {
|
||||
(hash_combine(value, args), ...);
|
||||
},
|
||||
a);
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class U>
|
||||
struct custom_hash<std::pair<T, U>> {
|
||||
u64 operator()(std::pair<T, U> const &a) const {
|
||||
u64 value = FIXED_RANDOM;
|
||||
hash_combine(value, a.first);
|
||||
hash_combine(value, a.second);
|
||||
return value;
|
||||
}
|
||||
};
|
||||
}; // namespace hashing
|
||||
|
||||
#ifdef PB_DS_ASSOC_CNTNR_HPP
|
||||
template <class Key, class Value = null_type>
|
||||
using hashtable = gp_hash_table<
|
||||
Key, Value, hashing::custom_hash<Key>, std::equal_to<Key>,
|
||||
direct_mask_range_hashing<>, linear_probe_fn<>,
|
||||
hash_standard_resize_policy<hash_exponential_size_policy<>,
|
||||
hash_load_check_resize_trigger<>, true>>;
|
||||
|
||||
#endif
|
||||
#ifdef PB_DS_TREE_POLICY_HPP
|
||||
template <typename T>
|
||||
using multitree = tree<T, null_type, std::less_equal<T>, rb_tree_tag,
|
||||
tree_order_statistics_node_update>;
|
||||
template <class Key, class Value = null_type>
|
||||
using rbtree = tree<Key, Value, std::less<Key>, rb_tree_tag,
|
||||
tree_order_statistics_node_update>;
|
||||
#endif
|
||||
|
||||
void solve() {
|
||||
ll n;
|
||||
cin >> n;
|
||||
ve<ll> b(n * (n - 1) / 2);
|
||||
|
||||
hashtable<int, int> m;
|
||||
for (auto &e : b) {
|
||||
cin >> e;
|
||||
++m[e];
|
||||
}
|
||||
sort(all(b));
|
||||
b.erase(unique(all(b)), b.end());
|
||||
|
||||
ve<int> ans(n);
|
||||
|
||||
int write = n - 1;
|
||||
int count = 0;
|
||||
for (int i = sz<int>(b) - 1; i >= 0; --i) {
|
||||
while (m[b[i]]) {
|
||||
ans[write--] = b[i];
|
||||
m[b[i]] -= count;
|
||||
++count;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &e : ans)
|
||||
pr("{} ", e);
|
||||
prln();
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
3
codeforces/891/c.in
Normal file
3
codeforces/891/c.in
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
1
|
||||
3
|
||||
1 3 1
|
||||
4
codeforces/891/c.out
Normal file
4
codeforces/891/c.out
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
1 3 3
|
||||
|
||||
[code]: 0
|
||||
[time]: 13.2291 ms
|
||||
6
codeforces/891/compile_flags.txt
Normal file
6
codeforces/891/compile_flags.txt
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
-Wall
|
||||
-Wextra
|
||||
-Wpedantic
|
||||
-Wshadow
|
||||
-DLOCAL
|
||||
-std=c++23
|
||||
113
codeforces/891/d.cc
Normal file
113
codeforces/891/d.cc
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MIN() {
|
||||
return std::numeric_limits<T>::min();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MAX() {
|
||||
return std::numeric_limits<T>::max();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto&& x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto&& x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
|
||||
#define prln(...) std::println(__VA_ARGS__)
|
||||
#define pr(...) std::print(__VA_ARGS__)
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbgln(...) std::println(__VA_ARGS__)
|
||||
#define dbg(...) std::print(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
inline static void NO() {
|
||||
prln("NO");
|
||||
}
|
||||
|
||||
inline static void YES() {
|
||||
prln("YES");
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using ve = std::vector<T>;
|
||||
template <typename T, size_t N>
|
||||
using ar = std::array<T, N>;
|
||||
template <typename T1, typename T2>
|
||||
using pa = std::pair<T1, T2>;
|
||||
template <typename... Ts>
|
||||
using tu = std::tuple<Ts...>;
|
||||
template <typename... Ts>
|
||||
using dq = std::deque<Ts...>;
|
||||
template <typename... Ts>
|
||||
using qu = std::queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using pq = std::priority_queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using st = std::stack<Ts...>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
int n;
|
||||
cin >> n;
|
||||
ve<ll> a(n), b(n);
|
||||
for (auto& e : a)
|
||||
cin >> e;
|
||||
for (auto& e : b)
|
||||
cin >> e;
|
||||
|
||||
ll best_diff = MIN<ll>();
|
||||
ve<ll> ans;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
auto diff = a[i] - b[i];
|
||||
if (diff > best_diff) {
|
||||
best_diff = diff;
|
||||
ans = {i};
|
||||
} else if (diff == best_diff) {
|
||||
ans.eb(i);
|
||||
}
|
||||
}
|
||||
|
||||
prln("{}", ans.size());
|
||||
for (auto& e : ans)
|
||||
pr("{} ", e + 1);
|
||||
prln();
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
16
codeforces/891/d.in
Normal file
16
codeforces/891/d.in
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
5
|
||||
4
|
||||
3 1 2 4
|
||||
4 3 2 1
|
||||
5
|
||||
1 2 4 1 2
|
||||
5 2 3 3 1
|
||||
2
|
||||
1 2
|
||||
2 1
|
||||
3
|
||||
0 2 1
|
||||
1 3 2
|
||||
3
|
||||
5 7 4
|
||||
-2 -3 -6
|
||||
13
codeforces/891/d.out
Normal file
13
codeforces/891/d.out
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
1
|
||||
4
|
||||
2
|
||||
3 5
|
||||
1
|
||||
2
|
||||
3
|
||||
1 2 3
|
||||
2
|
||||
2 3
|
||||
|
||||
[code]: 0
|
||||
[time]: 14.0336 ms
|
||||
155
codeforces/891/e.cc
Normal file
155
codeforces/891/e.cc
Normal file
|
|
@ -0,0 +1,155 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MIN() {
|
||||
return std::numeric_limits<T>::min();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MAX() {
|
||||
return std::numeric_limits<T>::max();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto&& x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto&& x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
|
||||
#define prln(...) std::println(__VA_ARGS__)
|
||||
#define pr(...) std::print(__VA_ARGS__)
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbgln(...) std::println(__VA_ARGS__)
|
||||
#define dbg(...) std::print(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
inline static void NO() {
|
||||
prln("NO");
|
||||
}
|
||||
|
||||
inline static void YES() {
|
||||
prln("YES");
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using ve = std::vector<T>;
|
||||
template <typename T, size_t N>
|
||||
using ar = std::array<T, N>;
|
||||
template <typename T1, typename T2>
|
||||
using pa = std::pair<T1, T2>;
|
||||
template <typename... Ts>
|
||||
using tu = std::tuple<Ts...>;
|
||||
template <typename... Ts>
|
||||
using dq = std::deque<Ts...>;
|
||||
template <typename... Ts>
|
||||
using qu = std::queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using pq = std::priority_queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using st = std::stack<Ts...>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
int n;
|
||||
cin >> n;
|
||||
ve<pa<ll, int>> a(n);
|
||||
for (int i = 0; i < n; ++i) {
|
||||
cin >> a[i].ff;
|
||||
a[i].ss = i;
|
||||
}
|
||||
sort(all(a));
|
||||
ve<ll> prefix(n + 1, 0), postfix(n + 2, 0);
|
||||
for (int i = 0; i < n; ++i) {
|
||||
prefix[i + 1] = prefix[i] + a[i].ff;
|
||||
}
|
||||
for (int i = n - 1; i >= 0; --i) {
|
||||
postfix[i + 1] = postfix[i + 2] + a[i].ff;
|
||||
}
|
||||
|
||||
ve<ll> ans(n);
|
||||
for (int i = 0; i < n; ++i) {
|
||||
ll x = n + a[i].ff * (i + 1) - prefix[i + 1];
|
||||
x += postfix[i + 2] - a[i].ff * (n - i - 1);
|
||||
ans[a[i].ss] = x;
|
||||
}
|
||||
|
||||
for (auto& e : ans)
|
||||
pr("{} ", e);
|
||||
prln();
|
||||
/*
|
||||
1 3 4
|
||||
|
||||
3 + 0 +
|
||||
|
||||
to query @ i, want to get info related to
|
||||
a[i] - a[0], a[i] - a[1], ....
|
||||
|
||||
prefix differences + postfix differences for each index
|
||||
|
||||
n + a[i] - a[0] + a[i] - a[1] + ... + a[i] - a[i] + a[j] - a[i] + a[j + 1]
|
||||
- a[i]
|
||||
|
||||
= n + a[i] * (i + 1) - prefix[i] (inclusive) + postfix[i] (exclusive) -
|
||||
a[i] * ``
|
||||
|
||||
n * a[i] - sum of prefix before i + sum of postfix after i
|
||||
|
||||
sum a[i] - a[j] + 1 for j in range(i + 1)
|
||||
count how manny points before us? * a[i]
|
||||
remove prefix sum up to j
|
||||
- and postfix! <- note this
|
||||
|
||||
*-**
|
||||
-
|
||||
---
|
||||
----
|
||||
|
||||
---
|
||||
-
|
||||
--
|
||||
|
||||
----
|
||||
--
|
||||
-
|
||||
|
||||
really, we're just adding the inclusive distance between ALL pairs
|
||||
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
7
codeforces/891/e.in
Normal file
7
codeforces/891/e.in
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
3
|
||||
3
|
||||
1 4 3
|
||||
5
|
||||
1 2 5 7 1
|
||||
4
|
||||
1 10 100 1000
|
||||
6
codeforces/891/e.out
Normal file
6
codeforces/891/e.out
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
8 7 6
|
||||
16 15 18 24 16
|
||||
1111 1093 1093 2893
|
||||
|
||||
[code]: 0
|
||||
[time]: 13.531 ms
|
||||
223
codeforces/891/f.cc
Normal file
223
codeforces/891/f.cc
Normal file
|
|
@ -0,0 +1,223 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MIN() {
|
||||
return std::numeric_limits<T>::min();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MAX() {
|
||||
return std::numeric_limits<T>::max();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto &&x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto &&x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
|
||||
#define prln(...) std::println(__VA_ARGS__)
|
||||
#define pr(...) std::print(__VA_ARGS__)
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbgln(...) std::println(__VA_ARGS__)
|
||||
#define dbg(...) std::print(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
inline static void NO() {
|
||||
prln("NO");
|
||||
}
|
||||
|
||||
inline static void YES() {
|
||||
prln("YES");
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using ve = std::vector<T>;
|
||||
template <typename T, size_t N>
|
||||
using ar = std::array<T, N>;
|
||||
template <typename T1, typename T2>
|
||||
using pa = std::pair<T1, T2>;
|
||||
template <typename... Ts>
|
||||
using tu = std::tuple<Ts...>;
|
||||
template <typename... Ts>
|
||||
using dq = std::deque<Ts...>;
|
||||
template <typename... Ts>
|
||||
using qu = std::queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using pq = std::priority_queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using st = std::stack<Ts...>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
// }}}
|
||||
|
||||
#include <ext/pb_ds/assoc_container.hpp>
|
||||
#include <ext/pb_ds/tree_policy.hpp>
|
||||
|
||||
using namespace __gnu_pbds;
|
||||
|
||||
// https://mirror.codeforces.com/blog/entry/124683
|
||||
|
||||
namespace hashing {
|
||||
using i64 = std::int64_t;
|
||||
using u64 = std::uint64_t;
|
||||
static const u64 FIXED_RANDOM =
|
||||
std::chrono::steady_clock::now().time_since_epoch().count();
|
||||
|
||||
#if USE_AES
|
||||
std::mt19937 rd(FIXED_RANDOM);
|
||||
const __m128i KEY1{(i64)rd(), (i64)rd()};
|
||||
const __m128i KEY2{(i64)rd(), (i64)rd()};
|
||||
#endif
|
||||
|
||||
template <class T, class D = void>
|
||||
struct custom_hash {};
|
||||
|
||||
template <class T>
|
||||
inline void hash_combine(u64 &seed, T const &v) {
|
||||
custom_hash<T> hasher;
|
||||
seed ^= hasher(v) + 0x9e3779b97f4a7c15 + (seed << 12) + (seed >> 4);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct custom_hash<T,
|
||||
typename std::enable_if<std::is_integral<T>::value>::type> {
|
||||
u64 operator()(T _x) const {
|
||||
u64 x = _x;
|
||||
#if USE_AES
|
||||
__m128i m{i64(u64(x) * 0xbf58476d1ce4e5b9u64), (i64)FIXED_RANDOM};
|
||||
__m128i y = _mm_aesenc_si128(m, KEY1);
|
||||
__m128i z = _mm_aesenc_si128(y, KEY2);
|
||||
return z[0];
|
||||
#else
|
||||
x += 0x9e3779b97f4a7c15 + FIXED_RANDOM;
|
||||
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
|
||||
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
|
||||
return x ^ (x >> 31);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct custom_hash<T, std::void_t<decltype(std::begin(std::declval<T>()))>> {
|
||||
u64 operator()(T const &a) const {
|
||||
u64 value = FIXED_RANDOM;
|
||||
for (auto &x : a)
|
||||
hash_combine(value, x);
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
template <class... T>
|
||||
struct custom_hash<std::tuple<T...>> {
|
||||
u64 operator()(const std::tuple<T...> &a) const {
|
||||
u64 value = FIXED_RANDOM;
|
||||
std::apply(
|
||||
[&value](T const &...args) {
|
||||
(hash_combine(value, args), ...);
|
||||
},
|
||||
a);
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class U>
|
||||
struct custom_hash<std::pair<T, U>> {
|
||||
u64 operator()(std::pair<T, U> const &a) const {
|
||||
u64 value = FIXED_RANDOM;
|
||||
hash_combine(value, a.first);
|
||||
hash_combine(value, a.second);
|
||||
return value;
|
||||
}
|
||||
};
|
||||
}; // namespace hashing
|
||||
|
||||
#ifdef PB_DS_ASSOC_CNTNR_HPP
|
||||
template <class Key, class Value = null_type>
|
||||
using hashtable = gp_hash_table<
|
||||
Key, Value, hashing::custom_hash<Key>, std::equal_to<Key>,
|
||||
direct_mask_range_hashing<>, linear_probe_fn<>,
|
||||
hash_standard_resize_policy<hash_exponential_size_policy<>,
|
||||
hash_load_check_resize_trigger<>, true>>;
|
||||
|
||||
#endif
|
||||
#ifdef PB_DS_TREE_POLICY_HPP
|
||||
template <typename T>
|
||||
using multitree = tree<T, null_type, std::less_equal<T>, rb_tree_tag,
|
||||
tree_order_statistics_node_update>;
|
||||
template <class Key, class Value = null_type>
|
||||
using rbtree = tree<Key, Value, std::less<Key>, rb_tree_tag,
|
||||
tree_order_statistics_node_update>;
|
||||
#endif
|
||||
|
||||
void solve() {
|
||||
int n;
|
||||
cin >> n;
|
||||
ve<ll> a(n);
|
||||
hashtable<ll, ll> freq;
|
||||
for (auto &e : a) {
|
||||
cin >> e;
|
||||
++freq[e];
|
||||
}
|
||||
int q;
|
||||
cin >> q;
|
||||
while (q--) {
|
||||
ll x, y;
|
||||
cin >> x >> y;
|
||||
|
||||
if (x * x < 4 * y) {
|
||||
pr("0 ");
|
||||
continue;
|
||||
}
|
||||
|
||||
ll root = sqrtl(powl(x, 2) - 4 * y);
|
||||
|
||||
ll r0 = (x + root) / 2;
|
||||
ll r1 = (x - root) / 2;
|
||||
|
||||
if (r0 + r1 != x || r0 * r1 != y) {
|
||||
pr("0 ");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (r0 == r1) {
|
||||
pr("{} ", (freq[r0] - 1) * freq[r0] / 2);
|
||||
} else
|
||||
pr("{} ", freq[r0] * freq[r1]);
|
||||
}
|
||||
prln();
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
18
codeforces/891/f.in
Normal file
18
codeforces/891/f.in
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
3
|
||||
3
|
||||
1 3 2
|
||||
4
|
||||
3 2
|
||||
5 6
|
||||
3 1
|
||||
5 5
|
||||
4
|
||||
1 1 1 1
|
||||
1
|
||||
2 1
|
||||
6
|
||||
1 4 -2 3 3 3
|
||||
3
|
||||
2 -8
|
||||
-1 -2
|
||||
7 12
|
||||
6
codeforces/891/f.out
Normal file
6
codeforces/891/f.out
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
1 1 0 0
|
||||
6
|
||||
1 1 3
|
||||
|
||||
[code]: 0
|
||||
[time]: 12.9466 ms
|
||||
Loading…
Add table
Add a link
Reference in a new issue