Submission #282058

#TimeUsernameProblemLanguageResultExecution timeMemory
282058dooweySeats (IOI18_seats)C++14
37 / 100
4038 ms103720 KiB
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #include "seats.h" using namespace std; typedef long long ll; typedef pair<int, int> pii; #define fi first #define se second #define mp make_pair const int M = (int)1e6 + 10; int cur; int pi[M], pj[M]; vector<vector<int>> tt; int val[M * 4 + 512]; int cnt[M * 4 + 512]; int lazy[M * 4 + 512]; void push(int node, int cl, int cr){ val[node] += lazy[node]; if(cl != cr){ lazy[node << 1] += lazy[node]; lazy[node << 1 | 1] += lazy[node]; } lazy[node] = 0; } void upd(int node, int cl, int cr, int tl, int tr, int x){ push(node, cl, cr); if(cr < tl || cl > tr) return; if(cl >= tl && cr <= tr){ lazy[node] = x; push(node, cl, cr); return; } int mid = (cl + cr) >> 1; upd(node << 1, cl, mid, tl, tr, x); upd(node << 1 | 1, mid + 1, cr, tl, tr, x); if(val[node << 1] == val[node << 1 | 1]){ val[node] = val[node << 1]; cnt[node] = cnt[node << 1] + cnt[node << 1 | 1]; } else if(val[node << 1] < val[node << 1 | 1]){ val[node] = val[node << 1]; cnt[node] = cnt[node << 1]; } else{ val[node] = val[node << 1 | 1]; cnt[node] = cnt[node << 1 | 1]; } } void upd_rect(int i, int j, int v){ vector<int> tc; for(int p = 0; p < 2; p ++ ){ for(int q = 0; q < 2; q ++ ){ tc.push_back(tt[i + p][j + q]); } } sort(tc.begin(), tc.end()); if(tc[0] < tc[1]) upd(1, 0, cur - 1, tc[0], tc[1] - 1, v); if(tc[2] < tc[3]) upd(1, 0, cur - 1, tc[2], tc[3] - 1, 4 * v); } void build(int node, int cl, int cr){ if(cl == cr){ cnt[node] = 1; return; } int mid = (cl + cr) >> 1; build(node << 1, cl, mid); build(node << 1 | 1, mid + 1, cr); cnt[node] = cnt[node << 1] + cnt[node << 1 | 1]; } void give_initial_chart(int H, int W, vector<int> R, vector<int> C) { cur = H * W; tt.resize(H + 2); for(int i = 0 ; i <= H + 1;i ++ ) tt[i].resize(W + 2, cur); for(int i = 0 ; i < cur ;i ++ ){ R[i] ++ ; C[i] ++ ; pi[i] = R[i]; pj[i] = C[i]; tt[R[i]][C[i]] = i; } build(1, 0, cur - 1); for(int i = 0 ; i <= H; i ++ ){ for(int j = 0 ; j <= W; j ++ ){ upd_rect(i, j, +1); } } } int swap_seats(int a, int b) { for(int i = -1; i <= 0; i ++ ){ for(int j = -1; j <= 0 ; j ++ ){ upd_rect(pi[a] + i, pj[a] + j,-1); upd_rect(pi[b] + i, pj[b] + j,-1); } } swap(tt[pi[a]][pj[a]], tt[pi[b]][pj[b]]); swap(pi[a], pi[b]); swap(pj[a], pj[b]); for(int i = -1; i <= 0; i ++ ){ for(int j = -1; j <= 0 ; j ++ ){ upd_rect(pi[a] + i, pj[a] + j,+1); upd_rect(pi[b] + i, pj[b] + j,+1); } } return cnt[1]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...