Submission #172991

#TimeUsernameProblemLanguageResultExecution timeMemory
172991keko37Seats (IOI18_seats)C++14
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> using namespace std; typedef long long llint; typedef pair <int, int> pi; const int MAXN = 1000005; const llint INF = 1000000000000000000LL; const int BIG = 1000000000; int n, m, ofs = 1; vector <int> r, c; vector < vector <int> > v; llint a[MAXN], b[MAXN]; int dx[4] = {0, 0, 1, 1}; int dy[4] = {0, 1, 0, 1}; struct node { llint mn, prop; int br; node () { mn = 0; br = 1; prop = 0; } node (llint _mn, int _br) { mn = _mn; br = _br; prop = 0; } } t[MAXN * 4]; node spoji (node a, node b) { if (a.mn < b.mn) return a; if (a.mn > b.mn) return b; return node(a.mn, a.br + b.br); } void tour_init () { while (ofs < n*m) ofs *= 2; for (int i = n*m; i < ofs; i++) { t[i + ofs] = node(INF, 1); } for (int i = ofs - 1; i > 0; i--) { t[i] = spoji(t[2 * i], t[2 * i + 1]); } } void propagate (int x) { if (t[x].prop == 0) return; if (x < ofs) { t[2*x].prop += t[x].prop; t[2*x+1].prop += t[x].prop; } t[x].mn += t[x].prop; t[x].prop = 0; } int from, to, val; void update (int x, int lo, int hi) { propagate(x); if (to < lo || hi < from) return; if (from <= lo && hi <= to) { t[x].prop += val; propagate(x); return; } update(2*x, lo, (lo + hi) / 2); update(2*x+1, (lo + hi) / 2 + 1, hi); t[x] = spoji(t[2*x], t[2*x+1]); } node upit (int x, int lo, int hi) { propagate(x); if (to < lo || hi < from) return node(INF, 0); if (from <= lo && hi <= to) return t[x]; return spoji(upit(2*x, lo, (lo + hi) / 2), upit(2*x+1, (lo + hi) / 2 + 1, hi)); } void two_by_two (int x, int y, int d) { int w[4] = {v[x][y], v[x][y + 1], v[x + 1][y], v[x + 1][y + 1]}; sort(w, w + 4); if (w[0] < w[1]) {from = w[0]; to = w[1] - 1; val = d; update(1, 0, ofs - 1);} if (w[2] < w[3]) {from = w[2]; to = w[3] - 1; val = BIG * d; update(1, 0, ofs - 1);} } void give_initial_chart (int N, int M, vector <int> R, vector <int> C) { n = N; m = M; r = R; c = C; vector <int> e(m + 2, BIG); for (int i = 0; i < n + 2; i++) v.push_back(e); for (int i = 0; i < n * m; i++) { v[R[i] + 1][C[i] + 1] = i; } tour_init(); for (int i = 0; i <= n; i++) { for (int j = 0; j <= m; j++) { two_by_two(i, j, 1); } } } int swap_seats (int a, int b) { vector <pi> u; for (int i = 0; i < 4; i++) u.push_back({r[a] + dx[i], c[a] + dy[i]}); for (int i = 0; i < 4; i++) u.push_back({r[b] + dx[i], c[b] + dy[i]}); sort(u.begin(), u.end()); u.erase(unique(u.begin(), u.end()), u.end()); for (auto p : u) two_by_two(p.first, p.second, -1); swap(v[r[a] + 1][c[a] + 1], v[r[b] + 1][c[b] + 1]); swap(r[a], r[b]); swap(c[a], c[b]); for (auto p : u) two_by_two(p.first, p.second, 1); from = 0; to = ofs - 1; node res = upit(1, 0, ofs - 1); if (res.mn > 4) return 0; return res.br; } int main () { ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector <int> r(n*m), c(n*m); for (int i = 0; i < n*m; i++) cin >> r[i]; for (int i = 0; i < n*m; i++) cin >> c[i]; give_initial_chart(n, m, r, c); int q; cin >> q; for (int i = 0; i < q; i++) { int a, b; cin >> a >> b; cout << swap_seats(a, b) << endl; } return 0; }

Compilation message (stderr)

/tmp/cczyXLdS.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/cclmVT5M.o:seats.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status