Submission #421676

#TimeUsernameProblemLanguageResultExecution timeMemory
421676alireza_kavianiSeats (IOI18_seats)C++11
17 / 100
4074 ms45240 KiB
#include "seats.h" #include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 10; int n , h , w , ans , A[2][MAXN] , valid[MAXN] , mn[2][MAXN] , mx[2][MAXN]; void give_initial_chart(int H, int W, vector<int> R, vector<int> C) { h = H; w = W; n = h * w; for(int i = 0 ; i < n ; i++){ A[0][i] = mn[0][i] = mx[0][i] = R[i]; A[1][i] = mn[1][i] = mx[1][i] = C[i]; } for(int i = 0 ; i < 2 ; i++){ for(int j = 1 ; j < n ; j++){ mn[i][j] = min(A[i][j] , mn[i][j - 1]); mx[i][j] = max(A[i][j] , mx[i][j - 1]); } } for(int i = 0 ; i < n ; i++){ int x = mx[0][i] - mn[0][i] + 1 , y = mx[1][i] - mn[1][i] + 1; if(x * y == i + 1){ valid[i] = 1; ans++; } } } int swap_seats(int a, int b) { if(a > b) swap(a , b); swap(A[0][a] , A[0][b]); swap(A[1][a] , A[1][b]); for(int i = 0 ; i < 2 ; i++){ mn[i][0] = mx[i][0] = A[i][0]; for(int j = max(1 , a) ; j < b ; j++){ mn[i][j] = min(A[i][j] , mn[i][j - 1]); mx[i][j] = max(A[i][j] , mx[i][j - 1]); } } for(int i = a ; i < b ; i++){ ans -= valid[i]; valid[i] = 0; int x = mx[0][i] - mn[0][i] + 1 , y = mx[1][i] - mn[1][i] + 1; // cout << i << ' ' << x << ' ' << y << endl; if(x * y == i + 1){ valid[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...