feat(codeforces): 964)
This commit is contained in:
parent
805d60fefc
commit
0cb0d11ba9
26 changed files with 1131 additions and 0 deletions
9
codeforces/964/.clang-format
Normal file
9
codeforces/964/.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
|
||||
79
codeforces/964/a.cc
Normal file
79
codeforces/964/a.cc
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
#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... Args> void dbg(std::string const &str, Args &&...args) {
|
||||
std::cout << std::vformat(str, std::make_format_args(args...));
|
||||
}
|
||||
|
||||
template <typename T> void dbg(T const &t) { std::cout << t; }
|
||||
|
||||
template <std::ranges::range T> void dbgln(T const &t) {
|
||||
if constexpr (std::is_convertible_v<T, char const *>) {
|
||||
std::cout << t << '\n';
|
||||
} else {
|
||||
for (auto const &e : t) {
|
||||
std::cout << e << ' ';
|
||||
}
|
||||
std::cout << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
void dbgln() { std::cout << '\n'; }
|
||||
|
||||
template <typename... Args> void dbgln(std::string const &str, Args &&...args) {
|
||||
dbg(str, std::forward<Args>(args)...);
|
||||
cout << '\n';
|
||||
}
|
||||
|
||||
template <typename T> void dbgln(T const &t) {
|
||||
dbg(t);
|
||||
cout << '\n';
|
||||
}
|
||||
|
||||
template <typename T> constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T> constexpr T MAX = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T> static T sc(auto &&x) { return static_cast<T>(x); }
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define ll long long
|
||||
#define ld long double
|
||||
#define vec vector
|
||||
#define endl '\n'
|
||||
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (r).rbegin(), (x).rend()
|
||||
#define sz(x) static_cast<int>((x).size())
|
||||
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
|
||||
#define ROF(a, b, c) for (int(a) = (b); (a) > (c); --(a))
|
||||
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
|
||||
void solve() {
|
||||
int n;
|
||||
cin >> n;
|
||||
cout << (n % 10) + n / 10 << endl;
|
||||
}
|
||||
|
||||
int main() {
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
9
codeforces/964/a.in
Normal file
9
codeforces/964/a.in
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
8
|
||||
77
|
||||
21
|
||||
40
|
||||
34
|
||||
19
|
||||
84
|
||||
10
|
||||
99
|
||||
8
codeforces/964/a.out
Normal file
8
codeforces/964/a.out
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
14
|
||||
3
|
||||
4
|
||||
7
|
||||
10
|
||||
12
|
||||
1
|
||||
18
|
||||
100
codeforces/964/b.cc
Normal file
100
codeforces/964/b.cc
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
#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... Args>
|
||||
void dbg(std::string const &str, Args &&...args) {
|
||||
std::cout << std::vformat(str, std::make_format_args(args...));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void dbg(T const &t) {
|
||||
std::cout << t;
|
||||
}
|
||||
|
||||
template <std::ranges::range T>
|
||||
void dbgln(T const &t) {
|
||||
if constexpr (std::is_convertible_v<T, char const *>) {
|
||||
std::cout << t << '\n';
|
||||
} else {
|
||||
for (auto const &e : t) {
|
||||
std::cout << e << ' ';
|
||||
}
|
||||
std::cout << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
void dbgln() {
|
||||
std::cout << '\n';
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void dbgln(std::string const &str, Args &&...args) {
|
||||
dbg(str, std::forward<Args>(args)...);
|
||||
cout << '\n';
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void dbgln(T const &t) {
|
||||
dbg(t);
|
||||
cout << '\n';
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
static T sc(auto &&x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define ll long long
|
||||
#define ld long double
|
||||
#define vec vector
|
||||
#define endl '\n'
|
||||
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (r).rbegin(), (x).rend()
|
||||
#define sz(x) static_cast<int>((x).size())
|
||||
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
|
||||
#define ROF(a, b, c) for (int(a) = (b); (a) > (c); --(a))
|
||||
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
|
||||
void solve() {
|
||||
int A, B, C, D;
|
||||
cin >> A >> B >> C >> D;
|
||||
|
||||
auto count = [](int a, int b, int c, int d) {
|
||||
return int(a > c && b >= d) + int(a == c && b > d);
|
||||
};
|
||||
|
||||
cout << (count(A, B, C, D) + count(A, B, D, C) + count(B, A, C, D) +
|
||||
count(B, A, D, C))
|
||||
<< endl;
|
||||
}
|
||||
|
||||
int main() {
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
6
codeforces/964/b.in
Normal file
6
codeforces/964/b.in
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
5
|
||||
3 8 2 6
|
||||
1 1 1 1
|
||||
10 10 2 2
|
||||
1 1 10 10
|
||||
3 8 7 2
|
||||
5
codeforces/964/b.out
Normal file
5
codeforces/964/b.out
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
2
|
||||
0
|
||||
4
|
||||
0
|
||||
2
|
||||
118
codeforces/964/c.cc
Normal file
118
codeforces/964/c.cc
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
#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... Args>
|
||||
void dbg(std::string const &str, Args &&...args) {
|
||||
std::cout << std::vformat(str, std::make_format_args(args...));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void dbg(T const &t) {
|
||||
std::cout << t;
|
||||
}
|
||||
|
||||
template <std::ranges::range T>
|
||||
void dbgln(T const &t) {
|
||||
if constexpr (std::is_convertible_v<T, char const *>) {
|
||||
std::cout << t << '\n';
|
||||
} else {
|
||||
for (auto const &e : t) {
|
||||
std::cout << e << ' ';
|
||||
}
|
||||
std::cout << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
void dbgln() {
|
||||
std::cout << '\n';
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void dbgln(std::string const &str, Args &&...args) {
|
||||
dbg(str, std::forward<Args>(args)...);
|
||||
cout << '\n';
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void dbgln(T const &t) {
|
||||
dbg(t);
|
||||
cout << '\n';
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
static T sc(auto &&x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
static void YES() {
|
||||
dbgln("YES");
|
||||
}
|
||||
static void NO() {
|
||||
dbgln("NO");
|
||||
}
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define ll long long
|
||||
#define ld long double
|
||||
#define vec vector
|
||||
#define endl '\n'
|
||||
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (r).rbegin(), (x).rend()
|
||||
#define sz(x) static_cast<int>((x).size())
|
||||
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
|
||||
#define ROF(a, b, c) for (int(a) = (b); (a) > (c); --(a))
|
||||
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
|
||||
void solve() {
|
||||
int n, s, m;
|
||||
cin >> n >> s >> m;
|
||||
|
||||
int prev = 0;
|
||||
bool can = 0;
|
||||
|
||||
while (n--) {
|
||||
int l, r;
|
||||
cin >> l >> r;
|
||||
if (l - prev >= s)
|
||||
can |= 1;
|
||||
prev = r;
|
||||
}
|
||||
|
||||
if (m - prev >= s)
|
||||
can |= 1;
|
||||
|
||||
if (can)
|
||||
YES();
|
||||
else
|
||||
NO();
|
||||
}
|
||||
|
||||
int main() {
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
17
codeforces/964/c.in
Normal file
17
codeforces/964/c.in
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
4
|
||||
3 3 10
|
||||
3 5
|
||||
6 8
|
||||
9 10
|
||||
3 3 10
|
||||
1 2
|
||||
3 5
|
||||
6 7
|
||||
3 3 10
|
||||
1 2
|
||||
3 5
|
||||
6 8
|
||||
3 4 10
|
||||
1 2
|
||||
6 7
|
||||
8 9
|
||||
4
codeforces/964/c.out
Normal file
4
codeforces/964/c.out
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
YES
|
||||
YES
|
||||
NO
|
||||
YES
|
||||
5
codeforces/964/compile_flags.txt
Normal file
5
codeforces/964/compile_flags.txt
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
-std=c++20
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wpedantic
|
||||
-Wshadow
|
||||
125
codeforces/964/d.cc
Normal file
125
codeforces/964/d.cc
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
#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... Args>
|
||||
void dbg(std::string const &str, Args &&...args) {
|
||||
std::cout << std::vformat(str, std::make_format_args(args...));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void dbg(T const &t) {
|
||||
std::cout << t;
|
||||
}
|
||||
|
||||
template <std::ranges::range T>
|
||||
void dbgln(T const &t) {
|
||||
if constexpr (std::is_convertible_v<T, char const *>) {
|
||||
std::cout << t << '\n';
|
||||
} else {
|
||||
for (auto const &e : t) {
|
||||
std::cout << e << ' ';
|
||||
}
|
||||
std::cout << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
void dbgln() {
|
||||
std::cout << '\n';
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void dbgln(std::string const &str, Args &&...args) {
|
||||
dbg(str, std::forward<Args>(args)...);
|
||||
cout << '\n';
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void dbgln(T const &t) {
|
||||
dbg(t);
|
||||
cout << '\n';
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
static T sc(auto &&x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
static void YES() {
|
||||
dbgln("YES");
|
||||
}
|
||||
static void NO() {
|
||||
dbgln("NO");
|
||||
}
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define ll long long
|
||||
#define ld long double
|
||||
#define vec vector
|
||||
#define endl '\n'
|
||||
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (r).rbegin(), (x).rend()
|
||||
#define sz(x) static_cast<int>((x).size())
|
||||
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
|
||||
#define ROF(a, b, c) for (int(a) = (b); (a) > (c); --(a))
|
||||
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
|
||||
void solve() {
|
||||
string s, t;
|
||||
cin >> s >> t;
|
||||
|
||||
if (sz(s) < sz(t)) {
|
||||
NO();
|
||||
return;
|
||||
}
|
||||
|
||||
int j = 0;
|
||||
FOR(i, 0, sz(s)) {
|
||||
if (j >= sz(t)) {
|
||||
if (s[i] == '?')
|
||||
s[i] = 'a';
|
||||
}
|
||||
if (s[i] != t[j]) {
|
||||
if (s[i] != '?')
|
||||
continue;
|
||||
s[i] = t[j++];
|
||||
} else if (s[i] == t[j])
|
||||
++j;
|
||||
}
|
||||
|
||||
if (j < sz(t)) {
|
||||
NO();
|
||||
} else {
|
||||
YES();
|
||||
dbgln(s);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
13
codeforces/964/d.in
Normal file
13
codeforces/964/d.in
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
6
|
||||
a?b?c?d??
|
||||
xxx
|
||||
?????
|
||||
xbx
|
||||
ab??e
|
||||
abcde
|
||||
ayy?x
|
||||
a
|
||||
ab??e
|
||||
dac
|
||||
paiu
|
||||
mom
|
||||
10
codeforces/964/d.out
Normal file
10
codeforces/964/d.out
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
YES
|
||||
axbxcxdaa
|
||||
YES
|
||||
xbxaa
|
||||
YES
|
||||
abcde
|
||||
YES
|
||||
ayyax
|
||||
NO
|
||||
NO
|
||||
139
codeforces/964/e.cc
Normal file
139
codeforces/964/e.cc
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
#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... Args>
|
||||
void dbg(std::string const &str, Args &&...args) {
|
||||
std::cout << std::vformat(str, std::make_format_args(args...));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void dbg(T const &t) {
|
||||
std::cout << t;
|
||||
}
|
||||
|
||||
template <std::ranges::range T>
|
||||
void dbgln(T const &t) {
|
||||
if constexpr (std::is_convertible_v<T, char const *>) {
|
||||
std::cout << t << '\n';
|
||||
} else {
|
||||
for (auto const &e : t) {
|
||||
std::cout << e << ' ';
|
||||
}
|
||||
std::cout << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
void dbgln() {
|
||||
std::cout << '\n';
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void dbgln(std::string const &str, Args &&...args) {
|
||||
dbg(str, std::forward<Args>(args)...);
|
||||
cout << '\n';
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void dbgln(T const &t) {
|
||||
dbg(t);
|
||||
cout << '\n';
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
static T sc(auto &&x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define ll long long
|
||||
#define ld long double
|
||||
#define vec vector
|
||||
#define endl '\n'
|
||||
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (r).rbegin(), (x).rend()
|
||||
#define sz(x) static_cast<int>((x).size())
|
||||
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
|
||||
#define ROF(a, b, c) for (int(a) = (b); (a) > (c); --(a))
|
||||
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
|
||||
long long power(long long base, long long exp) {
|
||||
long long result = 1;
|
||||
while (exp > 0) {
|
||||
if (exp & 1)
|
||||
result *= base;
|
||||
base *= base;
|
||||
exp >>= 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ll log_baseb(ll x, ll b) {
|
||||
ll res = 0;
|
||||
while (x >= b) {
|
||||
x /= b;
|
||||
res++;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
ll ceil_log_baseb(ll x, ll base) {
|
||||
ll res = 0, power = 1;
|
||||
while (power < x) {
|
||||
power *= base;
|
||||
res++;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void solve() {
|
||||
ll l, r;
|
||||
cin >> l >> r;
|
||||
|
||||
ll ans = l == 1 ? 1 : 1 + log_baseb(l, 3);
|
||||
if (r - l + 1 > 1)
|
||||
ans *= 2;
|
||||
|
||||
// add on count to reduce range [l+1,r] to 0
|
||||
|
||||
ll L = l + 1;
|
||||
|
||||
while (L <= r) {
|
||||
ll B = min(r + 1, (ll)power(3, 1 + log_baseb(L, 3)));
|
||||
// dbgln("floor(log({})/log(3))={}", L, log_baseb(L, 3));
|
||||
// dbgln("L={}, B={}", L, B);
|
||||
ans += ceil_log_baseb(B, 3) * (B - L);
|
||||
L = B;
|
||||
}
|
||||
|
||||
dbgln(ans);
|
||||
}
|
||||
|
||||
int main() {
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
6
codeforces/964/e.in
Normal file
6
codeforces/964/e.in
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
5
|
||||
1 3
|
||||
2 4
|
||||
199999 200000
|
||||
19 84
|
||||
10 100000000
|
||||
7
codeforces/964/e.out
Normal file
7
codeforces/964/e.out
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
5
|
||||
6
|
||||
36
|
||||
263
|
||||
1635429922
|
||||
|
||||
24:10 03/02/25
|
||||
151
codeforces/964/f.cc
Normal file
151
codeforces/964/f.cc
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
#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... Args>
|
||||
void dbg(std::string const &str, Args &&...args) {
|
||||
std::cout << std::vformat(str, std::make_format_args(args...));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void dbg(T const &t) {
|
||||
std::cout << t;
|
||||
}
|
||||
|
||||
template <std::ranges::range T>
|
||||
void dbgln(T const &t) {
|
||||
if constexpr (std::is_convertible_v<T, char const *>) {
|
||||
std::cout << t << '\n';
|
||||
} else {
|
||||
for (auto const &e : t) {
|
||||
std::cout << e << ' ';
|
||||
}
|
||||
std::cout << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
void dbgln() {
|
||||
std::cout << '\n';
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void dbgln(std::string const &str, Args &&...args) {
|
||||
dbg(str, std::forward<Args>(args)...);
|
||||
cout << '\n';
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void dbgln(T const &t) {
|
||||
dbg(t);
|
||||
cout << '\n';
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
static T sc(auto &&x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define ll long long
|
||||
#define ld long double
|
||||
#define vec vector
|
||||
#define endl '\n'
|
||||
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (r).rbegin(), (x).rend()
|
||||
#define sz(x) static_cast<int>((x).size())
|
||||
#define FOR(a, b, c) for (int a = (b); a < (c); ++a)
|
||||
#define ROF(a, b, c) for (int a = (b); a > (c); --a)
|
||||
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
|
||||
static constexpr int MOD = 1000000007;
|
||||
static constexpr int MAX_N = 2 * 100000 + 1;
|
||||
|
||||
static vec<ll> fac(MAX_N + 1, 1);
|
||||
bitset<MAX_N> seen;
|
||||
|
||||
void solve() {
|
||||
int n, k;
|
||||
cin >> n >> k;
|
||||
vec<int> a(n);
|
||||
seen.reset();
|
||||
for (auto &e : a) {
|
||||
cin >> e;
|
||||
}
|
||||
sort(all(a));
|
||||
|
||||
ll ans = 0;
|
||||
dbgln("----------------------");
|
||||
dbgln(a);
|
||||
|
||||
FOR(i, 0, n) {
|
||||
if (a[i] == 0 || seen[a[i]])
|
||||
continue;
|
||||
seen[a[i]] = true;
|
||||
// count <=, >=
|
||||
int lt = distance(a.begin(), lower_bound(all(a), a[i]));
|
||||
int gt = distance(upper_bound(all(a), a[i]), a.end());
|
||||
int eq = n - lt - gt - 1;
|
||||
|
||||
if (lt + eq < k / 2)
|
||||
continue;
|
||||
eq -= max(0, k / 2 - lt);
|
||||
if (gt + eq < k / 2)
|
||||
continue;
|
||||
eq -= max(0, k / 2 - gt);
|
||||
|
||||
dbgln("x={}, lt={}, gt={}, remaining eq={}", a[i], lt, gt, eq);
|
||||
ans = (ans + (max(1, lt) * max(1, gt)) % MOD) % MOD;
|
||||
|
||||
// count =
|
||||
int left = eq;
|
||||
if (lt < k / 2)
|
||||
eq -= k / 2 - lt;
|
||||
if (gt < k / 2)
|
||||
eq -= k / 2 - gt;
|
||||
|
||||
// - max(0, (k / 2 - lt)) - max(0, (k / 2 - gt)) + 1;
|
||||
// dbgln("with element {}, have {} choices", a[i], left);
|
||||
// FOR(i, 1, left) {
|
||||
// ll nci = fac[left] / (fac[i] * fac[left - i]);
|
||||
// dbgln("n={} choose i={}, nci={}", n, i, nci);
|
||||
// ans = (ans + nci) % MOD;
|
||||
// }
|
||||
// }
|
||||
|
||||
dbgln(ans);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
fac[0] = 1LL;
|
||||
FOR(i, 1, MAX_N + 1) {
|
||||
fac[i] = i * fac[i - 1];
|
||||
}
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
19
codeforces/964/f.in
Normal file
19
codeforces/964/f.in
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
9
|
||||
4 3
|
||||
1 0 0 1
|
||||
5 1
|
||||
1 1 1 1 1
|
||||
5 5
|
||||
0 1 0 1 0
|
||||
6 3
|
||||
1 0 1 0 1 1
|
||||
4 3
|
||||
1 0 1 1
|
||||
5 3
|
||||
1 0 1 1 0
|
||||
2 1
|
||||
0 0
|
||||
34 17
|
||||
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
|
||||
4 3
|
||||
0 1 2 2
|
||||
34
codeforces/964/f.out
Normal file
34
codeforces/964/f.out
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
----------------------
|
||||
0 0 1 1
|
||||
x=1, lt=2, gt=0, remaining eq=0
|
||||
2
|
||||
----------------------
|
||||
1 1 1 1 1
|
||||
x=1, lt=0, gt=0, remaining eq=4
|
||||
1
|
||||
----------------------
|
||||
0 0 0 1 1
|
||||
----------------------
|
||||
0 0 1 1 1 1
|
||||
x=1, lt=2, gt=0, remaining eq=2
|
||||
2
|
||||
----------------------
|
||||
0 1 1 1
|
||||
x=1, lt=1, gt=0, remaining eq=1
|
||||
1
|
||||
----------------------
|
||||
0 0 1 1 1
|
||||
x=1, lt=2, gt=0, remaining eq=1
|
||||
2
|
||||
----------------------
|
||||
0 0
|
||||
----------------------
|
||||
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
|
||||
x=1, lt=0, gt=0, remaining eq=17
|
||||
1
|
||||
----------------------
|
||||
0 1 2 2
|
||||
x=1, lt=1, gt=2, remaining eq=0
|
||||
2
|
||||
x=2, lt=2, gt=0, remaining eq=0
|
||||
4
|
||||
114
codeforces/964/g1.cc
Normal file
114
codeforces/964/g1.cc
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
#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... Args>
|
||||
void dbg(std::string const &str, Args &&...args) {
|
||||
std::cout << std::vformat(str, std::make_format_args(args...));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void dbg(T const &t) {
|
||||
std::cout << t;
|
||||
}
|
||||
|
||||
template <std::ranges::range T>
|
||||
void dbgln(T const &t) {
|
||||
if constexpr (std::is_convertible_v<T, char const *>) {
|
||||
std::cout << t << '\n';
|
||||
} else {
|
||||
for (auto const &e : t) {
|
||||
std::cout << e << ' ';
|
||||
}
|
||||
std::cout << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
void dbgln() {
|
||||
std::cout << '\n';
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void dbgln(std::string const &str, Args &&...args) {
|
||||
dbg(str, std::forward<Args>(args)...);
|
||||
cout << '\n';
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void dbgln(T const &t) {
|
||||
dbg(t);
|
||||
cout << '\n';
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
static T sc(auto &&x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
static void NO() {
|
||||
std::cout << "NO\n";
|
||||
}
|
||||
|
||||
static void YES() {
|
||||
std::cout << "YES\n";
|
||||
}
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define ll long long
|
||||
#define ld long double
|
||||
#define vec vector
|
||||
#define endl '\n'
|
||||
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (r).rbegin(), (x).rend()
|
||||
#define sz(x) static_cast<int>((x).size())
|
||||
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
|
||||
#define ROF(a, b, c) for (int(a) = (b); (a) > (c); --(a))
|
||||
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
|
||||
void solve() {
|
||||
int l = 2, r = 1000;
|
||||
|
||||
while (l <= r) {
|
||||
int m = l + (r - l) / 2;
|
||||
|
||||
dbgln("? {} {}", m, m);
|
||||
cout.flush();
|
||||
int area;
|
||||
cin >> area;
|
||||
if (area == m * m) {
|
||||
l = m + 1;
|
||||
} else {
|
||||
r = m - 1;
|
||||
}
|
||||
}
|
||||
|
||||
dbgln("! {}", l);
|
||||
}
|
||||
|
||||
int main() {
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--)
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
8
codeforces/964/g1.in
Normal file
8
codeforces/964/g1.in
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
2
|
||||
|
||||
18
|
||||
|
||||
25
|
||||
|
||||
|
||||
9999
|
||||
0
codeforces/964/g1.out
Normal file
0
codeforces/964/g1.out
Normal file
134
codeforces/964/g2.cc
Normal file
134
codeforces/964/g2.cc
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
#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... Args>
|
||||
void dbg(std::string const &str, Args &&...args) {
|
||||
std::cout << std::vformat(str, std::make_format_args(args...));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void dbg(T const &t) {
|
||||
std::cout << t;
|
||||
}
|
||||
|
||||
template <std::ranges::range T>
|
||||
void dbgln(T const &t) {
|
||||
if constexpr (std::is_convertible_v<T, char const *>) {
|
||||
std::cout << t << '\n';
|
||||
} else {
|
||||
for (auto const &e : t) {
|
||||
std::cout << e << ' ';
|
||||
}
|
||||
std::cout << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
void dbgln() {
|
||||
std::cout << '\n';
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void dbgln(std::string const &str, Args &&...args) {
|
||||
dbg(str, std::forward<Args>(args)...);
|
||||
cout << '\n';
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void dbgln(T const &t) {
|
||||
dbg(t);
|
||||
cout << '\n';
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
static T sc(auto &&x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
static void NO() {
|
||||
std::cout << "NO\n";
|
||||
}
|
||||
|
||||
static void YES() {
|
||||
std::cout << "YES\n";
|
||||
}
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define ll long long
|
||||
#define ld long double
|
||||
#define vec vector
|
||||
#define endl '\n'
|
||||
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (r).rbegin(), (x).rend()
|
||||
#define sz(x) static_cast<int>((x).size())
|
||||
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
|
||||
#define ROF(a, b, c) for (int(a) = (b); (a) > (c); --(a))
|
||||
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
|
||||
void solve() {
|
||||
int l = 2, r = 999;
|
||||
|
||||
while (l < r) {
|
||||
int x, y;
|
||||
|
||||
if (r - l == 1) {
|
||||
dbgln("? {} {}", l, l);
|
||||
cout.flush();
|
||||
int area;
|
||||
cin >> area;
|
||||
if (area != (l + 1) * (l + 1)) {
|
||||
l = r;
|
||||
}
|
||||
break;
|
||||
} else if (r - l == 2) {
|
||||
x = l + 1, y = r - 1;
|
||||
} else {
|
||||
x = l + (r - l) / 3;
|
||||
y = r - (r - l) / 3;
|
||||
}
|
||||
|
||||
dbgln("? {} {}", x, y);
|
||||
cout.flush();
|
||||
int area;
|
||||
cin >> area;
|
||||
|
||||
if (area == x * y) {
|
||||
l = y + 1;
|
||||
} else if (area == x * (y + 1)) {
|
||||
l = x + 1;
|
||||
r = y;
|
||||
} else {
|
||||
r = x;
|
||||
}
|
||||
}
|
||||
|
||||
dbgln("! {}", l);
|
||||
}
|
||||
|
||||
int main() {
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--)
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
0
codeforces/964/g2.in
Normal file
0
codeforces/964/g2.in
Normal file
11
codeforces/964/g2.out
Normal file
11
codeforces/964/g2.out
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
g2.cc: In function ‘int main()’:
|
||||
g2.cc:132:11: error: ‘i’ was not declared in this scope
|
||||
132 | solve(i);
|
||||
| ^
|
||||
g2.cc: At global scope:
|
||||
g2.cc:63:13: warning: ‘void YES()’ defined but not used [-Wunused-function]
|
||||
63 | static void YES() {
|
||||
| ^~~
|
||||
g2.cc:59:13: warning: ‘void NO()’ defined but not used [-Wunused-function]
|
||||
59 | static void NO() {
|
||||
| ^~
|
||||
Loading…
Add table
Add a link
Reference in a new issue