# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
630015 |
2022-08-15T14:11:11 Z |
leeh18 |
Meteors (POI11_met) |
C++17 |
|
1870 ms |
46116 KB |
#include <bits/stdc++.h>
#include <cassert>
#include <vector>
#include <cassert>
#include <numeric>
#include <type_traits>
namespace atcoder {
namespace internal {
#ifndef _MSC_VER
template <class T>
using is_signed_int128 =
typename std::conditional<std::is_same<T, __int128_t>::value ||
std::is_same<T, __int128>::value,
std::true_type,
std::false_type>::type;
template <class T>
using is_unsigned_int128 =
typename std::conditional<std::is_same<T, __uint128_t>::value ||
std::is_same<T, unsigned __int128>::value,
std::true_type,
std::false_type>::type;
template <class T>
using make_unsigned_int128 =
typename std::conditional<std::is_same<T, __int128_t>::value,
__uint128_t,
unsigned __int128>;
template <class T>
using is_integral = typename std::conditional<std::is_integral<T>::value ||
is_signed_int128<T>::value ||
is_unsigned_int128<T>::value,
std::true_type,
std::false_type>::type;
template <class T>
using is_signed_int = typename std::conditional<(is_integral<T>::value &&
std::is_signed<T>::value) ||
is_signed_int128<T>::value,
std::true_type,
std::false_type>::type;
template <class T>
using is_unsigned_int =
typename std::conditional<(is_integral<T>::value &&
std::is_unsigned<T>::value) ||
is_unsigned_int128<T>::value,
std::true_type,
std::false_type>::type;
template <class T>
using to_unsigned = typename std::conditional<
is_signed_int128<T>::value,
make_unsigned_int128<T>,
typename std::conditional<std::is_signed<T>::value,
std::make_unsigned<T>,
std::common_type<T>>::type>::type;
#else
template <class T> using is_integral = typename std::is_integral<T>;
template <class T>
using is_signed_int =
typename std::conditional<is_integral<T>::value && std::is_signed<T>::value,
std::true_type,
std::false_type>::type;
template <class T>
using is_unsigned_int =
typename std::conditional<is_integral<T>::value &&
std::is_unsigned<T>::value,
std::true_type,
std::false_type>::type;
template <class T>
using to_unsigned = typename std::conditional<is_signed_int<T>::value,
std::make_unsigned<T>,
std::common_type<T>>::type;
#endif
template <class T>
using is_signed_int_t = std::enable_if_t<is_signed_int<T>::value>;
template <class T>
using is_unsigned_int_t = std::enable_if_t<is_unsigned_int<T>::value>;
template <class T> using to_unsigned_t = typename to_unsigned<T>::type;
} // namespace internal
} // namespace atcoder
namespace atcoder {
template <class T> struct fenwick_tree {
using U = internal::to_unsigned_t<T>;
public:
fenwick_tree() : _n(0) {}
explicit fenwick_tree(int n) : _n(n), data(n) {}
void add(int p, T x) {
assert(0 <= p && p < _n);
p++;
while (p <= _n) {
data[p - 1] += U(x);
p += p & -p;
}
}
T sum(int l, int r) {
assert(0 <= l && l <= r && r <= _n);
return sum(r) - sum(l);
}
private:
int _n;
std::vector<U> data;
U sum(int r) {
U s = 0;
while (r > 0) {
s += data[r - 1];
r -= r & -r;
}
return s;
}
};
} // namespace atcoder
using namespace std;
using namespace atcoder;
auto main() -> int {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int N, M;
cin >> N >> M;
vector<vector<int>> g(N);
for (int i = 0; i < M; i++) {
int o;
cin >> o;
g[o-1].push_back(i);
}
vector<int64_t> p(N);
for (auto& x : p) {
cin >> x;
}
int Q;
cin >> Q;
vector<tuple<int, int, int64_t>> vec(Q);
for (auto& [l, r, a] : vec) {
cin >> l >> r >> a;
--l, --r;
}
vector<pair<int, int>> rng(N, make_pair(0, Q));
while (any_of(begin(rng), end(rng), [](auto e) { return e.first < e.second; })) {
vector<vector<int>> t(Q+1);
for (int i = 0; i < N; i++) {
auto [lo, hi] = rng[i];
if (lo < hi) {
auto mid = (lo + hi) / 2;
t[mid].push_back(i);
}
}
fenwick_tree<__int128> ft(M+1);
auto update = [&](int l, int r, int64_t val) { // [l, r] inclusive
ft.add(l, val);
ft.add(r+1, -val);
};
auto query = [&](int pos) {
return ft.sum(0, pos+1);
};
for (int i = 0; i < Q; i++) {
auto [l, r, a] = vec[i];
if (l <= r) {
update(l, r, a);
} else {
update(l, M-1, a);
update(0, r, a);
}
for (auto v : t[i]) {
__int128 sum = 0;
for (auto x : g[v]) {
sum += query(x);
}
auto& [lo, hi] = rng[v];
if (sum >= p[v]) {
hi = i;
} else {
lo = i + 1;
}
}
}
}
for (auto [lo, hi] : rng) {
if (lo == Q) {
cout << "NIE\n";
} else {
cout << lo + 1 << '\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
3608 KB |
Output is correct |
2 |
Correct |
121 ms |
4924 KB |
Output is correct |
3 |
Correct |
91 ms |
4432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
100 ms |
4060 KB |
Output is correct |
2 |
Correct |
104 ms |
4056 KB |
Output is correct |
3 |
Correct |
112 ms |
5076 KB |
Output is correct |
4 |
Correct |
27 ms |
2640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
3684 KB |
Output is correct |
2 |
Correct |
96 ms |
5188 KB |
Output is correct |
3 |
Correct |
50 ms |
2336 KB |
Output is correct |
4 |
Correct |
99 ms |
4600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
97 ms |
3376 KB |
Output is correct |
2 |
Correct |
101 ms |
4084 KB |
Output is correct |
3 |
Correct |
73 ms |
3480 KB |
Output is correct |
4 |
Correct |
118 ms |
5272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1074 ms |
26032 KB |
Output is correct |
2 |
Correct |
604 ms |
17944 KB |
Output is correct |
3 |
Correct |
260 ms |
12508 KB |
Output is correct |
4 |
Correct |
1864 ms |
43388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1060 ms |
25224 KB |
Output is correct |
2 |
Correct |
589 ms |
18100 KB |
Output is correct |
3 |
Correct |
206 ms |
11584 KB |
Output is correct |
4 |
Correct |
1870 ms |
46116 KB |
Output is correct |