feat(cf/895): nonlazy prop soln
This commit is contained in:
parent
6c16185126
commit
94383fbaf7
99 changed files with 4536 additions and 0 deletions
9
codeforces/900/.clang-format
Normal file
9
codeforces/900/.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/900/.clangd
Normal file
8
codeforces/900/.clangd
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
CompileFlags:
|
||||
Add:
|
||||
- -Wall
|
||||
- -Wextra
|
||||
- -Wpedantic
|
||||
- -Wshadow
|
||||
- -DLOCAL
|
||||
- -Wno-unknown-pragmas
|
||||
105
codeforces/900/a.cc
Normal file
105
codeforces/900/a.cc
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
#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...>;
|
||||
auto lb = [](auto... args) {
|
||||
return std::lower_bound(args...);
|
||||
};
|
||||
auto ub = [](auto... args) {
|
||||
return std::upper_bound(args...);
|
||||
};
|
||||
|
||||
#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, k;
|
||||
cin >> n >> k;
|
||||
int x;
|
||||
bool good = false;
|
||||
while (n--) {
|
||||
cin >> x;
|
||||
if (x == k) good = true;
|
||||
}
|
||||
|
||||
if (good) YES(); else 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/900/a.in
Normal file
15
codeforces/900/a.in
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
7
|
||||
5 4
|
||||
1 4 3 4 1
|
||||
4 1
|
||||
2 3 4 4
|
||||
5 6
|
||||
43 5 60 4 2
|
||||
2 5
|
||||
1 5
|
||||
4 1
|
||||
5 3 3 1
|
||||
1 3
|
||||
3
|
||||
5 3
|
||||
3 4 1 5 5
|
||||
0
codeforces/900/a.out
Normal file
0
codeforces/900/a.out
Normal file
105
codeforces/900/b.cc
Normal file
105
codeforces/900/b.cc
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
#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...>;
|
||||
auto lb = [](auto... args) {
|
||||
return std::lower_bound(args...);
|
||||
};
|
||||
auto ub = [](auto... args) {
|
||||
return std::upper_bound(args...);
|
||||
};
|
||||
|
||||
#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;
|
||||
ll x = 1;
|
||||
|
||||
for (int i = 0; i < n; ++i) {
|
||||
pr("{} ", x);
|
||||
x += 2;
|
||||
}
|
||||
|
||||
prln();
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
2
codeforces/900/b.in
Normal file
2
codeforces/900/b.in
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
1
|
||||
200000
|
||||
4
codeforces/900/b.out
Normal file
4
codeforces/900/b.out
Normal file
File diff suppressed because one or more lines are too long
104
codeforces/900/c.cc
Normal file
104
codeforces/900/c.cc
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
#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...>;
|
||||
auto lb = [](auto... args) {
|
||||
return std::lower_bound(args...);
|
||||
};
|
||||
auto ub = [](auto... args) {
|
||||
return std::upper_bound(args...);
|
||||
};
|
||||
|
||||
#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() {
|
||||
ll n, k, x;
|
||||
cin >> n >> k >> x;
|
||||
ll small = k * (k + 1) / 2;
|
||||
ll large = n * (n + 1) / 2 - (n - k + 1) * (n - k) / 2;
|
||||
|
||||
if (small <= x && x <= large) {
|
||||
YES();
|
||||
} else
|
||||
NO();
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
14
codeforces/900/c.in
Normal file
14
codeforces/900/c.in
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
12
|
||||
5 3 10
|
||||
5 3 3
|
||||
10 10 55
|
||||
6 5 20
|
||||
2 1 26
|
||||
187856 87856 2609202300
|
||||
200000 190000 19000000000
|
||||
28 5 2004
|
||||
2 2 2006
|
||||
9 6 40
|
||||
47202 32455 613407217
|
||||
185977 145541 15770805980
|
||||
|
||||
15
codeforces/900/c.out
Normal file
15
codeforces/900/c.out
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
YES
|
||||
NO
|
||||
YES
|
||||
YES
|
||||
NO
|
||||
NO
|
||||
YES
|
||||
NO
|
||||
NO
|
||||
NO
|
||||
YES
|
||||
YES
|
||||
|
||||
[code]: 0
|
||||
[time]: 14.3909 ms
|
||||
6
codeforces/900/compile_flags.txt
Normal file
6
codeforces/900/compile_flags.txt
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
-Wall
|
||||
-Wextra
|
||||
-Wpedantic
|
||||
-Wshadow
|
||||
-DLOCAL
|
||||
-std=c++23
|
||||
157
codeforces/900/d.cc
Normal file
157
codeforces/900/d.cc
Normal file
|
|
@ -0,0 +1,157 @@
|
|||
#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...>;
|
||||
auto lb = [](auto... args) {
|
||||
return std::lower_bound(args...);
|
||||
};
|
||||
auto ub = [](auto... args) {
|
||||
return std::upper_bound(args...);
|
||||
};
|
||||
|
||||
#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()
|
||||
// }}}
|
||||
|
||||
string reverseIntervals(string s, vector<pair<int, int>>& intervals) {
|
||||
int n = s.length();
|
||||
vector<int> flip(n + 1, 0);
|
||||
|
||||
for (auto& interval : intervals) {
|
||||
int start = interval.ff, end = interval.ss;
|
||||
if (start >= 0 && end < n && start <= end) {
|
||||
flip[start]++;
|
||||
flip[end + 1]--;
|
||||
}
|
||||
}
|
||||
|
||||
int current = 0;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
current += flip[i];
|
||||
if (current % 2 == 1) {
|
||||
int j = n - 1 - i;
|
||||
if (i < j) {
|
||||
swap(s[i], s[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
void solve() {
|
||||
int k, n;
|
||||
cin >> n >> k;
|
||||
string s;
|
||||
cin >> s;
|
||||
ve<int> L(k), R(k);
|
||||
for (auto& e : L)
|
||||
cin >> e;
|
||||
for (auto& e : R)
|
||||
cin >> e;
|
||||
int q;
|
||||
cin >> q;
|
||||
int x;
|
||||
ve<pa<int, int>> intervals;
|
||||
while (q--) {
|
||||
cin >> x;
|
||||
|
||||
int l = 0, r = k - 1;
|
||||
|
||||
while (l <= r) {
|
||||
int m = l + (r - l) / 2;
|
||||
if (L[m] <= x) {
|
||||
l = m + 1;
|
||||
} else {
|
||||
r = m - 1;
|
||||
}
|
||||
}
|
||||
|
||||
int i = r;
|
||||
int left = min(x, R[i] + L[i] - x), right = max(x, R[i] + L[i] - x);
|
||||
|
||||
prln("{} {}", left - 1, right - 1);
|
||||
intervals.eb(left - 1, right - 1);
|
||||
}
|
||||
|
||||
string ans = reverseIntervals(s, intervals);
|
||||
prln("{}", ans);
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
31
codeforces/900/d.in
Normal file
31
codeforces/900/d.in
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
5
|
||||
4 2
|
||||
abcd
|
||||
1 3
|
||||
2 4
|
||||
1
|
||||
1
|
||||
5 3
|
||||
abcde
|
||||
1 2 3
|
||||
1 2 5
|
||||
3
|
||||
1 2 3
|
||||
3 1
|
||||
gaf
|
||||
1
|
||||
3
|
||||
2
|
||||
2 2
|
||||
10 1
|
||||
aghcdegdij
|
||||
1
|
||||
10
|
||||
5
|
||||
1 2 3 4 2
|
||||
1 1
|
||||
a
|
||||
1
|
||||
1
|
||||
1
|
||||
1
|
||||
20
codeforces/900/d.out
Normal file
20
codeforces/900/d.out
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
0 1
|
||||
dcba
|
||||
0 0
|
||||
1 1
|
||||
2 4
|
||||
edcba
|
||||
1 1
|
||||
1 1
|
||||
gaf
|
||||
0 9
|
||||
1 8
|
||||
2 7
|
||||
3 6
|
||||
1 8
|
||||
jihgedcdga
|
||||
0 0
|
||||
a
|
||||
|
||||
[code]: 0
|
||||
[time]: 14.6108 ms
|
||||
257
codeforces/900/e.cc
Normal file
257
codeforces/900/e.cc
Normal file
|
|
@ -0,0 +1,257 @@
|
|||
#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...>;
|
||||
auto lb = [](auto... args) {
|
||||
return std::lower_bound(args...);
|
||||
};
|
||||
auto ub = [](auto... args) {
|
||||
return std::upper_bound(args...);
|
||||
};
|
||||
|
||||
#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()
|
||||
// }}}
|
||||
|
||||
template <typename T>
|
||||
struct segment_tree {
|
||||
public:
|
||||
explicit segment_tree(std::vector<T> const& ts) : n(ts.size()) {
|
||||
tree.resize(4 * n);
|
||||
build(1, 0, n - 1, ts);
|
||||
}
|
||||
|
||||
[[nodiscard]] T const query(int const l, int const r) const {
|
||||
if (!(0 <= l && l <= r && r < static_cast<int>(n))) {
|
||||
throw std::out_of_range(
|
||||
"cannot query segment tree of size " + std::to_string(n) +
|
||||
" at range [" + std::to_string(l) + ", " + std::to_string(r) + "]");
|
||||
}
|
||||
|
||||
return query(1, 0, n - 1, l, r);
|
||||
}
|
||||
|
||||
void update(int i, T const& t) {
|
||||
if (!(0 <= i && i < static_cast<int>(n))) {
|
||||
throw std::out_of_range("cannot update segment tree of size " +
|
||||
std::to_string(n) + " at index " +
|
||||
std::to_string(i));
|
||||
}
|
||||
|
||||
update(1, 0, n - 1, i, t);
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t lower_bound(T const& t) const noexcept {
|
||||
return lower_bound(1, 0, n - 1, t);
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t upper_bound(T const& t) const noexcept {
|
||||
return upper_bound(1, 0, n - 1, t);
|
||||
}
|
||||
|
||||
private:
|
||||
inline T const sentinel() const noexcept {
|
||||
return -1LL;
|
||||
}
|
||||
|
||||
inline T const merge(T const& x, T const& y) const noexcept {
|
||||
return x & y;
|
||||
}
|
||||
|
||||
void build(size_t const node, size_t const l, size_t const r,
|
||||
std::vector<T> const& ts) noexcept {
|
||||
if (l == r) {
|
||||
tree[node] = ts[l];
|
||||
} else {
|
||||
int m = l + (r - l) / 2;
|
||||
build(2 * node, l, m, ts);
|
||||
build(2 * node + 1, m + 1, r, ts);
|
||||
tree[node] = merge(tree[2 * node], tree[2 * node + 1]);
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] T query(size_t const node, size_t const lower,
|
||||
size_t const upper, size_t const l,
|
||||
size_t const r) const noexcept {
|
||||
if (upper < l || r < lower) {
|
||||
return sentinel();
|
||||
}
|
||||
|
||||
if (l <= lower && upper <= r) {
|
||||
return tree[node];
|
||||
}
|
||||
|
||||
size_t m = lower + (upper - lower) / 2;
|
||||
|
||||
return merge(query(2 * node, lower, m, l, r),
|
||||
query(2 * node + 1, m + 1, upper, l, r));
|
||||
}
|
||||
|
||||
void update(size_t const node, size_t const l, size_t const r, size_t const i,
|
||||
T const& t) noexcept {
|
||||
if (l == r) {
|
||||
tree[node] = t;
|
||||
} else {
|
||||
size_t m = l + (r - l) / 2;
|
||||
if (i <= m) {
|
||||
update(2 * node, l, m, i, t);
|
||||
} else {
|
||||
update(2 * node + 1, m + 1, r, i, t);
|
||||
}
|
||||
tree[node] = merge(tree[2 * node], tree[2 * node + 1]);
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t lower_bound(size_t const node, size_t const l,
|
||||
size_t const r, T const& t) const noexcept {
|
||||
if (l == r) {
|
||||
return tree[node] >= t ? l : n;
|
||||
}
|
||||
|
||||
size_t m = l + (r - l) / 2;
|
||||
if (tree[2 * node] >= t) {
|
||||
size_t res = lower_bound(2 * node, l, m, t);
|
||||
if (res < n)
|
||||
return res;
|
||||
}
|
||||
|
||||
return lower_bound(2 * node + 1, m + 1, r, t);
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t upper_bound(size_t const node, size_t const l,
|
||||
size_t const r, T const& t) const noexcept {
|
||||
if (l == r) {
|
||||
return tree[node] > t ? l : n;
|
||||
}
|
||||
|
||||
size_t m = l + (r - l) / 2;
|
||||
if (tree[2 * node] > t) {
|
||||
size_t res = upper_bound(2 * node, l, m, t);
|
||||
if (res < n)
|
||||
return res;
|
||||
}
|
||||
|
||||
return upper_bound(2 * node + 1, m + 1, r, t);
|
||||
}
|
||||
|
||||
size_t n;
|
||||
std::vector<T> tree;
|
||||
};
|
||||
|
||||
void solve() {
|
||||
int n;
|
||||
cin >> n;
|
||||
ve<ll> a(n);
|
||||
for (auto& e : a)
|
||||
cin >> e;
|
||||
segment_tree<ll> st(a);
|
||||
int q;
|
||||
cin >> q;
|
||||
int L;
|
||||
ll k;
|
||||
while (q--) {
|
||||
cin >> L >> k;
|
||||
--L;
|
||||
int l = L;
|
||||
int r = n - 1;
|
||||
|
||||
while (l <= r) {
|
||||
int m = l + (r - l) / 2;
|
||||
|
||||
if (st.query(L, m) >= k) {
|
||||
l = m + 1;
|
||||
} else {
|
||||
r = m - 1;
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: messed up invalid queries, was confused
|
||||
// minor details of algorithms still cofnuse
|
||||
if (r < L)
|
||||
pr("-1 ");
|
||||
else
|
||||
pr("{} ", r + 1);
|
||||
|
||||
// NOTE: would like to be able to use builtin lower bound but knowledge not
|
||||
// good enough
|
||||
}
|
||||
prln();
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
21
codeforces/900/e.in
Normal file
21
codeforces/900/e.in
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
3
|
||||
5
|
||||
15 14 17 42 34
|
||||
3
|
||||
1 7
|
||||
2 15
|
||||
4 5
|
||||
5
|
||||
7 5 3 1 7
|
||||
4
|
||||
1 7
|
||||
5 7
|
||||
2 3
|
||||
2 2
|
||||
7
|
||||
19 20 15 12 21 7 11
|
||||
4
|
||||
1 15
|
||||
4 4
|
||||
7 12
|
||||
5 7
|
||||
6
codeforces/900/e.out
Normal file
6
codeforces/900/e.out
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
2 -1 5
|
||||
1 5 2 2
|
||||
2 6 -1 5
|
||||
|
||||
[code]: 0
|
||||
[time]: 13.607 ms
|
||||
Loading…
Add table
Add a link
Reference in a new issue