Add a bunch of other problems.
Some are not finished...
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
/* Problem URL: https://codeforces.com/gym/103388/problem/C */
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define V vector
|
||||
|
||||
#define rmin(a, b) a = min(a, b)
|
||||
#define rmax(a, b) a = max(a, b)
|
||||
|
||||
#define rep(i, lim) for (int i = 0; i < (lim); i++)
|
||||
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
|
||||
|
||||
#define repv(i, v) for (auto &i : (v))
|
||||
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
|
||||
#define sortv(v) sort(v.begin(), v.end())
|
||||
#define all(v) (v).begin(), (v).end()
|
||||
|
||||
using vi = vector<int>;
|
||||
using vvi = vector<vi>;
|
||||
using vvvi = vector<vvi>;
|
||||
using vvvvi = vector<vvvi>;
|
||||
|
||||
using ll = long long;
|
||||
|
||||
using vl = vector<ll>;
|
||||
using vvl = vector<vl>;
|
||||
using vvvl = vector<vvl>;
|
||||
using vvvvl = vector<vvvl>;
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
|
||||
os << vec[0];
|
||||
for (size_t i = 1; i < vec.size(); i++) {
|
||||
os << ' ' << vec[i];
|
||||
}
|
||||
os << '\n';
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<v> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
is >> i;
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
|
||||
for (auto &i : vec) {
|
||||
os << i[0];
|
||||
for (size_t j = 1; j < i.size(); j++) {
|
||||
os << ' ' << i[j];
|
||||
}
|
||||
os << '\n';
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
for (auto &j : i) {
|
||||
is >> j;
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
ll b;
|
||||
int l;
|
||||
cin >> b >> l;
|
||||
|
||||
ll mod = b + 1;
|
||||
|
||||
auto fastpow = [&](ll a, ll p) {
|
||||
ll ans = 1;
|
||||
ll now = a;
|
||||
|
||||
rep(i, 20) {
|
||||
if ((p >> i) & 1) {
|
||||
ans *= now;
|
||||
ans %= mod;
|
||||
}
|
||||
|
||||
now *= now;
|
||||
now %= mod;
|
||||
}
|
||||
|
||||
return ans;
|
||||
};
|
||||
|
||||
vl fds(l);
|
||||
cin >> fds;
|
||||
|
||||
ll now = 0;
|
||||
rep(i, l) {
|
||||
now += fds[i] * fastpow(b, l - i - 1);
|
||||
now %= mod;
|
||||
}
|
||||
|
||||
if (now == 0) {
|
||||
cout << "0 0\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
rep(i, l) {
|
||||
ll p = fastpow(b, l - i - 1);
|
||||
ll tmp = (p * now) % mod;
|
||||
|
||||
if (fds[i] >= tmp) {
|
||||
cout << i + 1 << ' ' << fds[i] - tmp << '\n';
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
cout << "-1 -1\n";
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
/* Problem URL: https://codeforces.com/gym/103388/problem/E */
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define V vector
|
||||
|
||||
#define rmin(a, b) a = min(a, b)
|
||||
#define rmax(a, b) a = max(a, b)
|
||||
|
||||
#define rep(i, lim) for (int i = 0; i < (lim); i++)
|
||||
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
|
||||
|
||||
#define repv(i, v) for (auto &i : (v))
|
||||
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
|
||||
#define sortv(v) sort(v.begin(), v.end())
|
||||
#define all(v) (v).begin(), (v).end()
|
||||
|
||||
using vi = vector<int>;
|
||||
using vvi = vector<vi>;
|
||||
using vvvi = vector<vvi>;
|
||||
using vvvvi = vector<vvvi>;
|
||||
|
||||
using ll = long long;
|
||||
|
||||
using vl = vector<ll>;
|
||||
using vvl = vector<vl>;
|
||||
using vvvl = vector<vvl>;
|
||||
using vvvvl = vector<vvvl>;
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
|
||||
os << vec[0];
|
||||
for (size_t i = 1; i < vec.size(); i++) {
|
||||
os << ' ' << vec[i];
|
||||
}
|
||||
os << '\n';
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<v> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
is >> i;
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
|
||||
for (auto &i : vec) {
|
||||
os << i[0];
|
||||
for (size_t j = 1; j < i.size(); j++) {
|
||||
os << ' ' << i[j];
|
||||
}
|
||||
os << '\n';
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
for (auto &j : i) {
|
||||
is >> j;
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
int n;
|
||||
cin >> n;
|
||||
|
||||
int now = 0;
|
||||
int dir = 0;
|
||||
|
||||
now = 0;
|
||||
dir = 0;
|
||||
|
||||
V<queue<int>> fds(2);
|
||||
|
||||
while (n--) {
|
||||
int t, d;
|
||||
cin >> t >> d;
|
||||
|
||||
fds[d].push(t);
|
||||
}
|
||||
|
||||
while (!fds[0].empty() || !fds[1].empty()) {
|
||||
if (fds[0].empty()) {
|
||||
dir = 1;
|
||||
} else if (fds[1].empty()) {
|
||||
dir = 0;
|
||||
} else {
|
||||
dir = fds[0].front() > fds[1].front();
|
||||
}
|
||||
|
||||
if (fds[dir].front() <= now) {
|
||||
while (!fds[dir].empty() && fds[dir].front() <= now) {
|
||||
fds[dir].pop();
|
||||
}
|
||||
now += 10;
|
||||
|
||||
while (!fds[dir].empty() && fds[dir].front() <= now) {
|
||||
now = fds[dir].front() + 10;
|
||||
fds[dir].pop();
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
now = fds[dir].front() + 10;
|
||||
fds[dir].pop();
|
||||
|
||||
while (!fds[dir].empty() && fds[dir].front() <= now) {
|
||||
now = fds[dir].front() + 10;
|
||||
fds[dir].pop();
|
||||
}
|
||||
}
|
||||
|
||||
cout << now << '\n';
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
/* Problem URL: https://codeforces.com/gym/103388/problem/G */
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define V vector
|
||||
|
||||
#define rmin(a, b) a = min(a, b)
|
||||
#define rmax(a, b) a = max(a, b)
|
||||
|
||||
#define rep(i, lim) for (int i = 0; i < (lim); i++)
|
||||
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
|
||||
|
||||
#define repv(i, v) for (auto &i : (v))
|
||||
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
|
||||
#define sortv(v) sort(v.begin(), v.end())
|
||||
#define all(v) (v).begin(), (v).end()
|
||||
|
||||
using vi = vector<int>;
|
||||
using vvi = vector<vi>;
|
||||
using vvvi = vector<vvi>;
|
||||
using vvvvi = vector<vvvi>;
|
||||
|
||||
using ll = long long;
|
||||
|
||||
using vl = vector<ll>;
|
||||
using vvl = vector<vl>;
|
||||
using vvvl = vector<vvl>;
|
||||
using vvvvl = vector<vvvl>;
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
|
||||
os << vec[0];
|
||||
for (size_t i = 1; i < vec.size(); i++) {
|
||||
os << ' ' << vec[i];
|
||||
}
|
||||
os << '\n';
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<v> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
is >> i;
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
|
||||
for (auto &i : vec) {
|
||||
os << i[0];
|
||||
for (size_t j = 1; j < i.size(); j++) {
|
||||
os << ' ' << i[j];
|
||||
}
|
||||
os << '\n';
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
for (auto &j : i) {
|
||||
is >> j;
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
ll n;
|
||||
cin >> n;
|
||||
|
||||
vl dp(77);
|
||||
dp[0] = 1;
|
||||
dp[1] = 1;
|
||||
|
||||
rep(i, 75) {
|
||||
dp[i + 1] += dp[i];
|
||||
dp[i + 2] += dp[i];
|
||||
}
|
||||
|
||||
unordered_map<ll, bool> vis;
|
||||
|
||||
vi ans;
|
||||
|
||||
function<bool(ll)> dfs = [&](ll now) {
|
||||
if (now == 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (vis[now]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
vis[now] = true;
|
||||
|
||||
for (int i = 74; i > 0; i--) {
|
||||
if (now % dp[i] == 0) {
|
||||
bool res = dfs(now / dp[i]);
|
||||
|
||||
if (res) {
|
||||
ans.push_back(i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
if (!dfs(n)) {
|
||||
cout << "IMPOSSIBLE\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
reverse(all(ans));
|
||||
|
||||
string tmp;
|
||||
|
||||
repv(i, ans) {
|
||||
tmp += string(i, 'A');
|
||||
tmp += 'B';
|
||||
}
|
||||
|
||||
cout << tmp << '\n';
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
/* Problem URL: https://codeforces.com/gym/103388/problem/H */
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define V vector
|
||||
|
||||
#define rmin(a, b) a = min(a, b)
|
||||
#define rmax(a, b) a = max(a, b)
|
||||
|
||||
#define rep(i, lim) for (int i = 0; i < (lim); i++)
|
||||
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
|
||||
|
||||
#define repv(i, v) for (auto &i : (v))
|
||||
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
|
||||
#define sortv(v) sort(v.begin(), v.end())
|
||||
#define all(v) (v).begin(), (v).end()
|
||||
|
||||
using vi = vector<int>;
|
||||
using vvi = vector<vi>;
|
||||
using vvvi = vector<vvi>;
|
||||
using vvvvi = vector<vvvi>;
|
||||
|
||||
using ll = long long;
|
||||
|
||||
using vl = vector<ll>;
|
||||
using vvl = vector<vl>;
|
||||
using vvvl = vector<vvl>;
|
||||
using vvvvl = vector<vvvl>;
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
|
||||
os << vec[0];
|
||||
for (size_t i = 1; i < vec.size(); i++) {
|
||||
os << ' ' << vec[i];
|
||||
}
|
||||
os << '\n';
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<v> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
is >> i;
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
|
||||
for (auto &i : vec) {
|
||||
os << i[0];
|
||||
for (size_t j = 1; j < i.size(); j++) {
|
||||
os << ' ' << i[j];
|
||||
}
|
||||
os << '\n';
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
for (auto &j : i) {
|
||||
is >> j;
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
int n, k;
|
||||
cin >> n >> k;
|
||||
|
||||
vvi blocks(k);
|
||||
|
||||
vi act;
|
||||
|
||||
while (n--) {
|
||||
int num, c;
|
||||
cin >> num >> c;
|
||||
|
||||
blocks[c - 1].push_back(num);
|
||||
act.push_back(c - 1);
|
||||
}
|
||||
|
||||
rep(i, k) {
|
||||
sort(all(blocks[i]), greater<>());
|
||||
}
|
||||
|
||||
vi ans;
|
||||
|
||||
rep(i, act.size()) {
|
||||
ans.push_back(blocks[act[i]].back());
|
||||
blocks[act[i]].pop_back();
|
||||
}
|
||||
|
||||
nrep(i, 1, ans.size()) {
|
||||
if (ans[i - 1] > ans[i]) {
|
||||
cout << "N\n";
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
cout << "Y\n";
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/* Problem URL: https://codeforces.com/gym/103388/problem/K */
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define V vector
|
||||
|
||||
#define rmin(a, b) a = min(a, b)
|
||||
#define rmax(a, b) a = max(a, b)
|
||||
|
||||
#define rep(i, lim) for (int i = 0; i < (lim); i++)
|
||||
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
|
||||
|
||||
#define repv(i, v) for (auto &i : (v))
|
||||
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
|
||||
#define sortv(v) sort(v.begin(), v.end())
|
||||
#define all(v) (v).begin(), (v).end()
|
||||
|
||||
using vi = vector<int>;
|
||||
using vvi = vector<vi>;
|
||||
using vvvi = vector<vvi>;
|
||||
using vvvvi = vector<vvvi>;
|
||||
|
||||
using ll = long long;
|
||||
|
||||
using vl = vector<ll>;
|
||||
using vvl = vector<vl>;
|
||||
using vvvl = vector<vvl>;
|
||||
using vvvvl = vector<vvvl>;
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
|
||||
os << vec[0];
|
||||
for (size_t i = 1; i < vec.size(); i++) {
|
||||
os << ' ' << vec[i];
|
||||
}
|
||||
os << '\n';
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<v> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
is >> i;
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
|
||||
for (auto &i : vec) {
|
||||
os << i[0];
|
||||
for (size_t j = 1; j < i.size(); j++) {
|
||||
os << ' ' << i[j];
|
||||
}
|
||||
os << '\n';
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
for (auto &j : i) {
|
||||
is >> j;
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
int t, d, m;
|
||||
cin >> t >> d >> m;
|
||||
|
||||
int prev = 0;
|
||||
|
||||
while (m--) {
|
||||
int n;
|
||||
cin >> n;
|
||||
|
||||
if (n - prev >= t) {
|
||||
cout << "Y\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
prev = n;
|
||||
}
|
||||
|
||||
if (d - prev >= t) {
|
||||
cout << "Y\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
cout << "N\n";
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/* Problem URL: https://codeforces.com/gym/103388/problem/M */
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define V vector
|
||||
|
||||
#define rmin(a, b) a = min(a, b)
|
||||
#define rmax(a, b) a = max(a, b)
|
||||
|
||||
#define rep(i, lim) for (int i = 0; i < (lim); i++)
|
||||
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
|
||||
|
||||
#define repv(i, v) for (auto &i : (v))
|
||||
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
|
||||
#define sortv(v) sort(v.begin(), v.end())
|
||||
#define all(v) (v).begin(), (v).end()
|
||||
|
||||
using vi = vector<int>;
|
||||
using vvi = vector<vi>;
|
||||
using vvvi = vector<vvi>;
|
||||
using vvvvi = vector<vvvi>;
|
||||
|
||||
using ll = long long;
|
||||
|
||||
using vl = vector<ll>;
|
||||
using vvl = vector<vl>;
|
||||
using vvvl = vector<vvl>;
|
||||
using vvvvl = vector<vvvl>;
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
|
||||
os << vec[0];
|
||||
for (size_t i = 1; i < vec.size(); i++) {
|
||||
os << ' ' << vec[i];
|
||||
}
|
||||
os << '\n';
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<v> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
is >> i;
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
|
||||
for (auto &i : vec) {
|
||||
os << i[0];
|
||||
for (size_t j = 1; j < i.size(); j++) {
|
||||
os << ' ' << i[j];
|
||||
}
|
||||
os << '\n';
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
for (auto &j : i) {
|
||||
is >> j;
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
int q;
|
||||
cin >> q;
|
||||
|
||||
vvi graph(1);
|
||||
int cur = 1;
|
||||
|
||||
vi status(1);
|
||||
vi chosen(1);
|
||||
vi parent(1);
|
||||
|
||||
function<int(int)> dfs = [&](int i) {
|
||||
if (status[i] != -1) {
|
||||
return i;
|
||||
}
|
||||
|
||||
while (chosen[i] < graph[i].size()) {
|
||||
int res = dfs(graph[i][chosen[i]]);
|
||||
|
||||
if (res == -1) {
|
||||
chosen[i]++;
|
||||
continue;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
while (q--) {
|
||||
int p, c;
|
||||
cin >> p >> c;
|
||||
|
||||
if (p == 1) {
|
||||
graph[c - 1].push_back(graph.size());
|
||||
graph.emplace_back();
|
||||
parent.push_back(c - 1);
|
||||
status.push_back(0);
|
||||
chosen.push_back(0);
|
||||
continue;
|
||||
}
|
||||
|
||||
status[c - 1] = -1;
|
||||
|
||||
int ans = cur - 1;
|
||||
int tmp;
|
||||
while ((tmp = dfs(ans)) == -1) {
|
||||
ans = parent[ans];
|
||||
}
|
||||
|
||||
cur = tmp + 1;
|
||||
cout << cur << '\n';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
/* Problem URL: https://codeforces.com/gym/103388/problem/N */
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define V vector
|
||||
|
||||
#define rmin(a, b) a = min(a, b)
|
||||
#define rmax(a, b) a = max(a, b)
|
||||
|
||||
#define rep(i, lim) for (int i = 0; i < (lim); i++)
|
||||
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
|
||||
|
||||
#define repv(i, v) for (auto &i : (v))
|
||||
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
|
||||
#define sortv(v) sort(v.begin(), v.end())
|
||||
#define all(v) (v).begin(), (v).end()
|
||||
|
||||
using vi = vector<int>;
|
||||
using vvi = vector<vi>;
|
||||
using vvvi = vector<vvi>;
|
||||
using vvvvi = vector<vvvi>;
|
||||
|
||||
using ll = long long;
|
||||
|
||||
using vl = vector<ll>;
|
||||
using vvl = vector<vl>;
|
||||
using vvvl = vector<vvl>;
|
||||
using vvvvl = vector<vvvl>;
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
|
||||
os << vec[0];
|
||||
for (size_t i = 1; i < vec.size(); i++) {
|
||||
os << ' ' << vec[i];
|
||||
}
|
||||
os << '\n';
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<v> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
is >> i;
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
|
||||
for (auto &i : vec) {
|
||||
os << i[0];
|
||||
for (size_t j = 1; j < i.size(); j++) {
|
||||
os << ' ' << i[j];
|
||||
}
|
||||
os << '\n';
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
for (auto &j : i) {
|
||||
is >> j;
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
int y, n;
|
||||
cin >> y >> n;
|
||||
|
||||
vi fds(y);
|
||||
cin >> fds;
|
||||
|
||||
while (__builtin_popcount(y) != 1) {
|
||||
y++;
|
||||
fds.push_back(0);
|
||||
}
|
||||
|
||||
vvi seg(y * 2);
|
||||
|
||||
function<void(int, int, int)> build = [&](int i, int l, int r) {
|
||||
if (l == r) {
|
||||
seg[i].push_back(fds[i - y]);
|
||||
return;
|
||||
}
|
||||
|
||||
int mid = (l + r) / 2;
|
||||
|
||||
build(i * 2, l, mid);
|
||||
build(i * 2 + 1, mid + 1, r);
|
||||
|
||||
merge(all(seg[i * 2]), all(seg[i * 2 + 1]), back_inserter(seg[i]));
|
||||
};
|
||||
|
||||
build(1, 0, y - 1);
|
||||
|
||||
function<int(int, int, int, int, int, int)> query = [&](int i, int l, int r, int tl, int tr, int v) -> int {
|
||||
if (l > tr || r < tl) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (l >= tl && r <= tr) {
|
||||
auto lower = lower_bound(all(seg[i]), v);
|
||||
return seg[i].end() - lower;
|
||||
}
|
||||
|
||||
int mid = (l + r) / 2;
|
||||
|
||||
return query(i * 2, l, mid, tl, tr, v) + query(i * 2 + 1, mid + 1, r, tl, tr, v);
|
||||
};
|
||||
|
||||
while (n--) {
|
||||
int a, p ,f;
|
||||
cin >> a >> p >> f;
|
||||
|
||||
if (fds[a - 1] >= p) {
|
||||
cout << "0\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
cout << query(1, 0, y - 1, a - 1, a + f - 1, p) << '\n';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user