#include <bits/stdc++.h>
using namespace std;
#define forn(i, a, b) for(int i=a; i<=b; ++i)
const int maxN = 3e4 +10;
const int maxM = 2e3 +10;
int matched[maxN];
vector<int> E[maxM];
int le, ri, t = 1;
int N, M, K;
long long result;
int visited[maxM];
vector<int> not_match;
bool visit(int u) {
if (visited[u] == t) return false;
visited[u] = t;
while (E[u].size() && E[u].back() < le) E[u].pop_back();
int k = E[u].size();
for(int i=k-1; i >= 0; --i) {
int v = E[u][i];
if (v <= ri) {
if (!matched[v] || visit(matched[v])) {
matched[v] = u;
return true;
}
}
}
return false;
}
int main() {
ios::sync_with_stdio(0);
cin >> N >> M >> K;
forn(i, 1, K) {
int Ai, Bi;
cin >> Ai >> Bi;
E[Bi].push_back(Ai);
}
forn(i, 1, M) {
sort(E[i].begin(), E[i].end());
reverse(E[i].begin(), E[i].end());
}
forn(i, 1, M) not_match.push_back(i);
for(le = 1; le <= N; ++le) {
if (matched[le-1]) {
not_match.push_back(matched[le-1]);
matched[le-1] = 0;
}
while (ri < N && not_match.size()) {
ri ++;
while (not_match.size()) {
t ++;
if (visit(not_match.back())) not_match.pop_back(); else break;
}
}
if (not_match.empty()) result += N-ri+1;
}
cout << result;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
3 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
8 ms |
504 KB |
Output is correct |
26 |
Incorrect |
3 ms |
504 KB |
Output isn't correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Incorrect |
4 ms |
504 KB |
Output isn't correct |
30 |
Incorrect |
4 ms |
504 KB |
Output isn't correct |
31 |
Correct |
74 ms |
760 KB |
Output is correct |
32 |
Incorrect |
5 ms |
504 KB |
Output isn't correct |
33 |
Correct |
3 ms |
376 KB |
Output is correct |
34 |
Correct |
3 ms |
376 KB |
Output is correct |
35 |
Correct |
52 ms |
936 KB |
Output is correct |
36 |
Correct |
40 ms |
888 KB |
Output is correct |
37 |
Correct |
178 ms |
836 KB |
Output is correct |
38 |
Incorrect |
24 ms |
888 KB |
Output isn't correct |
39 |
Correct |
64 ms |
504 KB |
Output is correct |
40 |
Correct |
5 ms |
504 KB |
Output is correct |
41 |
Incorrect |
9 ms |
632 KB |
Output isn't correct |
42 |
Incorrect |
9 ms |
636 KB |
Output isn't correct |
43 |
Incorrect |
14 ms |
760 KB |
Output isn't correct |
44 |
Incorrect |
23 ms |
988 KB |
Output isn't correct |
45 |
Incorrect |
12 ms |
760 KB |
Output isn't correct |
46 |
Incorrect |
114 ms |
1272 KB |
Output isn't correct |
47 |
Incorrect |
26 ms |
1016 KB |
Output isn't correct |
48 |
Incorrect |
24 ms |
1016 KB |
Output isn't correct |
49 |
Incorrect |
153 ms |
1144 KB |
Output isn't correct |
50 |
Correct |
217 ms |
584 KB |
Output is correct |