제출 #413762

#제출 시각아이디문제언어결과실행 시간메모리
413762LastRonin자리 배치 (IOI18_seats)C++14
31 / 100
4070 ms71200 KiB
#include <bits/stdc++.h> #include "seats.h" #define ll long long #define pb push_back #define si short int #define f first #define s second #define mp make_pair using namespace std; const ll N = 1<<20; const ll big = 1e9; int n, dl; int h, w; int ans = 0; vector<int> R, C; struct segsnizu { int t[2 * N], t2[2 * N], t3[2 * N], t4[2 * N]; void upd(int p, si z, si z2) { int v = dl + p - 1; t[v] = t2[v] = z; t3[v] = t4[v] = z2; v >>= 1; while(v) { t4[v] = min(t4[v * 2], t4[v * 2 + 1]); t3[v] = max(t3[v * 2], t3[v * 2 + 1]); t2[v] = min(t2[v * 2], t2[v * 2 + 1]); t[v] = max(t[v * 2], t[v * 2 + 1]); v >>= 1; } } pair<int, int> get(int l, int r) { l = dl + l - 1, r = dl + r - 1; int ans = -30000, ans2 = 30000, ans3 = -30000, ans4 = 30000; while(l <= r) { if(l&1) { ans = max(t[l], ans); ans2 = min(t2[l], ans2); ans3 = max(t3[l], ans3); ans4 = min(t4[l++], ans4); } if(!(r&1)) { ans = max(t[r], ans); ans2 = min(t2[r], ans2); ans3 = max(t3[r], ans3); ans4 = min(t4[r--], ans4); } l >>= 1, r >>= 1; } return mp((ans - ans2 + 1) * (ans3 - ans4 + 1), min(ans - ans2 + 1, ans3 - ans4 + 1)); } } rt; void give_initial_chart(int H, int W, vector<int> r, vector<int> c) { R = r, C = c; n = H*W; dl = (1<<(__lg(n - 1) + 1)); for(int i = 1; i <= n; i++) { rt.upd(i, r[i - 1], c[i - 1]); } } int swap_seats(int a, int b) { swap(R[a], R[b]), swap(C[a], C[b]); rt.upd(a + 1, R[a], C[a]), rt.upd(b + 1, R[b], C[b]); int ans = 0; for(int i = 1; i <= n;) { pair<int, int> v = rt.get(1, i); v.f -= i; if(v.f == 0) ans++, v.f = v.s; i += v.f; } return ans; } /* int main() { int n, m, q; cin >> n >> m >> q; vector<int> rr, cc; for(int i = 1, a, b; i <= n*m; i++) cin >> a >> b, rr.pb(a), cc.pb(b); give_initial_chart(n, m, rr, cc); while(q--) { ll a, b; cin >> a >> b; cout << swap_seats(a, b) << "\n"; } } */
#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...