#include <bits/stdc++.h>
using namespace std;
char dp[2002][30003];
int pref[2002][30003];
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;
dp[b][a] = 1;
}
for (int j = 1; j <= m; j++) {
for (int i = 1; i <= n; i++) {
pref[j][i] = pref[j][i-1] + dp[j][i];
}
}
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 |
1 ms |
332 KB |
Output is correct |
2 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
5 |
Correct |
1 ms |
320 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 |
332 KB |
Output is correct |
9 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
15 |
Incorrect |
0 ms |
316 KB |
Output isn't correct |
16 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
716 KB |
Output is correct |
20 |
Correct |
1 ms |
716 KB |
Output is correct |
21 |
Correct |
1 ms |
700 KB |
Output is correct |
22 |
Incorrect |
1 ms |
708 KB |
Output isn't correct |
23 |
Correct |
1 ms |
704 KB |
Output is correct |
24 |
Correct |
1 ms |
716 KB |
Output is correct |
25 |
Correct |
2 ms |
1348 KB |
Output is correct |
26 |
Incorrect |
2 ms |
1356 KB |
Output isn't correct |
27 |
Correct |
1 ms |
1356 KB |
Output is correct |
28 |
Incorrect |
1 ms |
1344 KB |
Output isn't correct |
29 |
Correct |
2 ms |
1356 KB |
Output is correct |
30 |
Correct |
2 ms |
1356 KB |
Output is correct |
31 |
Correct |
11 ms |
7244 KB |
Output is correct |
32 |
Incorrect |
6 ms |
6824 KB |
Output isn't correct |
33 |
Correct |
5 ms |
5700 KB |
Output is correct |
34 |
Incorrect |
5 ms |
6348 KB |
Output isn't correct |
35 |
Correct |
17 ms |
7240 KB |
Output is correct |
36 |
Correct |
16 ms |
7048 KB |
Output is correct |
37 |
Correct |
51 ms |
21132 KB |
Output is correct |
38 |
Correct |
34 ms |
19088 KB |
Output is correct |
39 |
Incorrect |
286 ms |
94972 KB |
Output isn't correct |
40 |
Correct |
96 ms |
106180 KB |
Output is correct |
41 |
Correct |
284 ms |
110600 KB |
Output is correct |
42 |
Correct |
140 ms |
67680 KB |
Output is correct |
43 |
Correct |
151 ms |
67668 KB |
Output is correct |
44 |
Correct |
368 ms |
134980 KB |
Output is correct |
45 |
Runtime error |
242 ms |
262148 KB |
Execution killed with signal 9 |
46 |
Runtime error |
249 ms |
262148 KB |
Execution killed with signal 9 |
47 |
Correct |
731 ms |
244052 KB |
Output is correct |
48 |
Correct |
724 ms |
244048 KB |
Output is correct |
49 |
Runtime error |
259 ms |
262148 KB |
Execution killed with signal 9 |
50 |
Incorrect |
879 ms |
243328 KB |
Output isn't correct |