Submission #144280

#TimeUsernameProblemLanguageResultExecution timeMemory
144280MinnakhmetovSeats (IOI18_seats)C++14
0 / 100
4043 ms39544 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) { 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]); ans -= rect[i]; 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...