제출 #144282

#제출 시각아이디문제언어결과실행 시간메모리
144282Minnakhmetov자리 배치 (IOI18_seats)C++14
17 / 100
4073 ms56568 KiB
#include "seats.h" #include<bits/stdc++.h> using namespace std; const int N = 1e6 + 5, INF = 1e9; int n, m; vector<int> x, y; int lx[N], rx[N], ly[N], ry[N]; bool rect[N]; int ans = 0; void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) { n = H; m = W; x = R; y = C; lx[0] = INF; rx[0] = -1; ly[0] = INF; ry[0] = -1; for (int i = 1; i <= n * m; i++) { lx[i] = min(lx[i - 1], x[i - 1]); rx[i] = max(rx[i - 1], x[i - 1]); ly[i] = min(ly[i - 1], y[i - 1]); ry[i] = max(ry[i - 1], y[i - 1]); if ((rx[i] - lx[i] + 1) * (ry[i] - ly[i] + 1) == i) { rect[i] = 1; ans++; } } } int swap_seats(int a, int b) { if (a > b) swap(a, b); swap(x[a], x[b]); swap(y[a], y[b]); for (int i = a + 1; i <= b + 1; i++) { lx[i] = min(lx[i - 1], x[i - 1]); rx[i] = max(rx[i - 1], x[i - 1]); ly[i] = min(ly[i - 1], y[i - 1]); ry[i] = max(ry[i - 1], y[i - 1]); if (rect[i]) ans--; if ((rx[i] - lx[i] + 1) * (ry[i] - ly[i] + 1) == i) { rect[i] = 1; ans++; } else { rect[i] = 0; } } return ans; }
#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...