This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#ifndef LOCAL
#define FAST_IO
#endif
// ============
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define OVERRIDE(a, b, c, d, ...) d
#define REP2(i, n) for (i32 i = 0; i < (i32)(n); ++i)
#define REP3(i, m, n) for (i32 i = (i32)(m); i < (i32)(n); ++i)
#define REP(...) OVERRIDE(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
#define PER(i, n) for (i32 i = (i32)(n) - 1; i >= 0; --i)
#define ALL(x) begin(x), end(x)
using namespace std;
using u32 = unsigned int;
using u64 = unsigned long long;
using i32 = signed int;
using i64 = signed long long;
using f64 = double;
using f80 = long double;
template <typename T>
using Vec = vector<T>;
template <typename T>
bool chmin(T &x, const T &y) {
if (x > y) {
x = y;
return true;
}
return false;
}
template <typename T>
bool chmax(T &x, const T &y) {
if (x < y) {
x = y;
return true;
}
return false;
}
#ifdef INT128
using u128 = __uint128_t;
using i128 = __int128_t;
istream &operator>>(istream &is, i128 &x) {
i64 v;
is >> v;
x = v;
return is;
}
ostream &operator<<(ostream &os, i128 x) {
os << (i64)x;
return os;
}
istream &operator>>(istream &is, u128 &x) {
u64 v;
is >> v;
x = v;
return is;
}
ostream &operator<<(ostream &os, u128 x) {
os << (u64)x;
return os;
}
#endif
[[maybe_unused]] constexpr i32 INF = 1000000100;
[[maybe_unused]] constexpr i64 INF64 = 3000000000000000100;
struct SetUpIO {
SetUpIO() {
#ifdef FAST_IO
ios::sync_with_stdio(false);
cin.tie(nullptr);
#endif
cout << fixed << setprecision(15);
}
} set_up_io;
// ============
#ifdef DEBUGF
#else
#define DBG(x) (void)0
#endif
// のいみさんいつもありがとう 今回は借ります
// https://noimi.hatenablog.com/entry/2021/05/02/195143
// S : 持つデータの型 T : 範囲の型
template <class S, class T = int> struct IntervalManager {
struct node {
T l, r;
S x;
node(const T &l, const T &r, const S &x) : l(l), r(r), x(x) {}
constexpr bool operator<(const node &rhs) const {
if(l != rhs.l) return l < rhs.l;
return r < rhs.r;
}
};
const S unit;
set<node> s;
IntervalManager(const S &u = S()) : unit(u) {}
IntervalManager(const vector<T> &a) {
vector<node> setter;
for(int l = 0; l < a.size(); l++) {
int r = l;
for(; r < a.size() and a[l] == a[r]; r++) {}
setter.emplace_back(l, r, a[l]);
l = r - 1;
}
s = set<node>(all(setter));
}
// x を含んだセグメントのイテレータを返す
typename set<node>::iterator getIt(const T &x) {
auto it = s.upper_bound(node(x, numeric_limits<T>::max(), 0));
if(it == begin(s)) return end(s);
it = prev(it);
if(it->l <= x and x < it->r) return it;
return end(s);
}
// x を含んだセグメントの情報を持ってくる
node getSeg(const T &x) {
auto it = getIt(x);
if(it != end(s)) return *it;
return node(x, x + 1, unit);
}
// x 以上をはじめて含むセグメントの iterator が帰ってくる
typename set<node>::iterator nextIt(const T &x) {
auto it = s.upper_bound(node(x, numeric_limits<T>::max(), 0));
if(it == begin(s)) return it;
return prev(it);
}
// x に設定されてる値を取得
S get(const T &x) {
auto it = getIt(x);
if(it != end(s)) return it->x;
return unit;
}
S operator[](T k) const { return get(k); }
// [l, r) := x を set するときに消える区間加える区間ごとに関数を呼び出す
// ただし、内包, 結合される [L, r) := x の区間も一旦消す
template <typename ADD, typename DEL> void update(T l, T r, const S &x, const ADD &add, const DEL &del) {
auto it = s.lower_bound(node{l, 0, x});
while(it != end(s) and it->l <= r) {
if(it->l == r) {
if(it->x == x) {
del(r, it->r, x);
r = it->r, it = s.erase(it);
}
break;
}
if(it->r <= r) {
del(it->l, it->r, it->x);
it = s.erase(it);
} else {
if(it->x == x) {
r = it->r;
del(it->l, it->r, it->x);
it = s.erase(it);
} else {
del(it->l, r, it->x);
node n = *it;
it = s.erase(it);
it = s.emplace_hint(it, r, n.r, n.x);
}
}
}
if(it != begin(s)) {
it = prev(it);
if(it->r == l) {
if(it->x == x) {
del(it->l, it->r, it->x);
l = it->l;
it = s.erase(it);
}
} else if(l < it->r) {
if(it->x == x) {
del(it->l, it->r, it->x);
l = min(l, it->l);
r = max(r, it->r);
it = s.erase(it);
} else {
if(r < it->r) {
it = s.emplace_hint(next(it), r, it->r, it->x);
it = prev(it);
}
del(l, min(r, it->r), it->x);
node n = *it;
it = s.erase(it);
it = s.emplace_hint(it, n.l, l, n.x);
}
}
}
if(it != end(s)) it = next(it);
add(l, r, x);
s.emplace_hint(it, l, r, x);
}
void update(T l, T r, const S &x) {
update(
l, r, x, [](T, T, S) {}, [](T, T, S) {});
}
void show() {
for(auto e : s) {
cerr << "("
<< "[" << e.l << ", " << e.r << "): " << e.x << ") ";
}
cerr << endl;
}
};
int main() {
i32 n, m, q;
cin >> n >> m >> q;
Vec<i32> l(m), r(m);
REP(i, m) {
cin >> l[i] >> r[i];
--l[i];
}
Vec<i64> s(q);
REP(i, q) {
cin >> s[i];
}
IntervalManager<i64> manager;
i64 day = 0;
Vec<pair<i64, i64>> pool;
REP(i, m) {
i64 tmp = day - l[i];
auto del = [&pool, &day, &tmp](i32 l, i32 r, i64 x) -> void {
pool.emplace_back(tmp - x - 1, r - l);
};
auto add = [](i32 l, i32 r, i64 x) -> void {};
manager.update(l[i], r[i], tmp, add, del);
day += r[i] - l[i];
}
sort(ALL(pool));
if (!pool.empty()) {
PER(i, pool.size() - 1) {
pool[i].second += pool[i + 1].second;
}
}
REP(i, q) {
auto it = lower_bound(ALL(pool), pair<i64, i64>(s[i], 0));
if (it == pool.end()) {
cout << 0;
} else {
cout << it->second;
}
cout << " \n"[i + 1 == q];
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |