제출 #764419

#제출 시각아이디문제언어결과실행 시간메모리
764419khshg자리 배치 (IOI18_seats)C++14
17 / 100
4062 ms35556 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using str = string; using pi = pair<int, int>; using pl = pair<ll, ll>; using pd = pair<ld, ld>; #define mp make_pair #define ff first #define ss second #define ar array template<class T> using V = vector<T>; using vi = V<int>; using vb = V<bool>; using vl = V<ll>; using vd = V<ld>; using vs = V<str>; using vpi = V<pi>; using vpl = V<pl>; using vpd = V<pd>; #define sz(x) (int)((x).size()) #define bg(x) begin(x) #define all(x) bg(x), end(x) #define rall(x) (x).rbegin(), (x).rend() #define sor(x) sort(all(x)) #define rsz resize #define ins insert #define pb push_back #define eb emplace_back #define ft front() #define bk back() #define lb lower_bound #define ub upper_bound #define FOR(i, a, b) for(int i = (a); i < (b); ++i) #define F0R(i, a) FOR(i, 0, a) #define ROF(i, a, b) for(int i = (b) - 1; i >= (a); --i) #define R0F(i, a) ROF(i, 0, a) #define rep(a) F0R(_, a) #define trav(a, x) for(auto& a : x) template<class T> bool ckmin(T& a, const T& b) { return (b < a ? a = b, 1 : 0); } template<class T> bool ckmax(T& a, const T& b) { return (b > a ? a = b, 1 : 0); } int N, M; vi R, C; int Lf[1000000], Rf[1000000], Ls[1000000], Rs[1000000], ans; void dodo() { ans = 1; Lf[0] = R[0]; Rf[0] = R[0]; Ls[0] = C[0]; Rs[0] = C[0]; FOR(i, 1, N * M) { Lf[i] = min(Lf[i - 1], R[i]); Rf[i] = max(Rf[i - 1], R[i]); Ls[i] = min(Ls[i - 1], C[i]); Rs[i] = max(Rs[i - 1], C[i]); if(i + 1 == (Rf[i] - Lf[i] + 1) * (Rs[i] - Ls[i] + 1)) ++ans; } } void give_initial_chart(int _N, int _M, vi _R, vi _C) { swap(N, _N); swap(M, _M); swap(R, _R); swap(C, _C); dodo(); } int swap_seats(int A, int B) { if(A > B) swap(A, B); swap(R[A], R[B]); swap(C[A], C[B]); if(!A) { Lf[0] = R[0]; Rf[0] = R[0]; Ls[0] = C[0]; Rs[0] = C[0]; ++A; } FOR(i, A, B + 1) { if(i + 1 == (Rf[i] - Lf[i] + 1) * (Rs[i] - Ls[i] + 1)) --ans; Lf[i] = min(Lf[i - 1], R[i]); Rf[i] = max(Rf[i - 1], R[i]); Ls[i] = min(Ls[i - 1], C[i]); Rs[i] = max(Rs[i - 1], C[i]); if(i + 1 == (Rf[i] - Lf[i] + 1) * (Rs[i] - Ls[i] + 1)) ++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...