Submission #138751

#TimeUsernameProblemLanguageResultExecution timeMemory
138751MAMBASeats (IOI18_seats)C++17
5 / 100
4069 ms59868 KiB
#include "seats.h" #include <bits/stdc++.h> using namespace std; #define rep(i , j , k) for(int i = j; i < (int)k; i++) typedef vector<int> vi; int MIN(int a, int b) { return a < b ? a : b; } int MAX(int a, int b) { return b < a ? a : b; } const int N = 1e6 + 10; int n; template<int(*f)(int , int)> struct seg { int arr[N << 1]; seg() { memset(arr, f(0 , 63) ^ 63 , sizeof(arr)); } inline void Upd(int p , int val) { for (arr[p += n] = val; p > 1; p >>= 1) arr[p >> 1] = f(arr[p] , arr[p ^ 1]); } inline int Get(int l , int r) { int res = f(0 , (int)1e9) ^ (int)1e9; for (l += n , r += n; l < r; l >>= 1, r >>= 1) { if (l & 1) res = f(res , arr[l++]); if (r & 1) res = f(res , arr[--r]); } return res; } }; seg<MIN> mR , mC; seg<MAX> xR , xC; vi R , C; int solve(int me) { // cout << " ::::" << me << endl; if (me == n + 1) return 0; int sz = (xR.Get(0 , me) - mR.Get(0 , me) + 1) * (xC.Get(0 , me) - mC.Get(0 , me) + 1); // cout << " : " << sz << endl; if (sz == me) return solve(me + 1) + 1; return solve(sz); } void give_initial_chart(int H, int W, vi R_, vi C_) { R = R_, C = C_; n = H * W; rep(i , 0 , n) { mR.Upd(i , R[i]); mC.Upd(i , C[i]); xR.Upd(i , R[i]); xC.Upd(i , C[i]); } //cout << solve(1) << endl; //cout << "GOOD" << endl; return; } int swap_seats(int a, int b) { swap(R[a] , R[b]); swap(C[a] , C[b]); mR.Upd(a , R[a]); mC.Upd(a , C[a]); xR.Upd(a , R[a]); xC.Upd(a , C[a]); mR.Upd(b , R[b]); mC.Upd(b , C[b]); xR.Upd(b , R[b]); xC.Upd(b , C[b]); //cout << "DONE" << endl; return solve(1); }
#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...