Submission #1370047
Source Code Expand
#include <iostream> #include <vector> template<class T> class FenwickTree { public: std::vector<T> data; FenwickTree<T>(unsigned size) : data(size + 1u, 0) {} T sum(unsigned index) { ++index; T ret = 0; while (index) { ret += data[index]; index &= index - 1u; } return ret; } void add(unsigned index, T x) { ++index; while (index <= data.size()) { data[index] += x; index += index & (~index + 1u); } } }; int main() { unsigned N, M; std::cin >> N >> M; std::vector<std::pair<unsigned, unsigned>> lr(N); for (unsigned i = 0; i < N; ++i) { std::cin >> lr[i].first >> lr[i].second; } std::sort(lr.begin(), lr.end(), [](std::pair<unsigned, unsigned> i, std::pair<unsigned, unsigned> j) -> bool { return (i.second - i.first) < (j.second - j.first); }); auto p = lr.begin(); long long inc = N; FenwickTree<long long> fenwickTree(M + 2); for (unsigned i = 1; i <= M; ++i) { while (p < lr.end() && (p->second - p->first + 1) < i) { --inc; fenwickTree.add(p->first, 1); fenwickTree.add(p->second + 1, -1); ++p; } auto ans = inc; for (unsigned j = 0; j <= M; j += i) { ans += fenwickTree.sum(j); } std::cout << ans << std::endl; } return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Snuke Line |
User | ytsmiling |
Language | C++14 (Clang 3.8.0) |
Score | 700 |
Code Size | 1393 Byte |
Status | AC |
Exec Time | 643 ms |
Memory | 4096 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 700 / 700 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 00_example_01.txt, 00_example_02.txt |
All | 00_example_01.txt, 00_example_02.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_example_01.txt | AC | 1 ms | 256 KB |
00_example_02.txt | AC | 1 ms | 256 KB |
01.txt | AC | 1 ms | 256 KB |
02.txt | AC | 4 ms | 256 KB |
03.txt | AC | 2 ms | 256 KB |
04.txt | AC | 1 ms | 256 KB |
05.txt | AC | 3 ms | 256 KB |
06.txt | AC | 3 ms | 256 KB |
07.txt | AC | 1 ms | 256 KB |
08.txt | AC | 2 ms | 256 KB |
09.txt | AC | 2 ms | 256 KB |
10.txt | AC | 1 ms | 256 KB |
11.txt | AC | 490 ms | 3200 KB |
12.txt | AC | 632 ms | 3968 KB |
13.txt | AC | 392 ms | 2688 KB |
14.txt | AC | 377 ms | 2688 KB |
15.txt | AC | 387 ms | 2688 KB |
16.txt | AC | 463 ms | 3072 KB |
17.txt | AC | 621 ms | 3968 KB |
18.txt | AC | 370 ms | 2560 KB |
19.txt | AC | 631 ms | 3968 KB |
20.txt | AC | 626 ms | 3968 KB |
21.txt | AC | 640 ms | 3968 KB |
22.txt | AC | 625 ms | 3968 KB |
23.txt | AC | 625 ms | 3968 KB |
24.txt | AC | 613 ms | 3712 KB |
25.txt | AC | 428 ms | 2688 KB |
26.txt | AC | 379 ms | 2688 KB |
27.txt | AC | 622 ms | 3840 KB |
28.txt | AC | 429 ms | 2688 KB |
29.txt | AC | 643 ms | 3712 KB |
30.txt | AC | 453 ms | 2816 KB |
31.txt | AC | 616 ms | 4096 KB |
32.txt | AC | 423 ms | 2816 KB |
33.txt | AC | 383 ms | 2688 KB |
34.txt | AC | 619 ms | 4096 KB |
35.txt | AC | 615 ms | 4096 KB |
36.txt | AC | 1 ms | 256 KB |
37.txt | AC | 217 ms | 1280 KB |