Submission #77385

#TimeUsernameProblemLanguageResultExecution timeMemory
77385Just_Solve_The_ProblemSeats (IOI18_seats)C++11
17 / 100
4045 ms54496 KiB
#include <bits/stdc++.h> #include "seats.h" // #include "grader.cpp" #define pii pair < int, int > #define fr first #define sc second #define mk make_pair #define OK puts("ok"); using namespace std; const int N = (int)1e6 + 7; pair < int, int > pos[N]; int h, w; int ans; int was[N]; int mxx[N], mnx[N], mny[N], mxy[N]; void give_initial_chart(int H, int W, vector<int> R, vector<int> C) { h = H; w = W; for (int i = 0; i < H * W; i++) { pos[i] = mk(R[i], C[i]); } mnx[0] = mxx[0] = pos[0].fr; mny[0] = mxy[0] = pos[0].sc; ans = 1; was[0] = 1; for (int i = 1; i < h * w; i++) { mnx[i] = min(mnx[i - 1], pos[i].fr); mxx[i] = max(mxx[i - 1], pos[i].fr); mny[i] = min(mny[i - 1], pos[i].sc); mxy[i] = max(mxy[i - 1], pos[i].sc); if (i + 1 == (mxx[i] - mnx[i] + 1) * (mxy[i] - mny[i] + 1)) { ans++; was[i] = 1; } } } int swap_seats(int a, int b) { if (a > b) swap(a, b); swap(pos[a], pos[b]); for (int i = a; i <= b; i++) { if (i > 0) { mnx[i] = min(mnx[i - 1], pos[i].fr); mxx[i] = max(mxx[i - 1], pos[i].fr); mny[i] = min(mny[i - 1], pos[i].sc); mxy[i] = max(mxy[i - 1], pos[i].sc); } else { mnx[i] = pos[i].fr; mxx[i] = pos[i].fr; mny[i] = pos[i].sc; mxy[i] = pos[i].sc; } if (i + 1 == (mxx[i] - mnx[i] + 1) * (mxy[i] - mny[i] + 1)) { if (!was[i]) { was[i] = 1; ans++; } } else { if (was[i]) { was[i] = 0; ans--; } } } 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...