Submission #76292
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | #include "bits/stdc++.h" #pragma GCC optimize("Ofast") // Begin Header {{{ #pragma region using namespace std; #ifndef DEBUG #define dump(...) #endif #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) #define rep(i, b, e) for (intmax_t i = (b), i##_limit = (e); i < i##_limit; ++i) #define repc(i, b, e) for (intmax_t i = (b), i##_limit = (e); i <= i##_limit; ++i) #define repr(i, b, e) for (intmax_t i = (b), i##_limit = (e); i >= i##_limit; --i) #define var(Type, ...) \ Type __VA_ARGS__; \ input(__VA_ARGS__) #define let const auto constexpr size_t operator "" _zu(unsigned long long value) { return value; }; constexpr intmax_t operator "" _jd(unsigned long long value) { return value; }; constexpr uintmax_t operator "" _ju(unsigned long long value) { return value; }; constexpr int INF = 0x3f3f3f3f; constexpr intmax_t LINF = 0x3f3f3f3f3f3f3f3f_jd; using usize = size_t ; using imax = intmax_t; using uimax = uintmax_t; using ld = long double ; template < class T, class Compare = less<>> using MaxHeap = priority_queue<T, vector<T>, Compare>; template < class T, class Compare = greater<>> using MinHeap = priority_queue<T, vector<T>, Compare>; template < class Container, class Value = typename Container::value_type, enable_if_t<!is_same<Container, string>::value, nullptr_t> = nullptr> inline istream& operator>>(istream& is, Container& vs) { for (auto& v: vs) is >> v; return is; } template < class T, class U> inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; } inline void input() {} template < class Head, class ... Tail> inline void input(Head&& head, Tail&&... tail) { cin >> head; input(forward<Tail>(tail)...); } template < class Container, class Value = typename Container::value_type, enable_if_t<!is_same<Container, string>::value, nullptr_t> = nullptr> inline ostream& operator<<(ostream& os, const Container& vs) { static constexpr const char * delim[] = { " " , "" }; for (auto it = begin(vs); it != end(vs); ++it) { os << delim[it == begin(vs)] << *it; } return os; } inline void output() { cout << "\n" ; } template < class Head, class ... Tail> inline void output(Head&& head, Tail&&... tail) { cout << head; if ( sizeof ...(tail)) cout << " " ; output(forward<Tail>(tail)...); } template < class Iterator> inline void join( const Iterator& Begin, const Iterator& End, const string& delim = "\n" , const string& last = "\n" ) { for (auto it = Begin; it != End; ++it) { cout << ((it == Begin) ? "" : delim) << *it; } cout << last; } template < class T> inline vector<T> makeVector( const T& init_value, size_t sz) { return vector<T>(sz, init_value); } template < class T, class ... Args> inline auto makeVector( const T& init_value, size_t sz, Args... args) { return vector<decltype(makeVector<T>(init_value, args...))>( sz, makeVector<T>(init_value, args...)); } template < class Func> class FixPoint : Func { public : explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {} template < class ... Args> constexpr decltype(auto) operator()(Args&&... args) const { return Func::operator()(* this , std::forward<Args>(args)...); } }; template < class Func> static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept { return FixPoint<Func> {forward<Func>(f)}; } template < class Container> struct reverse_t { Container& c; reverse_t(Container& c) : c(c) {} auto begin() { return c.rbegin(); } auto end() { return c.rend(); } }; template < class Container> auto reversed(Container& c) { return reverse_t<Container>(c); } template < class T> inline bool chmax(T& a, const T& b) noexcept { return b > a && (a = b, true ); } template < class T> inline bool chmin(T& a, const T& b) noexcept { return b < a && (a = b, true ); } template < class T> inline T diff( const T& a, const T& b) noexcept { return a < b ? b - a : a - b; } template < class T> inline T sigma( const T& l, const T& r) noexcept { return (l + r) * (r - l + 1) / 2; } template < class T> inline T div_floor(T a, T b) noexcept { if (b < 0) a = -a, b = -b; return a >= 0 ? a / b : (a + 1) / b - 1; } template < class T> inline T div_ceil(T a, T b) noexcept { if (b < 0) a = -a, b = -b; return a > 0 ? (a - 1) / b + 1 : a / b; } void operator|=(vector< bool >::reference lhs, const bool rhs) { lhs = lhs | rhs; } void operator&=(vector< bool >::reference lhs, const bool rhs) { lhs = lhs & rhs; } void operator^=(vector< bool >::reference lhs, const bool rhs) { lhs = lhs ^ rhs; } void ioinit() { ios_base::sync_with_stdio( false ); cin.tie(nullptr); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); clog << fixed << setprecision(10); } #pragma endregion // }}} End Header // FenwickTree {{{ template < class T> struct FenwickTree { vector<T> ft; const size_t SIZE; explicit FenwickTree( size_t n) : ft(n + 5, 0), SIZE(1 << (__lg(n + 5) + 1)) {} void add( int i, const T& v) { for (++i; i < ft.size(); i += i & -i) ft[i] += v; } // [0, i] T sum( int i) const { T ret = 0; for (++i; i > 0; i -= i & -i) ret += ft[i]; return ret; } // [s, t] T sum( int s, int t) const { if (s > t) swap(s, t); return sum(t) - sum(s - 1); } size_t lower_bound(T v) const { size_t i = 0; for ( size_t k = SIZE; k > 0; k >>= 1) { if (i + k < ft.size() && ft[i + k] < v) { v -= ft[i + k]; i += k; } } return i; } size_t upper_bound(T v) const { size_t i = 0; for ( size_t k = SIZE; k > 0; k >>= 1) { if (i + k < ft.size() && ft[i + k] <= v) { v -= ft[i + k]; i += k; } } return i; } }; // }}} int main() { ioinit(); const intmax_t M = 200'000; var( size_t , N, Q); assert (1 <= N && N <= M); assert (1 <= Q && Q <= M); vector<pair<intmax_t, intmax_t>> ps(N); for (auto&& [l, r]: ps) { input(l, r); assert (1 <= l && l <= r && r <= M); } sort(all(ps)); vector<tuple<intmax_t, intmax_t, size_t >> qs(Q); rep(i, 0, Q) { var(intmax_t, u, v); assert (1 <= u && u <= v && v <= M); qs[i] = make_tuple(u, v, i); } sort(all(qs)); vector<intmax_t> res(Q); { FenwickTree<intmax_t> ft(M + 1); size_t pos = 0; for ( const auto [u, v, i]: qs) { while (pos < N) { const auto [l, r] = ps[pos]; if (l > u) break ; ft.add(r, 1); pos++; } res[i] += ft.sum(u, M); } } { FenwickTree<intmax_t> ft(M + 1); int pos = N - 1; for ( const auto [u, v, i]: reversed(qs)) { while (pos >= 0) { const auto [l, r] = ps[pos]; if (l <= u) break ; ft.add(l, 1); pos--; } res[i] += ft.sum(0, v); } } join(all(res)); return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 1661 - Intersection |
ユーザー名 | もけ |
投稿日時 | 2023-09-21 18:00:15 |
言語 | C++17 |
状態 | Accepted |
得点 | 3 |
ソースコード長 | 7589 Byte |
最大実行時間 | 117 ms |
最大メモリ使用量 | 15916 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 3 / 3 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
00_sample_00.in | AC | 31 ms | 2140 KB |
1
|
01_small_00.in | AC | 19 ms | 1916 KB |
1
|
01_small_01.in | AC | 22 ms | 1944 KB |
1
|
01_small_02.in | AC | 18 ms | 1968 KB |
1
|
01_small_03.in | AC | 26 ms | 1996 KB |
1
|
02_corner_minimum_00.in | AC | 22 ms | 2144 KB |
1
|
02_corner_minimum_01.in | AC | 28 ms | 2044 KB |
1
|
02_corner_minimum_02.in | AC | 23 ms | 2072 KB |
1
|
02_corner_minimum_03.in | AC | 21 ms | 2100 KB |
1
|
02_corner_minimum_04.in | AC | 18 ms | 2128 KB |
1
|
02_corner_minimum_05.in | AC | 21 ms | 2156 KB |
1
|
02_corner_minimum_06.in | AC | 17 ms | 2176 KB |
1
|
03_general_00.in | AC | 19 ms | 2204 KB |
1
|
03_general_01.in | AC | 26 ms | 2204 KB |
1
|
04_random_00.in | AC | 30 ms | 2232 KB |
1
|
04_random_01.in | AC | 21 ms | 2284 KB |
1
|
04_random_02.in | AC | 16 ms | 2280 KB |
1
|
05_large_00.in | AC | 22 ms | 2196 KB |
1
|
05_large_01.in | AC | 23 ms | 2192 KB |
1
|
05_large_02.in | AC | 27 ms | 2420 KB |
1
|
06_corner_maximum_00.in | AC | 117 ms | 11904 KB |
1
|
06_corner_maximum_01.in | AC | 93 ms | 13040 KB |
1
|
06_corner_maximum_02.in | AC | 90 ms | 13408 KB |
1
|
07_corner_critical_00.in | AC | 73 ms | 10704 KB |
1
|
07_corner_critical_01.in | AC | 115 ms | 14320 KB |
1
|
07_corner_critical_02.in | AC | 111 ms | 14688 KB |
1
|
07_corner_critical_03.in | AC | 100 ms | 15056 KB |
1
|
07_corner_critical_04.in | AC | 94 ms | 15552 KB |
1
|
07_corner_critical_05.in | AC | 89 ms | 15916 KB |
1
|