#include <bits/stdc++.h>
using namespace std;
//char dp[2222][33333];
int pref[2222][33333];
int n, m, k;
int check(int l, int r) {
if (r - l + 1 < m) return 0;
for (int j = 1; j <= m; j++) {
if (pref[j][r] - pref[j][l-1] == 0)
return 0;
}
return 1;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> k;
for (int i = 0; i < k; i++) {
int a, b;
cin >> a >> b;
pref[b][a] = 1;
}
for (int j = 1; j <= m; j++) {
for (int i = 1; i <= n; i++) {
pref[j][i] += pref[j][i-1];
}
}
long long ans = 0;
for (int l = 1, r = 1; l <= n; l++) {
while (r <= n && !check(l, r)) r++;
if (r <= n) {
ans += n - r + 1;
}
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
4 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
16 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
460 KB |
Output is correct |
22 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
23 |
Correct |
1 ms |
460 KB |
Output is correct |
24 |
Correct |
1 ms |
460 KB |
Output is correct |
25 |
Correct |
2 ms |
844 KB |
Output is correct |
26 |
Incorrect |
1 ms |
844 KB |
Output isn't correct |
27 |
Correct |
1 ms |
844 KB |
Output is correct |
28 |
Incorrect |
1 ms |
844 KB |
Output isn't correct |
29 |
Correct |
2 ms |
844 KB |
Output is correct |
30 |
Correct |
2 ms |
844 KB |
Output is correct |
31 |
Correct |
12 ms |
4300 KB |
Output is correct |
32 |
Incorrect |
4 ms |
4300 KB |
Output isn't correct |
33 |
Correct |
4 ms |
4300 KB |
Output is correct |
34 |
Incorrect |
4 ms |
4300 KB |
Output isn't correct |
35 |
Correct |
15 ms |
4388 KB |
Output is correct |
36 |
Correct |
13 ms |
4380 KB |
Output is correct |
37 |
Correct |
46 ms |
14232 KB |
Output is correct |
38 |
Correct |
34 ms |
14284 KB |
Output is correct |
39 |
Incorrect |
286 ms |
86980 KB |
Output isn't correct |
40 |
Correct |
89 ms |
86896 KB |
Output is correct |
41 |
Correct |
279 ms |
86864 KB |
Output is correct |
42 |
Correct |
126 ms |
63116 KB |
Output is correct |
43 |
Correct |
143 ms |
63092 KB |
Output is correct |
44 |
Correct |
369 ms |
125984 KB |
Output is correct |
45 |
Correct |
1215 ms |
243468 KB |
Output is correct |
46 |
Execution timed out |
1602 ms |
243904 KB |
Time limit exceeded |
47 |
Correct |
750 ms |
243172 KB |
Output is correct |
48 |
Correct |
763 ms |
243268 KB |
Output is correct |
49 |
Execution timed out |
1598 ms |
243880 KB |
Time limit exceeded |
50 |
Incorrect |
918 ms |
243268 KB |
Output isn't correct |