# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1248170 | CrabCNH | Worst Reporter 3 (JOI18_worst_reporter3) | C++20 | 6 ms | 1856 KiB |
#include <bits/stdc++.h>
#define task "BriantheCrab"
#define int long long
#define pii pair <int, int>
#define fi first
#define se second
#define szf sizeof
#define sz(s) (int)((s).size())
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;
template <class T> void minimize (T &t, T f) {if (t > f) t = f;}
template <class T> void maximize (T &t, T f) {if (t < f) t = f;}
const int maxN = 2e5 + 5;
const int inf = 1e18 + 7;
const int mod = 1e9 + 7;
// khong tu code thi khong kha len duoc dau
struct Que {
int t, l, r;
};
int n, q;
int d[maxN];
Que off[maxN];
namespace sub1 {
bool check () {
int cnt = 0;
for (int i = 1; i <= n; i ++) {
cnt += (d[i] == 1);
}
return (cnt == n);
}
void sol () {
for (int i = 1; i <= q; i ++) {
auto [t, l, r] = off[i];
int L = - n + t;
int R = t;
//cout << L << ' ' << R << ' ' << l << ' ' << r << '\n';
if (R < l || r < L) {
cout << 0;
}
else if (R <= r) {
if (L <= l) {
cout << R - l + 1;
}
else {
cout << R - L + 1;
}
}
else {
if (L <= l) {
cout << r - L + 1;
}
else {
cout << r - l + 1;
}
}
cout << '\n';
}
}
}
void solve () {
cin >> n >> q;
for (int i = 1; i <= n; i ++) {
cin >> d[i];
}
for (int i = 1; i <= n; i ++) {
int t, l, r;
cin >> t >> l >> r;
off[i] = {t, l, r};
}
if (sub1 :: check ()) {
sub1 :: sol ();
return;
}
return;
}
signed main () {
cin.tie (nullptr) -> sync_with_stdio (false);
if (fopen (task".inp", "r")) {
freopen (task".inp", "r", stdin);
freopen (task".out", "w", stdout);
}
int t = 1;
//cin >> t;
while (t --) {
solve ();
}
return 0;
}
// thfv
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |