Submission #1294397
Source Code Expand
#include<iostream> #include<vector> #include<algorithm> using namespace std; int n, l[100009], r[100009], s[1000009], used[1000009], bit[1000009]; vector<pair<int, int>>F[1000005], G[1000005]; vector<int>H; void add(int s, int x) { while (s <= n) { bit[s] += x; s += (s&-s); } } int sum(int s) { int x = 0; while (s >= 1) { x += bit[s]; s -= (s&-s); }return x; } int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> l[i] >> r[i]; F[r[i]].push_back(make_pair(l[i], i)); G[l[i]].push_back(make_pair(r[i], i)); } s[0] = -1; for (int i = 1; i <= 1000000; i++) { s[i] = s[i - 1]; for (int j = 0; j < (int)F[i].size(); j++) { s[i] = max(s[i], max(s[i - 1], F[i][j].first)); } } int R = 1000000; while (R != -1) { H.push_back(R); R = s[R]; } H.pop_back(); reverse(H.begin(), H.end()); cout << H.size() << endl; int P = 0; for (int i = 0; i < H.size(); i++) { if (i)cout << ' '; for (int j = P + 1; j <= H[i]; j++) { for (int k = 0; k < F[j].size(); k++) { if (used[F[j][k].second] == 0) { add(F[j][k].second, 1); used[F[j][k].second] = 1; } } } int L = 0, R = n + 2, M, Q; while (true) { M = (L + R) / 2; int F1 = sum(M - 1), F2 = sum(M); if (F1 == 0 && F2 != 0) { cout << M; used[M] = 2; add(M, -1); Q = r[M]; break; } if (F2 == 0)L = M; else R = M; } for (int j = P; j < Q; j++) { for (int k = 0; k < G[j].size(); k++) { if (used[G[j][k].second] <= 1) { if (used[G[j][k].second] == 1)add(G[j][k].second, -1); used[G[j][k].second] = 2; } } } P = Q; } cout << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - 仕事計画 |
User | E869120 |
Language | C++14 (GCC 5.4.1) |
Score | 100 |
Code Size | 1616 Byte |
Status | AC |
Exec Time | 200 ms |
Memory | 64248 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 100 / 100 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample1.txt, sample2.txt, sample3.txt |
All | 0.txt, 1.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 2.txt, 20.txt, 21.txt, 22.txt, 23.txt, 3.txt, 4.txt, 5.txt, 6.txt, 7.txt, 8.txt, 9.txt, sample1.txt, sample2.txt, sample3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0.txt | AC | 23 ms | 54784 KB |
1.txt | AC | 24 ms | 54784 KB |
10.txt | AC | 24 ms | 54784 KB |
11.txt | AC | 27 ms | 54784 KB |
12.txt | AC | 24 ms | 54784 KB |
13.txt | AC | 24 ms | 54784 KB |
14.txt | AC | 27 ms | 54784 KB |
15.txt | AC | 24 ms | 54784 KB |
16.txt | AC | 24 ms | 54784 KB |
17.txt | AC | 28 ms | 54784 KB |
18.txt | AC | 67 ms | 59776 KB |
19.txt | AC | 81 ms | 60160 KB |
2.txt | AC | 25 ms | 54784 KB |
20.txt | AC | 153 ms | 63488 KB |
21.txt | AC | 65 ms | 59904 KB |
22.txt | AC | 82 ms | 59776 KB |
23.txt | AC | 200 ms | 64248 KB |
3.txt | AC | 24 ms | 54784 KB |
4.txt | AC | 23 ms | 54784 KB |
5.txt | AC | 25 ms | 54784 KB |
6.txt | AC | 24 ms | 54784 KB |
7.txt | AC | 24 ms | 54784 KB |
8.txt | AC | 26 ms | 54784 KB |
9.txt | AC | 24 ms | 54784 KB |
sample1.txt | AC | 23 ms | 54784 KB |
sample2.txt | AC | 24 ms | 54784 KB |
sample3.txt | AC | 23 ms | 54784 KB |