Submission #623669

#TimeUsernameProblemLanguageResultExecution timeMemory
623669MateGiorbelidzeSeats (IOI18_seats)C++14
0 / 100
4027 ms45620 KiB
#include "seats.h" #include <bits/stdc++.h> using namespace std; #define ll long long std::vector<int> r , c , mxr, mxc, mnr, mnc; ll ans = 0 , h , w; void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) { r = R; c = C; h = H; w = W; mxr.resize( h * w + 1 ); mxc.resize( h * w + 1 ); mnr.resize( h * w + 1 ); mnc.resize( h * w + 1 ); mxr[0] = mxc[0] = INT_MIN; mnr[0] = mnc[0] = INT_MAX; for (int i = 1; i <= h * w; i++) { mxr[i] = max(mxr[i - 1] , r[i - 1]); mxc[i] = max(mxc[i - 1] , c[i - 1]); mnr[i] = min(mnr[i - 1] , r[i - 1]); mnc[i] = min(mxc[i - 1] , c[i - 1]); if ( (mxr[i] - mnr[i] + 1) * (mxc[i] - mnc[i] + 1) == i) ans++; } } int swap_seats(int a, int b) { a++; b++; if (a > b) swap(a , b); for (int i = a; i <= b; i++) if ( (mxr[i] - mnr[i] + 1) * (mxc[i] - mnc[i] + 1) == i) ans--; swap (r[a - 1] , r[b - 1]); swap (c[a - 1] , c[b - 1]); for (int i = a; i <= b; i++) { mxr[i] = max(mxr[i - 1] , r[i - 1]); mxc[i] = max(mxc[i - 1] , c[i - 1]); mnr[i] = min(mnr[i - 1] , r[i - 1]); mnc[i] = min(mxc[i - 1] , c[i - 1]); if ( (mxr[i] - mnr[i] + 1) * (mxc[i] - mnc[i] + 1) == i) 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...