# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
80633 |
2018-10-21T19:58:14 Z |
qkxwsm |
Seats (IOI18_seats) |
C++14 |
|
4000 ms |
121868 KB |
#include "seats.h"
#include <bits/stdc++.h>
using namespace std;
#define MP make_pair
#define fi first
#define se second
#define INF 1000000007
#define MAXN 1048577
typedef pair<int, int> pii;
typedef pair<pii, pii> ppp;
typedef pair<pii, int> ppi;
int N, M, K;
pii coor[MAXN];
vector<int> grid[MAXN];
pii lazy[2 * MAXN];
ppi stor[2 * MAXN];
ppi comb(ppi a, ppi b)
{
ppi res = {{0, 0}, 0};
if (a.fi <= b.fi)
{
res.fi = a.fi;
res.se += a.se;
}
if (b.fi <= a.fi)
{
res.fi = b.fi;
res.se += b.se;
}
return res;
}
void build(int w, int L, int R)
{
stor[w] = {{0, 0}, 1};
lazy[w] = {0, 0};
if (L == R) return;
int mid = (L + R) >> 1;
build(w << 1, L, mid);
build(w << 1 | 1, mid + 1, R);
stor[w] = comb(stor[w << 1], stor[w << 1 | 1]);
}
void push(int w, int L, int R)
{
stor[w].fi.fi += lazy[w].fi; stor[w].fi.se += lazy[w].se;
if (L != R)
{
lazy[w << 1].fi += lazy[w].fi; lazy[w << 1].se += lazy[w].se;
lazy[w << 1 | 1].fi += lazy[w].fi; lazy[w << 1 | 1].se += lazy[w].se;
}
lazy[w] = {0, 0};
}
void update(int w, int L, int R, int a, int b, pii v)
{
push(w, L, R);
if (b < L || R < a) return;
if (a <= L && R <= b)
{
lazy[w].fi += v.fi; lazy[w].se += v.se;
push(w, L, R);
return;
}
int mid = (L + R) >> 1;
update(w << 1, L, mid, a, b, v);
update(w << 1 | 1, mid + 1, R, a, b, v);
stor[w] = comb(stor[w << 1], stor[w << 1 | 1]);
}
void upd(int l, int r, pii p)
{
r = min(r, K - 1);
l = max(l, 0);
if (l > r) return;
update(1, 0, K - 1, l, r, p);
}
ppp sort4(int a, int b, int c, int d)
{
if (a > b) swap(a, b); if (b > c) swap(b, c); if (c > d) swap(c, d);
if (a > b) swap(a, b); if (b > c) swap(b, c); if (c > d) swap(c, d);
if (a > b) swap(a, b); if (b > c) swap(b, c); if (c > d) swap(c, d);
return {{a, b}, {c, d}};
}
void give_initial_chart(int h, int w, vector<int> R, vector<int> C)
{
N = h + 2;
M = w + 2;
K = w * h;
for (int i = 0; i < N; i++)
{
grid[i].resize(M);
}
for (int i = 0; i < N; i++)
{
for (int j = 0; j < M; j++)
{
if (i == 0 || i == N - 1 || j == 0 || j == M - 1)
{
grid[i][j] = K; K++;
}
}
}
K = w * h;
for (int i = 0; i < K; i++)
{
R[i]++; C[i]++;
coor[i] = {R[i], C[i]};
grid[R[i]][C[i]] = i;
}
build(1, 0, K - 1);
for (int i = 0; i < N - 1; i++)
{
for (int j = 0; j < M - 1; j++)
{
ppp p = sort4(grid[i][j], grid[i + 1][j], grid[i][j + 1], grid[i + 1][j + 1]);
upd(p.se.fi, p.se.se - 1, {1, 0});
upd(p.fi.fi, p.fi.se - 1, {0, 1});
}
}
}
int swap_seats(int a, int b)
{
pii p0 = coor[a], p1 = coor[b];
for (int i = -1; i <= 0; i++)
{
for (int j = -1; j <= 0; j++)
{
int x = p0.fi + i, y = p0.se + j;
ppp p = sort4(grid[x][y], grid[x + 1][y], grid[x][y + 1], grid[x + 1][y + 1]);
upd(p.se.fi, p.se.se - 1, {-1, 0});
upd(p.fi.fi, p.fi.se - 1, {0, -1});
}
}
for (int i = -1; i <= 0; i++)
{
for (int j = -1; j <= 0; j++)
{
int x = p1.fi + i, y = p1.se + j;
ppp p = sort4(grid[x][y], grid[x + 1][y], grid[x][y + 1], grid[x + 1][y + 1]);
upd(p.se.fi, p.se.se - 1, {-1, 0});
upd(p.fi.fi, p.fi.se - 1, {0, -1});
}
}
swap(coor[a], coor[b]);
swap(grid[p0.fi][p0.se], grid[p1.fi][p1.se]);
for (int i = -1; i <= 0; i++)
{
for (int j = -1; j <= 0; j++)
{
int x = p0.fi + i, y = p0.se + j;
ppp p = sort4(grid[x][y], grid[x + 1][y], grid[x][y + 1], grid[x + 1][y + 1]);
upd(p.se.fi, p.se.se - 1, {1, 0});
upd(p.fi.fi, p.fi.se - 1, {0, 1});
}
}
for (int i = -1; i <= 0; i++)
{
for (int j = -1; j <= 0; j++)
{
int x = p1.fi + i, y = p1.se + j;
ppp p = sort4(grid[x][y], grid[x + 1][y], grid[x][y + 1], grid[x + 1][y + 1]);
upd(p.se.fi, p.se.se - 1, {1, 0});
upd(p.fi.fi, p.fi.se - 1, {0, 1});
}
}
push(1, 0, K - 1);
return stor[1].se;
}
Compilation message
seats.cpp: In function 'ppp sort4(int, int, int, int)':
seats.cpp:82:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if (a > b) swap(a, b); if (b > c) swap(b, c); if (c > d) swap(c, d);
^~
seats.cpp:82:25: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
if (a > b) swap(a, b); if (b > c) swap(b, c); if (c > d) swap(c, d);
^~
seats.cpp:83:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if (a > b) swap(a, b); if (b > c) swap(b, c); if (c > d) swap(c, d);
^~
seats.cpp:83:25: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
if (a > b) swap(a, b); if (b > c) swap(b, c); if (c > d) swap(c, d);
^~
seats.cpp:84:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if (a > b) swap(a, b); if (b > c) swap(b, c); if (c > d) swap(c, d);
^~
seats.cpp:84:25: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
if (a > b) swap(a, b); if (b > c) swap(b, c); if (c > d) swap(c, d);
^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
25080 KB |
Output is correct |
2 |
Correct |
80 ms |
25252 KB |
Output is correct |
3 |
Correct |
102 ms |
25252 KB |
Output is correct |
4 |
Correct |
54 ms |
25264 KB |
Output is correct |
5 |
Correct |
48 ms |
25320 KB |
Output is correct |
6 |
Correct |
68 ms |
25320 KB |
Output is correct |
7 |
Correct |
70 ms |
25352 KB |
Output is correct |
8 |
Correct |
65 ms |
25356 KB |
Output is correct |
9 |
Correct |
66 ms |
25544 KB |
Output is correct |
10 |
Correct |
72 ms |
25544 KB |
Output is correct |
11 |
Correct |
66 ms |
25544 KB |
Output is correct |
12 |
Correct |
52 ms |
25544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
25080 KB |
Output is correct |
2 |
Correct |
80 ms |
25252 KB |
Output is correct |
3 |
Correct |
102 ms |
25252 KB |
Output is correct |
4 |
Correct |
54 ms |
25264 KB |
Output is correct |
5 |
Correct |
48 ms |
25320 KB |
Output is correct |
6 |
Correct |
68 ms |
25320 KB |
Output is correct |
7 |
Correct |
70 ms |
25352 KB |
Output is correct |
8 |
Correct |
65 ms |
25356 KB |
Output is correct |
9 |
Correct |
66 ms |
25544 KB |
Output is correct |
10 |
Correct |
72 ms |
25544 KB |
Output is correct |
11 |
Correct |
66 ms |
25544 KB |
Output is correct |
12 |
Correct |
52 ms |
25544 KB |
Output is correct |
13 |
Correct |
136 ms |
26264 KB |
Output is correct |
14 |
Correct |
152 ms |
26272 KB |
Output is correct |
15 |
Correct |
99 ms |
26340 KB |
Output is correct |
16 |
Correct |
77 ms |
26656 KB |
Output is correct |
17 |
Correct |
121 ms |
26656 KB |
Output is correct |
18 |
Correct |
117 ms |
26656 KB |
Output is correct |
19 |
Correct |
114 ms |
26656 KB |
Output is correct |
20 |
Correct |
96 ms |
26656 KB |
Output is correct |
21 |
Correct |
79 ms |
26656 KB |
Output is correct |
22 |
Correct |
79 ms |
26668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3428 ms |
93712 KB |
Output is correct |
2 |
Correct |
1791 ms |
94524 KB |
Output is correct |
3 |
Correct |
1791 ms |
94604 KB |
Output is correct |
4 |
Correct |
1510 ms |
94604 KB |
Output is correct |
5 |
Correct |
1561 ms |
94604 KB |
Output is correct |
6 |
Correct |
1478 ms |
94604 KB |
Output is correct |
7 |
Correct |
1591 ms |
94604 KB |
Output is correct |
8 |
Correct |
1708 ms |
94604 KB |
Output is correct |
9 |
Correct |
1720 ms |
94604 KB |
Output is correct |
10 |
Correct |
1726 ms |
94604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
140 ms |
94604 KB |
Output is correct |
2 |
Correct |
289 ms |
94604 KB |
Output is correct |
3 |
Correct |
1543 ms |
94604 KB |
Output is correct |
4 |
Correct |
3501 ms |
94604 KB |
Output is correct |
5 |
Correct |
1404 ms |
102288 KB |
Output is correct |
6 |
Correct |
3314 ms |
121868 KB |
Output is correct |
7 |
Correct |
1514 ms |
121868 KB |
Output is correct |
8 |
Correct |
1746 ms |
121868 KB |
Output is correct |
9 |
Correct |
1730 ms |
121868 KB |
Output is correct |
10 |
Correct |
1650 ms |
121868 KB |
Output is correct |
11 |
Correct |
1541 ms |
121868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
91 ms |
121868 KB |
Output is correct |
2 |
Correct |
170 ms |
121868 KB |
Output is correct |
3 |
Correct |
280 ms |
121868 KB |
Output is correct |
4 |
Correct |
367 ms |
121868 KB |
Output is correct |
5 |
Correct |
579 ms |
121868 KB |
Output is correct |
6 |
Correct |
2283 ms |
121868 KB |
Output is correct |
7 |
Correct |
2634 ms |
121868 KB |
Output is correct |
8 |
Correct |
2132 ms |
121868 KB |
Output is correct |
9 |
Execution timed out |
4062 ms |
121868 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
25080 KB |
Output is correct |
2 |
Correct |
80 ms |
25252 KB |
Output is correct |
3 |
Correct |
102 ms |
25252 KB |
Output is correct |
4 |
Correct |
54 ms |
25264 KB |
Output is correct |
5 |
Correct |
48 ms |
25320 KB |
Output is correct |
6 |
Correct |
68 ms |
25320 KB |
Output is correct |
7 |
Correct |
70 ms |
25352 KB |
Output is correct |
8 |
Correct |
65 ms |
25356 KB |
Output is correct |
9 |
Correct |
66 ms |
25544 KB |
Output is correct |
10 |
Correct |
72 ms |
25544 KB |
Output is correct |
11 |
Correct |
66 ms |
25544 KB |
Output is correct |
12 |
Correct |
52 ms |
25544 KB |
Output is correct |
13 |
Correct |
136 ms |
26264 KB |
Output is correct |
14 |
Correct |
152 ms |
26272 KB |
Output is correct |
15 |
Correct |
99 ms |
26340 KB |
Output is correct |
16 |
Correct |
77 ms |
26656 KB |
Output is correct |
17 |
Correct |
121 ms |
26656 KB |
Output is correct |
18 |
Correct |
117 ms |
26656 KB |
Output is correct |
19 |
Correct |
114 ms |
26656 KB |
Output is correct |
20 |
Correct |
96 ms |
26656 KB |
Output is correct |
21 |
Correct |
79 ms |
26656 KB |
Output is correct |
22 |
Correct |
79 ms |
26668 KB |
Output is correct |
23 |
Correct |
3428 ms |
93712 KB |
Output is correct |
24 |
Correct |
1791 ms |
94524 KB |
Output is correct |
25 |
Correct |
1791 ms |
94604 KB |
Output is correct |
26 |
Correct |
1510 ms |
94604 KB |
Output is correct |
27 |
Correct |
1561 ms |
94604 KB |
Output is correct |
28 |
Correct |
1478 ms |
94604 KB |
Output is correct |
29 |
Correct |
1591 ms |
94604 KB |
Output is correct |
30 |
Correct |
1708 ms |
94604 KB |
Output is correct |
31 |
Correct |
1720 ms |
94604 KB |
Output is correct |
32 |
Correct |
1726 ms |
94604 KB |
Output is correct |
33 |
Correct |
140 ms |
94604 KB |
Output is correct |
34 |
Correct |
289 ms |
94604 KB |
Output is correct |
35 |
Correct |
1543 ms |
94604 KB |
Output is correct |
36 |
Correct |
3501 ms |
94604 KB |
Output is correct |
37 |
Correct |
1404 ms |
102288 KB |
Output is correct |
38 |
Correct |
3314 ms |
121868 KB |
Output is correct |
39 |
Correct |
1514 ms |
121868 KB |
Output is correct |
40 |
Correct |
1746 ms |
121868 KB |
Output is correct |
41 |
Correct |
1730 ms |
121868 KB |
Output is correct |
42 |
Correct |
1650 ms |
121868 KB |
Output is correct |
43 |
Correct |
1541 ms |
121868 KB |
Output is correct |
44 |
Correct |
91 ms |
121868 KB |
Output is correct |
45 |
Correct |
170 ms |
121868 KB |
Output is correct |
46 |
Correct |
280 ms |
121868 KB |
Output is correct |
47 |
Correct |
367 ms |
121868 KB |
Output is correct |
48 |
Correct |
579 ms |
121868 KB |
Output is correct |
49 |
Correct |
2283 ms |
121868 KB |
Output is correct |
50 |
Correct |
2634 ms |
121868 KB |
Output is correct |
51 |
Correct |
2132 ms |
121868 KB |
Output is correct |
52 |
Execution timed out |
4062 ms |
121868 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |