# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
80630 |
2018-10-21T19:47:04 Z |
qkxwsm |
Seats (IOI18_seats) |
C++14 |
|
3595 ms |
263168 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 1050013
typedef pair<int, int> pii;
typedef pair<pii, pii> ppp;
typedef pair<pii, int> ppi;
int N, M, K;
pii coor[MAXN];
vector<vector<int> > grid;
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;
grid.resize(N);
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: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);
^~
seats.cpp:85: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:85: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 |
33 ms |
504 KB |
Output is correct |
2 |
Correct |
51 ms |
732 KB |
Output is correct |
3 |
Correct |
72 ms |
732 KB |
Output is correct |
4 |
Correct |
30 ms |
732 KB |
Output is correct |
5 |
Correct |
35 ms |
784 KB |
Output is correct |
6 |
Correct |
45 ms |
784 KB |
Output is correct |
7 |
Correct |
47 ms |
784 KB |
Output is correct |
8 |
Correct |
46 ms |
784 KB |
Output is correct |
9 |
Correct |
47 ms |
784 KB |
Output is correct |
10 |
Correct |
51 ms |
784 KB |
Output is correct |
11 |
Correct |
45 ms |
800 KB |
Output is correct |
12 |
Correct |
27 ms |
800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
504 KB |
Output is correct |
2 |
Correct |
51 ms |
732 KB |
Output is correct |
3 |
Correct |
72 ms |
732 KB |
Output is correct |
4 |
Correct |
30 ms |
732 KB |
Output is correct |
5 |
Correct |
35 ms |
784 KB |
Output is correct |
6 |
Correct |
45 ms |
784 KB |
Output is correct |
7 |
Correct |
47 ms |
784 KB |
Output is correct |
8 |
Correct |
46 ms |
784 KB |
Output is correct |
9 |
Correct |
47 ms |
784 KB |
Output is correct |
10 |
Correct |
51 ms |
784 KB |
Output is correct |
11 |
Correct |
45 ms |
800 KB |
Output is correct |
12 |
Correct |
27 ms |
800 KB |
Output is correct |
13 |
Correct |
114 ms |
1636 KB |
Output is correct |
14 |
Correct |
132 ms |
1652 KB |
Output is correct |
15 |
Correct |
81 ms |
1804 KB |
Output is correct |
16 |
Correct |
57 ms |
2108 KB |
Output is correct |
17 |
Correct |
102 ms |
2108 KB |
Output is correct |
18 |
Correct |
97 ms |
2108 KB |
Output is correct |
19 |
Correct |
93 ms |
2108 KB |
Output is correct |
20 |
Correct |
82 ms |
2108 KB |
Output is correct |
21 |
Correct |
59 ms |
2108 KB |
Output is correct |
22 |
Correct |
63 ms |
2108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3484 ms |
69308 KB |
Output is correct |
2 |
Correct |
1793 ms |
85308 KB |
Output is correct |
3 |
Correct |
1756 ms |
101132 KB |
Output is correct |
4 |
Correct |
1551 ms |
117100 KB |
Output is correct |
5 |
Correct |
1578 ms |
133180 KB |
Output is correct |
6 |
Correct |
1539 ms |
149064 KB |
Output is correct |
7 |
Correct |
1616 ms |
164904 KB |
Output is correct |
8 |
Correct |
1717 ms |
180972 KB |
Output is correct |
9 |
Correct |
1779 ms |
196972 KB |
Output is correct |
10 |
Correct |
1642 ms |
213016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
213016 KB |
Output is correct |
2 |
Correct |
263 ms |
213016 KB |
Output is correct |
3 |
Correct |
1553 ms |
213016 KB |
Output is correct |
4 |
Correct |
3595 ms |
229124 KB |
Output is correct |
5 |
Correct |
1485 ms |
252924 KB |
Output is correct |
6 |
Runtime error |
3369 ms |
263168 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
70 ms |
263168 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
504 KB |
Output is correct |
2 |
Correct |
51 ms |
732 KB |
Output is correct |
3 |
Correct |
72 ms |
732 KB |
Output is correct |
4 |
Correct |
30 ms |
732 KB |
Output is correct |
5 |
Correct |
35 ms |
784 KB |
Output is correct |
6 |
Correct |
45 ms |
784 KB |
Output is correct |
7 |
Correct |
47 ms |
784 KB |
Output is correct |
8 |
Correct |
46 ms |
784 KB |
Output is correct |
9 |
Correct |
47 ms |
784 KB |
Output is correct |
10 |
Correct |
51 ms |
784 KB |
Output is correct |
11 |
Correct |
45 ms |
800 KB |
Output is correct |
12 |
Correct |
27 ms |
800 KB |
Output is correct |
13 |
Correct |
114 ms |
1636 KB |
Output is correct |
14 |
Correct |
132 ms |
1652 KB |
Output is correct |
15 |
Correct |
81 ms |
1804 KB |
Output is correct |
16 |
Correct |
57 ms |
2108 KB |
Output is correct |
17 |
Correct |
102 ms |
2108 KB |
Output is correct |
18 |
Correct |
97 ms |
2108 KB |
Output is correct |
19 |
Correct |
93 ms |
2108 KB |
Output is correct |
20 |
Correct |
82 ms |
2108 KB |
Output is correct |
21 |
Correct |
59 ms |
2108 KB |
Output is correct |
22 |
Correct |
63 ms |
2108 KB |
Output is correct |
23 |
Correct |
3484 ms |
69308 KB |
Output is correct |
24 |
Correct |
1793 ms |
85308 KB |
Output is correct |
25 |
Correct |
1756 ms |
101132 KB |
Output is correct |
26 |
Correct |
1551 ms |
117100 KB |
Output is correct |
27 |
Correct |
1578 ms |
133180 KB |
Output is correct |
28 |
Correct |
1539 ms |
149064 KB |
Output is correct |
29 |
Correct |
1616 ms |
164904 KB |
Output is correct |
30 |
Correct |
1717 ms |
180972 KB |
Output is correct |
31 |
Correct |
1779 ms |
196972 KB |
Output is correct |
32 |
Correct |
1642 ms |
213016 KB |
Output is correct |
33 |
Correct |
111 ms |
213016 KB |
Output is correct |
34 |
Correct |
263 ms |
213016 KB |
Output is correct |
35 |
Correct |
1553 ms |
213016 KB |
Output is correct |
36 |
Correct |
3595 ms |
229124 KB |
Output is correct |
37 |
Correct |
1485 ms |
252924 KB |
Output is correct |
38 |
Runtime error |
3369 ms |
263168 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
39 |
Halted |
0 ms |
0 KB |
- |